refactor(socket) rm jsonSend

This commit is contained in:
coderaiser 2014-01-28 06:40:24 -05:00
parent f205e5913b
commit 926bff1854

View file

@ -79,18 +79,18 @@
'jsonp-polling'
]);
ret = io.sockets.on('connection', onConnection);
ret = io.sockets.on('connection', function(socket) {
onConnection(socket, function(json) {
var msg = Util.stringifyJSON(json);
socket.send(msg);
});
});
}
return ret;
};
function jsonSend(socket, json) {
var msg = Util.stringifyJSON(json);
socket.send(msg);
}
function onConnection(socket) {
function onConnection(socket, callback) {
var msg, onDisconect, onMessage;
++ConNum;
@ -98,14 +98,14 @@
if (!Clients[ConNum]) {
msg = log(ConNum, 'connected\n');
jsonSend(socket, {
Util.exec(callback, {
stdout : msg
});
Clients[ConNum] = true;
onMessage = getOnMessage(ConNum, function(json) {
jsonSend(socket, json);
});
onMessage = getOnMessage(ConNum, callback);
onDisconect = Util.retFunc(disconnect, ConNum);
socket.on('message', onMessage);
@ -116,7 +116,7 @@
} else {
msg = log(ConNum, ' in use. Reconnecting...\n');
jsonSend(socket, {
Util.exec(callback, {
stdout: msg
});
@ -154,7 +154,7 @@
Util.log(connName + pCommand);
if (equalPart(pCommand, CLOUDCMD))
lRet = onCloudCmd(pCommand, Util.retExec(callback, json));
lRet = onCloudCmd(pCommand, callback);
else if (equalPart(pCommand, 'cd ')) {
lRet = true;
@ -208,7 +208,7 @@
} else if (WIN32 || firstChar === ' ' || isContain)
exec(pCommand, options, lExec_func);
else
getSpawn(pCommand, options, Util.retExec(callback));
getSpawn(pCommand, options, callback);
}
};
}