refactor(cloudfunc) add channel constants

This commit is contained in:
coderaiser 2014-02-04 03:48:44 -05:00
parent e4938b593e
commit 3260695785
5 changed files with 50 additions and 31 deletions

View file

@ -6,7 +6,7 @@ var CloudCmd, Util, DOM, CloudFunc, $;
function ConsoleProto(CallBack) {
var Name = 'Console',
Buffer = {
Buffer = {
log : '',
error : ''
},
@ -17,6 +17,9 @@ var CloudCmd, Util, DOM, CloudFunc, $;
Key = CloudCmd.Key,
Images = DOM.Images,
Notify = DOM.Notify,
CHANNEL = CloudFunc.CHANNEL_CONSOLE,
Console = this;
function init() {
@ -153,19 +156,20 @@ var CloudCmd, Util, DOM, CloudFunc, $;
}
function addListeners(callback) {
var socket = CloudCmd.Socket;
var socket = CloudCmd.Socket,
options = {
'connect' : function() {
log(socket.CONNECTED);
},
'disconnect': function() {
error(socket.DISCONNECTED);
}
};
socket.on({
'message' : onMessage,
'connect' : function() {
log(socket.CONNECTED);
},
'disconnect': function() {
error(socket.DISCONNECTED);
}
});
options[CHANNEL] = onMessage;
socket.on(options);
Util.exec(callback);
}

View file

@ -5,15 +5,19 @@ var CloudCmd, Util, DOM, CloudFunc, Terminal;
CloudCmd.Terminal = TerminalProto;
function TerminalProto(CallBack) {
var Name = 'Terminal',
var Name = 'Terminal',
Loading,
Element,
MouseBinded,
Term,
Key = CloudCmd.Key,
Images = DOM.Images,
Notify = DOM.Notify,
CloudTerm = this;
Key = CloudCmd.Key,
Images = DOM.Images,
Notify = DOM.Notify,
CHANNEL = CloudFunc.CHANNEL_TERMINAL,
CHANNEL_RESIZE = CloudFunc.CHANNEL_TERMINAL_RESIZE,
CloudTerm = this;
function init() {
Loading = true;
@ -96,19 +100,17 @@ var CloudCmd, Util, DOM, CloudFunc, Terminal;
rows: 25
};
socket.on({
'terminal-data' : write
});
socket.on(CHANNEL, write);
Term.on('keydown', listener);
Term.on('data', function(data) {
if (data)
socket.emit('terminal-data', data);
socket.emit(CHANNEL, data);
});
//Term.resize(size.cols, size.rows);
socket.emit('terminal-resize', size);
//socket.emit(CHANNEL_RESIZE, size);
Util.exec(callback);
}

View file

@ -45,6 +45,9 @@ var Util;
/* id панелей с файлами */
this.PANEL_LEFT = 'js-left';
this.PANEL_RIGHT = 'js-right';
this.CHANNEL_CONSOLE = 'message';
this.CHANNEL_TERMINAL = 'terminal-data';
this.CHANNEL_TERMINAL_RESIZE= 'terminal-size';
this.addListener = function(name, func, allListeners, socket) {
var listeners, obj;

View file

@ -13,6 +13,7 @@
Util = main.util,
path = main.path,
CloudFunc = main.cloudfunc,
mainpackage = main.mainpackage,
equalPart = Util.isContainStrAtBegin,
CLOUDCMD = mainpackage.name,
@ -21,6 +22,9 @@
Clients = [],
WIN32 = main.WIN32,
ConNum = 0,
CHANNEL = CloudFunc.CHANNEL_CONSOLE,
HELP = {
stdout : CLOUDCMD + ' exit \n' +
CLOUDCMD + ' update \n',
@ -55,7 +59,7 @@
var msg = Util.stringifyJSON(json);
if (all)
socket.send(msg, clientSocket, 'message', all);
socket.send(msg, clientSocket, CHANNEL, all);
socket.send(msg, clientSocket);
});
@ -85,11 +89,11 @@
log(conNum, 'disconnected');
socket.removeListener('message', onMessage, clientSocket);
socket.removeListener(CHANNEL, onMessage, clientSocket);
socket.removeListener('disconnect', onDisconnect, clientSocket);
}.bind(null, ConNum);
socket.on('message', onMessage, clientSocket);
socket.on(CHANNEL, onMessage, clientSocket);
socket.on('disconnect', onDisconnect, clientSocket);
} else {
msg = log(ConNum, ' in use. Reconnecting...\n');

View file

@ -9,11 +9,17 @@
Util = main.util,
path = main.path,
CloudFunc = main.cloudfunc,
mainpackage = main.mainpackage,
CLOUDCMD = mainpackage.name,
ClientDirs = [],
Clients = [],
WIN32 = main.WIN32,
CHANNEL = CloudFunc.CHANNEL_TERMINAL,
CHANNEL_RESIZE = CloudFunc.CHANNEL_RESIZE,
ConNum = 0;
/**
* function listen on servers port
@ -25,7 +31,7 @@
if (pty)
ret = socket.on('connection', function(clientSocket) {
onConnection(clientSocket, function(data) {
socket.emit('terminal-data', data, clientSocket);
socket.emit(CHANNEL, data, clientSocket);
});
});
@ -49,15 +55,15 @@
log(conNum, 'terminal disconnected');
socket.removeListener('terminal-data', dataFunc, clientSocket);
socket.removeListener('terminal-resize', resizeFunc, clientSocket);
socket.removeListener(CHANNEL, dataFunc, clientSocket);
socket.removeListener(CHANNEL_RESIZE, resizeFunc, clientSocket);
socket.removeListener('disconnect', onDisconnect, clientSocket);
term.destroy();
}.bind(null, ConNum, term);
socket.on('terminal-data', dataFunc, clientSocket);
socket.on('terminal-resize', resizeFunc, clientSocket);
socket.on(CHANNEL, dataFunc, clientSocket);
socket.on(CHANNEL_RESIZE, resizeFunc, clientSocket);
socket.on('disconnect', onDisconnect, clientSocket);
} else {
log(ConNum, ' in use. Reconnecting...\n');