@cuecue/socketio 0.0.27 → 0.0.31

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 +40 -24
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1,10 +1,20 @@
1
- import createDebug from 'debug';
2
- import isArray from 'lodash/isArray';
3
- import { BasePlugin } from '@cuecue/core';
4
- import { io } from 'socket.io-client';
5
- import io$1 from 'socket.io';
1
+ 'use strict';
6
2
 
7
- class Base extends BasePlugin {
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var createDebug = require('debug');
6
+ var isArray = require('lodash/isArray');
7
+ var core = require('@cuecue/core');
8
+ var socket_ioClient = require('socket.io-client');
9
+ var io = require('socket.io');
10
+
11
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
+
13
+ var createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
14
+ var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);
15
+ var io__default = /*#__PURE__*/_interopDefaultLegacy(io);
16
+
17
+ class Base extends core.BasePlugin {
8
18
  constructor({
9
19
  commands = null,
10
20
  ...opts
@@ -16,7 +26,7 @@ class Base extends BasePlugin {
16
26
  });
17
27
  this.onConnect = this.onConnect.bind(this);
18
28
  this.commands = commands;
19
- this.debug = createDebug('cuecue:socketio');
29
+ this.debug = createDebug__default["default"]('cuecue:socketio');
20
30
  }
21
31
 
22
32
  async onInit() {
@@ -34,7 +44,7 @@ class Base extends BasePlugin {
34
44
  host,
35
45
  namespace
36
46
  } = this.options;
37
- this.socket = io(namespace !== null ? host.replace(/\/?$/, `/${namespace.replace(/^\//, '')}`) : host);
47
+ this.socket = socket_ioClient.io(namespace !== null ? host.replace(/\/?$/, `/${namespace.replace(/^\//, '')}`) : host);
38
48
  this.socket.on('connect', this.onConnect);
39
49
  return Promise.resolve();
40
50
  }
@@ -66,7 +76,7 @@ class ClientInput extends Base {
66
76
  });
67
77
  this.onMessage = this.onMessage.bind(this);
68
78
  this.commands = commands;
69
- this.debug = createDebug('cuecue:input:socketio');
79
+ this.debug = createDebug__default["default"]('cuecue:input:socketio');
70
80
  }
71
81
 
72
82
  setInputCommands(commands) {
@@ -100,7 +110,7 @@ class ClientInput extends Base {
100
110
 
101
111
  if (this.commands === null || this.commands.indexOf(finalCommand) !== -1) {
102
112
  this.debug('command: %s args: %o', finalCommand, finalArgs);
103
- this.emit('command', command, ...(isArray(finalArgs) ? finalArgs : [finalArgs]));
113
+ this.emit('command', command, ...(isArray__default["default"](finalArgs) ? finalArgs : [finalArgs]));
104
114
  } else {
105
115
  this.debug('message: %o', message);
106
116
  }
@@ -115,7 +125,7 @@ class ClientOutput extends Base {
115
125
  ...opts
116
126
  });
117
127
  this.socket = null;
118
- this.debug = createDebug('cuecue:output:socketio');
128
+ this.debug = createDebug__default["default"]('cuecue:output:socketio');
119
129
  }
120
130
 
121
131
  cue(cue, extraData = null) {
@@ -185,7 +195,7 @@ class ClientOutput extends Base {
185
195
 
186
196
  }
187
197
 
188
- class BaseServer extends BasePlugin {
198
+ class BaseServer extends core.BasePlugin {
189
199
  constructor({
190
200
  commands = null,
191
201
  ...opts
@@ -199,7 +209,7 @@ class BaseServer extends BasePlugin {
199
209
  this.io = null;
200
210
  this.onConnection = this.onConnection.bind(this);
201
211
  this.commands = commands;
202
- this.debug = createDebug('cuecue:socketio');
212
+ this.debug = createDebug__default["default"]('cuecue:socketio');
203
213
  }
204
214
 
205
215
  async onInit() {
@@ -208,23 +218,26 @@ class BaseServer extends BasePlugin {
208
218
  }
209
219
 
210
220
  async onDestroy() {
211
- await this.closeSocket();
221
+ await this.closeServer();
212
222
  await super.onDestroy();
213
223
  }
214
224
 
215
- async connectSocket() {
225
+ async createServer() {
216
226
  const {
217
227
  server,
218
- port
228
+ port,
229
+ cors
219
230
  } = this.options;
220
- const ioOptions = {};
221
- this.io = io$1(ioOptions);
231
+ const ioOptions = {
232
+ cors
233
+ };
234
+ this.io = io__default["default"](ioOptions);
222
235
  this.io.on('connection', this.onConnection);
223
236
  this.io.listen(server || port);
224
237
  return Promise.resolve();
225
238
  }
226
239
 
227
- async closeSocket() {
240
+ async closeServer() {
228
241
  this.io.off('connection', this.onConnection);
229
242
  return new Promise(resolve => {
230
243
  this.io.close(() => {
@@ -251,7 +264,7 @@ class ServerInput extends BaseServer {
251
264
  this.onSocketConnection = this.onSocketConnection.bind(this);
252
265
  this.onMessage = this.onMessage.bind(this);
253
266
  this.commands = commands;
254
- this.debug = createDebug('cuecue:input:socketio-server');
267
+ this.debug = createDebug__default["default"]('cuecue:input:socketio-server');
255
268
  }
256
269
 
257
270
  setInputCommands(commands) {
@@ -306,7 +319,7 @@ class ServerInput extends BaseServer {
306
319
 
307
320
  if (this.commands === null || this.commands.indexOf(finalCommand) !== -1) {
308
321
  this.debug('command: %s args: %o', finalCommand, finalArgs);
309
- this.emit('command', command, ...(isArray(finalArgs) ? finalArgs : [finalArgs]));
322
+ this.emit('command', command, ...(isArray__default["default"](finalArgs) ? finalArgs : [finalArgs]));
310
323
  } else {
311
324
  this.debug('message: %o', message);
312
325
  }
@@ -314,14 +327,14 @@ class ServerInput extends BaseServer {
314
327
 
315
328
  }
316
329
 
317
- class ServerOutput extends Base {
330
+ class ServerOutput extends BaseServer {
318
331
  constructor(opts = {}) {
319
332
  super({
320
333
  namespace: process.env.SOCKETIO_OUTPUT_NAMESPACE || null,
321
334
  ...opts
322
335
  });
323
336
  this.socket = null;
324
- this.debug = createDebug('cuecue:output:socketio');
337
+ this.debug = createDebug__default["default"]('cuecue:output:socketio');
325
338
  }
326
339
 
327
340
  cue(cue, extraData = null) {
@@ -406,4 +419,7 @@ class ServerOutput extends Base {
406
419
 
407
420
  }
408
421
 
409
- export { ClientInput as Input, ClientOutput as Output, ServerInput, ServerOutput };
422
+ exports.Input = ClientInput;
423
+ exports.Output = ClientOutput;
424
+ exports.ServerInput = ServerInput;
425
+ exports.ServerOutput = ServerOutput;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuecue/socketio",
3
- "version": "0.0.27",
3
+ "version": "0.0.31",
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.27",
43
+ "@cuecue/core": "^0.0.31",
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": "2c305c0d1c0b13469fe74e2b928c0b45744c8ac0"
53
+ "gitHead": "bc6f4b36d80e298f4f70cb3f581f5bf3f856dadd"
54
54
  }