From cd311d098443cb26a9bc91864c5d468fe72aebcd Mon Sep 17 00:00:00 2001 From: coderaiser Date: Sun, 30 Jun 2013 09:26:41 +0000 Subject: [PATCH] chore(socket) move out function connect --- lib/client/socket.js | 47 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/lib/client/socket.js b/lib/client/socket.js index cd9fa7bf..18fe07b6 100644 --- a/lib/client/socket.js +++ b/lib/client/socket.js @@ -1,5 +1,5 @@ /* module make possible connectoin thrue socket.io on a client */ -var CloudCmd, Util, DOM, jqconsole, io; +var CloudCmd, Util, DOM, io; (function(CloudCmd, Util, DOM){ 'use strict'; @@ -8,32 +8,33 @@ var CloudCmd, Util, DOM, jqconsole, io; Terminal, ERROR_MSG = 'could not connect to socket.io\n'+ - 'npm i socket.io'; + 'npm i socket.io'; DOM.jsload('/socket.io/lib/socket.io.js', { onerror : Util.retExec(Util.log, ERROR_MSG), - - onload : function(){ - socket = io.connect(CloudCmd.HOST); - - CloudCmd.Socket = socket; - - socket.on('connect', function () { - outToTerminal({stdout: 'socket connected'}); - }); - - socket.on('message', function (msg) { - var lMsg = Util.parseJSON(msg); - - outToTerminal(lMsg); - - }); - - socket.on('disconnect', function () { - outToTerminal({stderr: 'socket disconected'}); - }); - } + onload : connect }); + + function connect() { + socket = io.connect(CloudCmd.HOST); + + CloudCmd.Socket = socket; + + socket.on('connect', function () { + outToTerminal({stdout: 'socket connected'}); + }); + + socket.on('message', function (msg) { + var lMsg = Util.parseJSON(msg); + + outToTerminal(lMsg); + + }); + + socket.on('disconnect', function () { + outToTerminal({stderr: 'socket disconected'}); + }); + } function outToTerminal(pMsg){ var i, n, lResult, lStdout, lStderr,