@cuecue/socketio 0.0.29 → 0.0.33

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.
Files changed (2) hide show
  1. package/dist/index.js +16 -44
  2. 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.closeSocket();
222
+ await this.closeServer();
222
223
  await super.onDestroy();
223
224
  }
224
225
 
225
- async connectSocket() {
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.on('connection', this.onConnection);
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 closeSocket() {
238
- this.io.off('connection', this.onConnection);
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 onInit() {
273
- await super.onInit();
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
 
@@ -396,15 +376,7 @@ class ServerOutput extends BaseServer {
396
376
 
397
377
  async send(...args) {
398
378
  this.debug('send: %o', args);
399
- const {
400
- namespace = null
401
- } = this.options;
402
-
403
- if (namespace !== null) {
404
- return this.sendToNamespace(namespace, ...args);
405
- }
406
-
407
- this.io.send(...args);
379
+ this.namespace.send(...args);
408
380
  return Promise.resolve();
409
381
  }
410
382
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuecue/socketio",
3
- "version": "0.0.29",
3
+ "version": "0.0.33",
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.29",
43
+ "@cuecue/core": "^0.0.33",
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": "00a8a8ab630e0fe5e6433d8f4b00500ccf8446b6"
53
+ "gitHead": "d1b75d2689630be436bf18e1fda1a8d48365a84d"
54
54
  }