mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(console) add onMsg
This commit is contained in:
parent
e704406368
commit
8e106cebbf
1 changed files with 22 additions and 10 deletions
|
|
@ -19,28 +19,36 @@
|
|||
|
||||
CHANNEL = CloudFunc.CHANNEL_CONSOLE;
|
||||
|
||||
module.exports = function() {
|
||||
module.exports = function(onMsg) {
|
||||
socket.on('connection', function(clientSocket) {
|
||||
onConnection(clientSocket, function(error, json) {
|
||||
onConnection(clientSocket, onMsg, function(error, json) {
|
||||
socket.emit(CHANNEL, json, clientSocket);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function onConnection(clientSocket, callback) {
|
||||
function onConnection(clientSocket, onMsg, callback) {
|
||||
var msg, onDisconnect, onMessage;
|
||||
|
||||
++ConNum;
|
||||
if (!callback) {
|
||||
callback = onMsg;
|
||||
onMsg = null;
|
||||
}
|
||||
|
||||
Util.checkArgs(arguments, ['clientSocket', 'callback']);
|
||||
Util.checkArgs([clientSocket, callback], ['clientSocket', 'callback']);
|
||||
|
||||
++ConNum;
|
||||
|
||||
if (!Clients[ConNum]) {
|
||||
msg = log(ConNum, 'console connected');
|
||||
|
||||
callback(null, {
|
||||
stdout : addNewLine(msg),
|
||||
path : CWD
|
||||
});
|
||||
if (onMsg)
|
||||
onMsg('cd .', callback);
|
||||
else
|
||||
callback(null, {
|
||||
stdout : addNewLine(msg),
|
||||
path : CWD
|
||||
});
|
||||
|
||||
Clients[ConNum] = {
|
||||
cwd : CWD
|
||||
|
|
@ -48,7 +56,11 @@
|
|||
|
||||
onMessage = function(command) {
|
||||
log(ConNum, command);
|
||||
spawnify(command, Clients[ConNum], callback);
|
||||
|
||||
if (onMsg)
|
||||
onMsg(command, callback);
|
||||
else
|
||||
spawnify(command, Clients[ConNum], callback);
|
||||
},
|
||||
onDisconnect = function(conNum) {
|
||||
Clients[conNum] = null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue