diff --git a/example/im/js/main.js b/example/im/js/main.js index 7cadeff..9b06679 100644 --- a/example/im/js/main.js +++ b/example/im/js/main.js @@ -6,7 +6,7 @@ var utils = odd.utils, NetStatusEvent = events.NetStatusEvent, Level = events.Level, Code = events.Code, - IM = raw.IM, + IM = odd.IM, Sending = IM.CommandMessage.Sending, Casting = IM.CommandMessage.Casting; diff --git a/src/im/im.js b/src/im/im.js index f6af75b..a7429e8 100644 --- a/src/im/im.js +++ b/src/im/im.js @@ -69,6 +69,8 @@ _this.join = _ns.join; _this.leave = _ns.leave; _this.chmod = _ns.chmod; + _this.invoke = _ns.invoke; + _this.quit = _ns.quit; _this.send = _ns.send; _this.sendStatus = _ns.sendStatus; _this.call = _ns.call; diff --git a/src/im/im.netstream.js b/src/im/im.netstream.js index 5896e82..d180ae3 100644 --- a/src/im/im.netstream.js +++ b/src/im/im.netstream.js @@ -90,11 +90,10 @@ result = resolve; status = reject; }); - var args = { + _this.call(0, { name: Command.JOIN, rid: rid, - }; - _this.call(0, args, null, new Responder(function (m) { + }, null, new Responder(function (m) { _logger.log(`Join success: user=${_client.userId()}, room=${rid}`); result(); }, function (m) { @@ -110,11 +109,10 @@ result = resolve; status = reject; }); - var args = { + _this.call(0, { name: Command.LEAVE, rid: rid, - }; - _this.call(0, args, null, new Responder(function (m) { + }, null, new Responder(function (m) { _logger.log(`Leave success: user=${_client.userId()}, room=${rid}`); result(); }, function (m) { @@ -130,14 +128,13 @@ result = resolve; status = reject; }); - var args = { + _this.call(0, { name: Command.CHMOD, rid: rid, tid: tid, operator: operator, mask: mask, - }; - _this.call(0, args, null, new Responder(function (m) { + }, null, new Responder(function (m) { _logger.log(`Chmod success: user=${_client.userId()}, room=${rid}, target=${tid}, operator=${operator}, mask=${mask}`); result(); }, function (m) { @@ -147,20 +144,53 @@ return await ret; }; + _this.invoke = async function (path, args, env, dir, timeout) { + var result, status; + var ret = new Promise((resolve, reject) => { + result = resolve; + status = reject; + }); + _this.call(0, { + name: Command.INVOKE, + path: path, + args: args, + env: env, + dir: dir, + timeout: timeout, + }, null, new Responder(function (m) { + _logger.log(`Invoke success: user=${_client.userId()}, path=${path}, args=${args}, env=${env}, dir=${dir}, timeout=${timeout}, pid=${m.Arguments.info.pid}`); + result(); + }, function (m) { + _logger.error(`Failed to invoke: user=${_client.userId()}, path=${path}, args=${args}, env=${env}, dir=${dir}, timeout=${timeout}, error=${m.Arguments.description}`); + status(m.Arguments.description); + })); + return await ret; + }; + + _this.quit = async function (pid) { + return await _this.call(0, { + name: Command.QUIT, + pid: pid, + }).then(() => { + _logger.log(`Send quit success: user=${_client.userId()}, pid=${pid}`); + }).catch((err) => { + _logger.error(`Failed to send quit: user=${_client.userId()}, pid=${pid}, error=${err}`); + }); + }; + _this.send = async function (type, cast, id, data, payload) { var result, status; var ret = new Promise((resolve, reject) => { result = resolve; status = reject; }); - var args = { + _this.call(0, { name: Command.SEND, type: type, cast: cast, id: id, data: data, - }; - _this.call(0, args, payload, new Responder(function (m) { + }, payload, new Responder(function (m) { _logger.log(`${data}: user=${_client.userId()}, cast=${cast}, to=${id}`); result(); }, function (m) { diff --git a/src/im/message/message.js b/src/im/message/message.js index 540252e..8a1382e 100644 --- a/src/im/message/message.js +++ b/src/im/message/message.js @@ -13,6 +13,8 @@ JOIN: 'join', LEAVE: 'leave', CHMOD: 'chmod', + INVOKE: 'invoke', + QUIT: 'quit', SEND: 'send', PLAY: 'play', STOP: 'stop', diff --git a/src/im/ui/ui.js b/src/im/ui/ui.js index bce9da1..c32fb54 100644 --- a/src/im/ui/ui.js +++ b/src/im/ui/ui.js @@ -77,6 +77,8 @@ _this.join = _im.join; _this.leave = _im.leave; _this.chmod = _im.chmod; + _this.invoke = _im.invoke; + _this.quit = _im.quit; _this.send = _im.send; _this.sendStatus = _im.sendStatus; _this.call = _im.call; diff --git a/src/odd.js b/src/odd.js index 12c3405..398b14a 100644 --- a/src/odd.js +++ b/src/odd.js @@ -1,6 +1,6 @@ odd = function () { return { - version: '2.5.00', + version: '2.5.01', }; };