diff --git a/lib/client/console.js b/lib/client/console.js index 58d67886..c549657f 100644 --- a/lib/client/console.js +++ b/lib/client/console.js @@ -14,6 +14,7 @@ var CloudCmd, Util, DOM, CloudFunc, $; jqconsole, Element, MouseBinded, + Socket, Key = CloudCmd.Key, Images = DOM.Images, Notify = DOM.Notify, @@ -31,6 +32,10 @@ var CloudCmd, Util, DOM, CloudFunc, $; load, Console.show, CloudCmd.Socket, + function(callback) { + Socket = CloudCmd.Socket; + Util.exec(callback); + }, addListeners, ]); } @@ -58,11 +63,9 @@ var CloudCmd, Util, DOM, CloudFunc, $; // Handle a command. var handler = function(command) { - var socket = CloudCmd.Socket; - - if (command && socket) { + if (command) { Images.showLoad({ top:true }); - socket.emit(CHANNEL, command); + Socket.emit(CHANNEL, command); } jqconsole.Prompt(true, handler); @@ -156,20 +159,19 @@ var CloudCmd, Util, DOM, CloudFunc, $; } function addListeners(callback) { - var socket = CloudCmd.Socket, - options = { + var options = { 'connect' : function() { - log(socket.CONNECTED); + log(Socket.CONNECTED); }, 'disconnect': function() { - error(socket.DISCONNECTED); + error(Socket.DISCONNECTED); } }; options[CHANNEL] = onMessage; - socket.on(options); + Socket.on(options); Util.exec(callback); } diff --git a/lib/client/terminal.js b/lib/client/terminal.js index 6adaa859..f4df1399 100644 --- a/lib/client/terminal.js +++ b/lib/client/terminal.js @@ -11,6 +11,7 @@ var CloudCmd, Util, DOM, CloudFunc, Terminal; MouseBinded, Term, Cell, + Socket = CloudCmd.Socket, Key = CloudCmd.Key, ESC = Key.ESC, Images = DOM.Images, @@ -32,13 +33,15 @@ var CloudCmd, Util, DOM, CloudFunc, Terminal; Util.loadOnLoad([ DOM.jqueryLoad, CloudCmd.View, + load, + CloudCmd.Socket, /* rm view keys, it ruin terminal */ function(callback) { CloudCmd.View.rmKeys(), + Socket = CloudCmd.Socket; + Util.exec(callback); }, - load, - CloudCmd.Socket, CloudTerm.show, addListeners ]); @@ -49,10 +52,8 @@ var CloudCmd, Util, DOM, CloudFunc, Terminal; function show(callback) { var options = { - onUpdate: onResize, - }, - - socket = CloudCmd.Socket; + onUpdate: onResize, + }; if (!Loading) { Images.showLoad({top:true}); @@ -109,13 +110,12 @@ var CloudCmd, Util, DOM, CloudFunc, Terminal; } function addListeners(callback) { - var socket = CloudCmd.Socket, - options = { + var options = { 'connect': function() { - write(socket.CONNECTED + '\r'); + write(Socket.CONNECTED + '\r'); }, 'disconnect': function() { - write(socket.DISCONNECTED +'\r'); + write(Socket.DISCONNECTED +'\r'); }, }; @@ -124,14 +124,14 @@ var CloudCmd, Util, DOM, CloudFunc, Terminal; Term.resize(size.cols, size.rows); }; - socket.on(options); + Socket.on(options); Term.on('data', function(data) { - socket.emit(CHANNEL, data); + Socket.emit(CHANNEL, data); }); Term.on('resize', function(size) { - socket.emit(CHANNEL_RESIZE, size); + Socket.emit(CHANNEL_RESIZE, size); }); Util.exec(callback);