mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(socket) add disconect
This commit is contained in:
parent
89cf78f056
commit
e644c25719
2 changed files with 34 additions and 7 deletions
|
|
@ -84,6 +84,8 @@ getJSONfromFileTable.
|
|||
|
||||
* fix(help) remove pre
|
||||
|
||||
* feature(socket) add disconect
|
||||
|
||||
|
||||
2012.04.22, v0.2.0
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@
|
|||
++lConnNum;
|
||||
socket.send('{"stdout":"client connected"}');
|
||||
|
||||
Util.log('server connected');
|
||||
log(lConnNum, 'connected');
|
||||
|
||||
if(!OnMessageFuncs[lConnNum])
|
||||
OnMessageFuncs[lConnNum] = onMessage(lConnNum, socket);
|
||||
|
|
@ -57,6 +57,7 @@
|
|||
lConn_func = OnMessageFuncs[lConnNum];
|
||||
|
||||
socket.on('message', lConn_func);
|
||||
socket.on('disconnect', Util.call(disconnect, lConnNum));
|
||||
|
||||
});
|
||||
}
|
||||
|
|
@ -64,6 +65,19 @@
|
|||
return lRet;
|
||||
};
|
||||
|
||||
function disconnect(pParams){
|
||||
var lConnNum, lRet = Util.checkObj(pParams, ['params']);
|
||||
|
||||
if(lRet) {
|
||||
lConnNum = pParams.params;
|
||||
OnMessageFuncs [lConnNum] =
|
||||
ClientFuncs [lConnNum] = null;
|
||||
|
||||
log(lConnNum, 'disconnected');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* function gets onMessage function
|
||||
* that execute needed command
|
||||
|
|
@ -74,7 +88,7 @@
|
|||
return function(pCommand) {
|
||||
var lMsg, lWinCommand, lExec_func;
|
||||
|
||||
Util.log(pCommand);
|
||||
Util.log('#' + pConnNum + ': ' + pCommand);
|
||||
|
||||
if( Util.isContainStrAtBegin(pCommand, 'cloudcmd') ){
|
||||
pCommand = Util.removeStr(pCommand, 'cloudcmd');
|
||||
|
|
@ -118,7 +132,7 @@
|
|||
}
|
||||
|
||||
if(!ClientFuncs[pConnNum])
|
||||
ClientFuncs[pConnNum] = getExec(pSocket);
|
||||
ClientFuncs[pConnNum] = getExec(pSocket, pConnNum);
|
||||
|
||||
lExec_func = ClientFuncs[pConnNum];
|
||||
|
||||
|
|
@ -131,7 +145,7 @@
|
|||
* function send result of command to client
|
||||
* @param pSocket
|
||||
*/
|
||||
function getExec(pSocket){
|
||||
function getExec(pSocket, pConnNum){
|
||||
return function(pError, pStdout, pStderr) {
|
||||
var lExec = {
|
||||
stdout : pStdout,
|
||||
|
|
@ -140,11 +154,22 @@
|
|||
|
||||
lExec_str = JSON.stringify(lExec);
|
||||
|
||||
if (pError) {
|
||||
Util.log('exec error: ' + pError);
|
||||
}
|
||||
log(pConnNum, pError, 'error');
|
||||
log(pConnNum, pStderr, 'stderror');
|
||||
|
||||
pSocket.send(lExec_str);
|
||||
};
|
||||
}
|
||||
|
||||
function log(pConnNum, pStr, pType){
|
||||
var lType = ' ';
|
||||
|
||||
if (pStr) {
|
||||
|
||||
if (pType)
|
||||
lType += pType + ':';
|
||||
|
||||
Util.log('#' + pConnNum + lType + pStr);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue