@cuecue/socketio 0.0.28 → 0.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +18 -38
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -207,6 +207,7 @@ class BaseServer extends core.BasePlugin {
|
|
|
207
207
|
...opts
|
|
208
208
|
});
|
|
209
209
|
this.io = null;
|
|
210
|
+
this.namespace - null;
|
|
210
211
|
this.onConnection = this.onConnection.bind(this);
|
|
211
212
|
this.commands = commands;
|
|
212
213
|
this.debug = createDebug__default["default"]('cuecue:socketio');
|
|
@@ -218,24 +219,29 @@ class BaseServer extends core.BasePlugin {
|
|
|
218
219
|
}
|
|
219
220
|
|
|
220
221
|
async onDestroy() {
|
|
221
|
-
await this.
|
|
222
|
+
await this.closeServer();
|
|
222
223
|
await super.onDestroy();
|
|
223
224
|
}
|
|
224
225
|
|
|
225
|
-
async
|
|
226
|
+
async createServer() {
|
|
226
227
|
const {
|
|
227
228
|
server,
|
|
228
|
-
port
|
|
229
|
+
port,
|
|
230
|
+
cors,
|
|
231
|
+
namespace
|
|
229
232
|
} = this.options;
|
|
230
|
-
const ioOptions = {
|
|
233
|
+
const ioOptions = {
|
|
234
|
+
cors
|
|
235
|
+
};
|
|
231
236
|
this.io = io__default["default"](ioOptions);
|
|
232
|
-
this.io.
|
|
237
|
+
this.namespace = namespace !== null ? this.io.of(namespace) : this.io;
|
|
238
|
+
this.namespace.on('connection', this.onConnection);
|
|
233
239
|
this.io.listen(server || port);
|
|
234
240
|
return Promise.resolve();
|
|
235
241
|
}
|
|
236
242
|
|
|
237
|
-
async
|
|
238
|
-
this.
|
|
243
|
+
async closeServer() {
|
|
244
|
+
this.namespace.off('connection', this.onConnection);
|
|
239
245
|
return new Promise(resolve => {
|
|
240
246
|
this.io.close(() => {
|
|
241
247
|
resolve();
|
|
@@ -269,34 +275,8 @@ class ServerInput extends BaseServer {
|
|
|
269
275
|
return this;
|
|
270
276
|
}
|
|
271
277
|
|
|
272
|
-
async
|
|
273
|
-
await super.
|
|
274
|
-
const {
|
|
275
|
-
namespace
|
|
276
|
-
} = this.namespace;
|
|
277
|
-
|
|
278
|
-
if (namespace !== null) {
|
|
279
|
-
this.io.of(namespace).on('connection', this.onSocketConnection);
|
|
280
|
-
} else {
|
|
281
|
-
this.io.on('connection', this.onSocketConnection);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
async onDestroy() {
|
|
286
|
-
const {
|
|
287
|
-
namespace
|
|
288
|
-
} = this.namespace;
|
|
289
|
-
|
|
290
|
-
if (namespace !== null) {
|
|
291
|
-
this.io.of(namespace).off('connection', this.onSocketConnection);
|
|
292
|
-
} else {
|
|
293
|
-
this.io.off('connection', this.onSocketConnection);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
await super.onDestroy();
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
async onSocketConnection(socket) {
|
|
278
|
+
async onConnection(socket) {
|
|
279
|
+
await super.onConnection(socket);
|
|
300
280
|
socket.on('message', this.onMessage);
|
|
301
281
|
}
|
|
302
282
|
|
|
@@ -324,7 +304,7 @@ class ServerInput extends BaseServer {
|
|
|
324
304
|
|
|
325
305
|
}
|
|
326
306
|
|
|
327
|
-
class ServerOutput extends
|
|
307
|
+
class ServerOutput extends BaseServer {
|
|
328
308
|
constructor(opts = {}) {
|
|
329
309
|
super({
|
|
330
310
|
namespace: process.env.SOCKETIO_OUTPUT_NAMESPACE || null,
|
|
@@ -404,13 +384,13 @@ class ServerOutput extends Base {
|
|
|
404
384
|
return this.sendToNamespace(namespace, ...args);
|
|
405
385
|
}
|
|
406
386
|
|
|
407
|
-
this.
|
|
387
|
+
this.namespace.send(...args);
|
|
408
388
|
return Promise.resolve();
|
|
409
389
|
}
|
|
410
390
|
|
|
411
391
|
async sendToNamespace(namespace, ...args) {
|
|
412
392
|
this.debug('send: %o', args);
|
|
413
|
-
this.
|
|
393
|
+
this.namespace.of(namespace).send(...args);
|
|
414
394
|
return Promise.resolve();
|
|
415
395
|
}
|
|
416
396
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cuecue/socketio",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@babel/runtime": "^7.12.5",
|
|
43
|
-
"@cuecue/core": "^0.0.
|
|
43
|
+
"@cuecue/core": "^0.0.32",
|
|
44
44
|
"debug": "^4.3.1",
|
|
45
45
|
"lodash": "^4.17.20",
|
|
46
46
|
"socket.io": "^4.1.2",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "ea2dab28c212c792af3cf1da9ef5e6603c408207"
|
|
54
54
|
}
|