Skip to content

Commit 5b2559c

Browse files
committed
v2.5.01 - Add im api: invoke/quit.
1 parent 23ac69a commit 5b2559c

File tree

6 files changed

+50
-14
lines changed

6 files changed

+50
-14
lines changed

example/im/js/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var utils = odd.utils,
66
NetStatusEvent = events.NetStatusEvent,
77
Level = events.Level,
88
Code = events.Code,
9-
IM = raw.IM,
9+
IM = odd.IM,
1010
Sending = IM.CommandMessage.Sending,
1111
Casting = IM.CommandMessage.Casting;
1212

src/im/im.js

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
_this.join = _ns.join;
7070
_this.leave = _ns.leave;
7171
_this.chmod = _ns.chmod;
72+
_this.invoke = _ns.invoke;
73+
_this.quit = _ns.quit;
7274
_this.send = _ns.send;
7375
_this.sendStatus = _ns.sendStatus;
7476
_this.call = _ns.call;

src/im/im.netstream.js

+42-12
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,10 @@
9090
result = resolve;
9191
status = reject;
9292
});
93-
var args = {
93+
_this.call(0, {
9494
name: Command.JOIN,
9595
rid: rid,
96-
};
97-
_this.call(0, args, null, new Responder(function (m) {
96+
}, null, new Responder(function (m) {
9897
_logger.log(`Join success: user=${_client.userId()}, room=${rid}`);
9998
result();
10099
}, function (m) {
@@ -110,11 +109,10 @@
110109
result = resolve;
111110
status = reject;
112111
});
113-
var args = {
112+
_this.call(0, {
114113
name: Command.LEAVE,
115114
rid: rid,
116-
};
117-
_this.call(0, args, null, new Responder(function (m) {
115+
}, null, new Responder(function (m) {
118116
_logger.log(`Leave success: user=${_client.userId()}, room=${rid}`);
119117
result();
120118
}, function (m) {
@@ -130,14 +128,13 @@
130128
result = resolve;
131129
status = reject;
132130
});
133-
var args = {
131+
_this.call(0, {
134132
name: Command.CHMOD,
135133
rid: rid,
136134
tid: tid,
137135
operator: operator,
138136
mask: mask,
139-
};
140-
_this.call(0, args, null, new Responder(function (m) {
137+
}, null, new Responder(function (m) {
141138
_logger.log(`Chmod success: user=${_client.userId()}, room=${rid}, target=${tid}, operator=${operator}, mask=${mask}`);
142139
result();
143140
}, function (m) {
@@ -147,20 +144,53 @@
147144
return await ret;
148145
};
149146

147+
_this.invoke = async function (path, args, env, dir, timeout) {
148+
var result, status;
149+
var ret = new Promise((resolve, reject) => {
150+
result = resolve;
151+
status = reject;
152+
});
153+
_this.call(0, {
154+
name: Command.INVOKE,
155+
path: path,
156+
args: args,
157+
env: env,
158+
dir: dir,
159+
timeout: timeout,
160+
}, null, new Responder(function (m) {
161+
_logger.log(`Invoke success: user=${_client.userId()}, path=${path}, args=${args}, env=${env}, dir=${dir}, timeout=${timeout}, pid=${m.Arguments.info.pid}`);
162+
result();
163+
}, function (m) {
164+
_logger.error(`Failed to invoke: user=${_client.userId()}, path=${path}, args=${args}, env=${env}, dir=${dir}, timeout=${timeout}, error=${m.Arguments.description}`);
165+
status(m.Arguments.description);
166+
}));
167+
return await ret;
168+
};
169+
170+
_this.quit = async function (pid) {
171+
return await _this.call(0, {
172+
name: Command.QUIT,
173+
pid: pid,
174+
}).then(() => {
175+
_logger.log(`Send quit success: user=${_client.userId()}, pid=${pid}`);
176+
}).catch((err) => {
177+
_logger.error(`Failed to send quit: user=${_client.userId()}, pid=${pid}, error=${err}`);
178+
});
179+
};
180+
150181
_this.send = async function (type, cast, id, data, payload) {
151182
var result, status;
152183
var ret = new Promise((resolve, reject) => {
153184
result = resolve;
154185
status = reject;
155186
});
156-
var args = {
187+
_this.call(0, {
157188
name: Command.SEND,
158189
type: type,
159190
cast: cast,
160191
id: id,
161192
data: data,
162-
};
163-
_this.call(0, args, payload, new Responder(function (m) {
193+
}, payload, new Responder(function (m) {
164194
_logger.log(`${data}: user=${_client.userId()}, cast=${cast}, to=${id}`);
165195
result();
166196
}, function (m) {

src/im/message/message.js

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
JOIN: 'join',
1414
LEAVE: 'leave',
1515
CHMOD: 'chmod',
16+
INVOKE: 'invoke',
17+
QUIT: 'quit',
1618
SEND: 'send',
1719
PLAY: 'play',
1820
STOP: 'stop',

src/im/ui/ui.js

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
_this.join = _im.join;
7878
_this.leave = _im.leave;
7979
_this.chmod = _im.chmod;
80+
_this.invoke = _im.invoke;
81+
_this.quit = _im.quit;
8082
_this.send = _im.send;
8183
_this.sendStatus = _im.sendStatus;
8284
_this.call = _im.call;

src/odd.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
odd = function () {
22
return {
3-
version: '2.5.00',
3+
version: '2.5.01',
44
};
55
};
66

0 commit comments

Comments
 (0)