refactor(console) send -> emit

This commit is contained in:
coderaiser 2014-02-04 04:34:11 -05:00
parent 000665f7a0
commit 9df8e857db
3 changed files with 21 additions and 20 deletions

View file

@ -62,7 +62,7 @@ var CloudCmd, Util, DOM, CloudFunc, $;
if (command && socket) {
Images.showLoad({ top:true });
socket.send(command);
socket.emit(CHANNEL, command);
}
jqconsole.Prompt(true, handler);
@ -175,13 +175,13 @@ var CloudCmd, Util, DOM, CloudFunc, $;
}
function onMessage(json) {
var msg = Util.parseJSON(json);
log(msg.stdout);
error(msg.stderr);
if (json) {
Util.log(json);
log(json.stdout);
error(json.stderr);
}
DOM.Images.hideLoad();
Util.log(msg);
}
init();

View file

@ -56,12 +56,7 @@
ret = socket.on('connection', function(clientSocket) {
onConnection(clientSocket, function(json, all) {
var msg = Util.stringifyJSON(json);
if (all)
socket.send(msg, clientSocket, CHANNEL, all);
socket.send(msg, clientSocket);
socket.emit(CHANNEL, json, clientSocket, all);
});
});

View file

@ -27,16 +27,22 @@
CloudFunc.removeListener(name, func, AllListeners, socket);
}
function send(msg, clientSocket, channel, all) {
if (all && channel)
clientSocket.broadcast.emit(channel, msg);
else
clientSocket.send(msg);
function send(msg, socket) {
if (socket)
socket.send(msg);
}
function emit(channel, message, clientSocket) {
if (clientSocket)
clientSocket.emit(channel, message);
function emit(channel, message, socket, all) {
var obj;
if (socket) {
if (all)
obj = socket.broadcast;
else
obj = socket;
obj.emit(channel, message);
}
}
/**