Skip to content

Commit

Permalink
v2.5.01 - Add im api: invoke/quit.
Browse files Browse the repository at this point in the history
  • Loading branch information
oddengine committed Mar 15, 2023
1 parent 23ac69a commit 5b2559c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 14 deletions.
2 changes: 1 addition & 1 deletion example/im/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/im/im.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
54 changes: 42 additions & 12 deletions src/im/im.netstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions src/im/message/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
JOIN: 'join',
LEAVE: 'leave',
CHMOD: 'chmod',
INVOKE: 'invoke',
QUIT: 'quit',
SEND: 'send',
PLAY: 'play',
STOP: 'stop',
Expand Down
2 changes: 2 additions & 0 deletions src/im/ui/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/odd.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
odd = function () {
return {
version: '2.5.00',
version: '2.5.01',
};
};

0 comments on commit 5b2559c

Please sign in to comment.