|
90 | 90 | result = resolve;
|
91 | 91 | status = reject;
|
92 | 92 | });
|
93 |
| - var args = { |
| 93 | + _this.call(0, { |
94 | 94 | name: Command.JOIN,
|
95 | 95 | rid: rid,
|
96 |
| - }; |
97 |
| - _this.call(0, args, null, new Responder(function (m) { |
| 96 | + }, null, new Responder(function (m) { |
98 | 97 | _logger.log(`Join success: user=${_client.userId()}, room=${rid}`);
|
99 | 98 | result();
|
100 | 99 | }, function (m) {
|
|
110 | 109 | result = resolve;
|
111 | 110 | status = reject;
|
112 | 111 | });
|
113 |
| - var args = { |
| 112 | + _this.call(0, { |
114 | 113 | name: Command.LEAVE,
|
115 | 114 | rid: rid,
|
116 |
| - }; |
117 |
| - _this.call(0, args, null, new Responder(function (m) { |
| 115 | + }, null, new Responder(function (m) { |
118 | 116 | _logger.log(`Leave success: user=${_client.userId()}, room=${rid}`);
|
119 | 117 | result();
|
120 | 118 | }, function (m) {
|
|
130 | 128 | result = resolve;
|
131 | 129 | status = reject;
|
132 | 130 | });
|
133 |
| - var args = { |
| 131 | + _this.call(0, { |
134 | 132 | name: Command.CHMOD,
|
135 | 133 | rid: rid,
|
136 | 134 | tid: tid,
|
137 | 135 | operator: operator,
|
138 | 136 | mask: mask,
|
139 |
| - }; |
140 |
| - _this.call(0, args, null, new Responder(function (m) { |
| 137 | + }, null, new Responder(function (m) { |
141 | 138 | _logger.log(`Chmod success: user=${_client.userId()}, room=${rid}, target=${tid}, operator=${operator}, mask=${mask}`);
|
142 | 139 | result();
|
143 | 140 | }, function (m) {
|
|
147 | 144 | return await ret;
|
148 | 145 | };
|
149 | 146 |
|
| 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 | + |
150 | 181 | _this.send = async function (type, cast, id, data, payload) {
|
151 | 182 | var result, status;
|
152 | 183 | var ret = new Promise((resolve, reject) => {
|
153 | 184 | result = resolve;
|
154 | 185 | status = reject;
|
155 | 186 | });
|
156 |
| - var args = { |
| 187 | + _this.call(0, { |
157 | 188 | name: Command.SEND,
|
158 | 189 | type: type,
|
159 | 190 | cast: cast,
|
160 | 191 | id: id,
|
161 | 192 | data: data,
|
162 |
| - }; |
163 |
| - _this.call(0, args, payload, new Responder(function (m) { |
| 193 | + }, payload, new Responder(function (m) { |
164 | 194 | _logger.log(`${data}: user=${_client.userId()}, cast=${cast}, to=${id}`);
|
165 | 195 | result();
|
166 | 196 | }, function (m) {
|
|
0 commit comments