@cuecue/socketio 0.0.26 → 0.0.30

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 (3) hide show
  1. package/dist/index.js +422 -0
  2. package/package.json +8 -6
  3. package/lib/index.js +0 -579
package/dist/index.js ADDED
@@ -0,0 +1,422 @@
1
+ 'use strict';
2
+
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 {
18
+ constructor({
19
+ commands = null,
20
+ ...opts
21
+ } = {}) {
22
+ super({
23
+ host: process.env.SOCKETIO_HOST || 'localhost',
24
+ namespace: process.env.SOCKETIO_NAMESPACE || null,
25
+ ...opts
26
+ });
27
+ this.onConnect = this.onConnect.bind(this);
28
+ this.commands = commands;
29
+ this.debug = createDebug__default["default"]('cuecue:socketio');
30
+ }
31
+
32
+ async onInit() {
33
+ await super.onInit();
34
+ await this.connectSocket();
35
+ }
36
+
37
+ async onDestroy() {
38
+ await this.closeSocket();
39
+ await super.onDestroy();
40
+ }
41
+
42
+ async connectSocket() {
43
+ const {
44
+ host,
45
+ namespace
46
+ } = this.options;
47
+ this.socket = socket_ioClient.io(namespace !== null ? host.replace(/\/?$/, `/${namespace.replace(/^\//, '')}`) : host);
48
+ this.socket.on('connect', this.onConnect);
49
+ return Promise.resolve();
50
+ }
51
+
52
+ async closeSocket() {
53
+ this.socket.off('connect', this.onConnect);
54
+ this.socket.close();
55
+ return Promise.resolve();
56
+ }
57
+
58
+ onConnect() {
59
+ const {
60
+ host,
61
+ namespace
62
+ } = this.options;
63
+ this.debug('Connected on %s/%s', host, namespace || '');
64
+ }
65
+
66
+ }
67
+
68
+ class ClientInput extends Base {
69
+ constructor({
70
+ commands = null,
71
+ ...opts
72
+ } = {}) {
73
+ super({
74
+ namespace: process.env.SOCKETIO_INPUT_NAMESPACE || null,
75
+ ...opts
76
+ });
77
+ this.onMessage = this.onMessage.bind(this);
78
+ this.commands = commands;
79
+ this.debug = createDebug__default["default"]('cuecue:input:socketio');
80
+ }
81
+
82
+ setInputCommands(commands) {
83
+ this.commands = commands;
84
+ return this;
85
+ }
86
+
87
+ async onInit() {
88
+ await super.onInit();
89
+ this.socket.on('message', this.onMessage);
90
+ }
91
+
92
+ async onDestroy() {
93
+ this.socket.off('message', this.onMessage);
94
+ await super.onDestroy();
95
+ }
96
+
97
+ async onMessage(message) {
98
+ const {
99
+ transformMessage = null,
100
+ transformCommand = null
101
+ } = this.options;
102
+ const {
103
+ command = null,
104
+ args = []
105
+ } = (transformMessage !== null ? await transformMessage(message) : message) || {};
106
+ const {
107
+ command: finalCommand = command,
108
+ args: finalArgs = args
109
+ } = (transformCommand !== null ? await transformCommand(command, args) : null) || {};
110
+
111
+ if (this.commands === null || this.commands.indexOf(finalCommand) !== -1) {
112
+ this.debug('command: %s args: %o', finalCommand, finalArgs);
113
+ this.emit('command', command, ...(isArray__default["default"](finalArgs) ? finalArgs : [finalArgs]));
114
+ } else {
115
+ this.debug('message: %o', message);
116
+ }
117
+ }
118
+
119
+ }
120
+
121
+ class ClientOutput extends Base {
122
+ constructor(opts = {}) {
123
+ super({
124
+ namespace: process.env.SOCKETIO_OUTPUT_NAMESPACE || null,
125
+ ...opts
126
+ });
127
+ this.socket = null;
128
+ this.debug = createDebug__default["default"]('cuecue:output:socketio');
129
+ }
130
+
131
+ cue(cue, extraData = null) {
132
+ this.command('cue', cue, extraData);
133
+ }
134
+
135
+ cues(cues) {
136
+ this.command('cues', cues);
137
+ }
138
+
139
+ interact(data, interactionId = null) {
140
+ this.command('interact', data, interactionId);
141
+ }
142
+
143
+ interaction(interaction) {
144
+ this.command('interaction', interaction);
145
+ }
146
+
147
+ uninteraction(interactionId) {
148
+ this.command('uninteract', interactionId);
149
+ }
150
+
151
+ uninteractions(interactionIds) {
152
+ this.command('uninteractions', interactionIds);
153
+ }
154
+
155
+ async command(command, ...args) {
156
+ const {
157
+ transformCommand = null,
158
+ transformMessage = null,
159
+ acceptCommand = null
160
+ } = this.options;
161
+ const value = transformCommand !== null ? await transformCommand(command, args) : {
162
+ command,
163
+ args
164
+ };
165
+
166
+ if (value === false) {
167
+ this.debug('command canceled: %s %o', command, args);
168
+ return Promise.resolve();
169
+ }
170
+
171
+ const {
172
+ command: finalCommand = command,
173
+ args: finalArgs = args
174
+ } = value || {};
175
+
176
+ if (acceptCommand !== null && !acceptCommand(finalCommand, finalArgs)) {
177
+ this.debug('command refused: %s %o', finalCommand, finalArgs);
178
+ return Promise.resolve();
179
+ }
180
+
181
+ this.debug('command: %s message: %o', finalCommand, finalArgs);
182
+ const message = {
183
+ command: finalCommand,
184
+ args: finalArgs
185
+ };
186
+ const payload = transformMessage !== null ? await transformMessage(message) : message;
187
+ return this.send(payload);
188
+ }
189
+
190
+ async send(...args) {
191
+ this.debug('send: %o', args);
192
+ this.socket.send(...args);
193
+ return Promise.resolve();
194
+ }
195
+
196
+ }
197
+
198
+ class BaseServer extends core.BasePlugin {
199
+ constructor({
200
+ commands = null,
201
+ ...opts
202
+ } = {}) {
203
+ super({
204
+ port: process.env.SOCKETIO_PORT || 3000,
205
+ namespace: process.env.SOCKETIO_NAMESPACE || null,
206
+ server: null,
207
+ ...opts
208
+ });
209
+ this.io = null;
210
+ this.onConnection = this.onConnection.bind(this);
211
+ this.commands = commands;
212
+ this.debug = createDebug__default["default"]('cuecue:socketio');
213
+ }
214
+
215
+ async onInit() {
216
+ await super.onInit();
217
+ await this.createServer();
218
+ }
219
+
220
+ async onDestroy() {
221
+ await this.closeServer();
222
+ await super.onDestroy();
223
+ }
224
+
225
+ async createServer() {
226
+ const {
227
+ server,
228
+ port
229
+ } = this.options;
230
+ const ioOptions = {};
231
+ this.io = io__default["default"](ioOptions);
232
+ this.io.on('connection', this.onConnection);
233
+ this.io.listen(server || port);
234
+ return Promise.resolve();
235
+ }
236
+
237
+ async closeServer() {
238
+ this.io.off('connection', this.onConnection);
239
+ return new Promise(resolve => {
240
+ this.io.close(() => {
241
+ resolve();
242
+ });
243
+ });
244
+ }
245
+
246
+ onConnection(socket) {
247
+ this.debug('Client connected %s', socket.id);
248
+ }
249
+
250
+ }
251
+
252
+ class ServerInput extends BaseServer {
253
+ constructor({
254
+ commands = null,
255
+ ...opts
256
+ } = {}) {
257
+ super({
258
+ namespace: process.env.SOCKETIO_INPUT_NAMESPACE || null,
259
+ ...opts
260
+ });
261
+ this.onSocketConnection = this.onSocketConnection.bind(this);
262
+ this.onMessage = this.onMessage.bind(this);
263
+ this.commands = commands;
264
+ this.debug = createDebug__default["default"]('cuecue:input:socketio-server');
265
+ }
266
+
267
+ setInputCommands(commands) {
268
+ this.commands = commands;
269
+ return this;
270
+ }
271
+
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) {
300
+ socket.on('message', this.onMessage);
301
+ }
302
+
303
+ async onMessage(message) {
304
+ const {
305
+ transformMessage = null,
306
+ transformCommand = null
307
+ } = this.options;
308
+ const {
309
+ command = null,
310
+ args = []
311
+ } = (transformMessage !== null ? await transformMessage(message) : message) || {};
312
+ const {
313
+ command: finalCommand = command,
314
+ args: finalArgs = args
315
+ } = (transformCommand !== null ? await transformCommand(command, args) : null) || {};
316
+
317
+ if (this.commands === null || this.commands.indexOf(finalCommand) !== -1) {
318
+ this.debug('command: %s args: %o', finalCommand, finalArgs);
319
+ this.emit('command', command, ...(isArray__default["default"](finalArgs) ? finalArgs : [finalArgs]));
320
+ } else {
321
+ this.debug('message: %o', message);
322
+ }
323
+ }
324
+
325
+ }
326
+
327
+ class ServerOutput extends BaseServer {
328
+ constructor(opts = {}) {
329
+ super({
330
+ namespace: process.env.SOCKETIO_OUTPUT_NAMESPACE || null,
331
+ ...opts
332
+ });
333
+ this.socket = null;
334
+ this.debug = createDebug__default["default"]('cuecue:output:socketio');
335
+ }
336
+
337
+ cue(cue, extraData = null) {
338
+ this.command('cue', cue, extraData);
339
+ }
340
+
341
+ cues(cues) {
342
+ this.command('cues', cues);
343
+ }
344
+
345
+ interact(data, interactionId = null) {
346
+ this.command('interact', data, interactionId);
347
+ }
348
+
349
+ interaction(interaction) {
350
+ this.command('interaction', interaction);
351
+ }
352
+
353
+ uninteraction(interactionId) {
354
+ this.command('uninteract', interactionId);
355
+ }
356
+
357
+ uninteractions(interactionIds) {
358
+ this.command('uninteractions', interactionIds);
359
+ }
360
+
361
+ async command(command, ...args) {
362
+ const {
363
+ transformCommand = null,
364
+ transformMessage = null,
365
+ acceptCommand = null
366
+ } = this.options;
367
+ const value = transformCommand !== null ? await transformCommand(command, args) : {
368
+ command,
369
+ args
370
+ };
371
+
372
+ if (value === false) {
373
+ this.debug('command canceled: %s %o', command, args);
374
+ return Promise.resolve();
375
+ }
376
+
377
+ const {
378
+ command: finalCommand = command,
379
+ args: finalArgs = args,
380
+ namespace = null
381
+ } = value || {};
382
+
383
+ if (acceptCommand !== null && !acceptCommand(finalCommand, finalArgs)) {
384
+ this.debug('command refused: %s %o', finalCommand, finalArgs);
385
+ return Promise.resolve();
386
+ }
387
+
388
+ this.debug('command: %s message: %o', finalCommand, finalArgs);
389
+ const message = {
390
+ command: finalCommand,
391
+ args: finalArgs
392
+ };
393
+ const payload = transformMessage !== null ? await transformMessage(message) : message;
394
+ return namespace !== null ? this.sendToNamespace(payload) : this.send(payload);
395
+ }
396
+
397
+ async send(...args) {
398
+ 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);
408
+ return Promise.resolve();
409
+ }
410
+
411
+ async sendToNamespace(namespace, ...args) {
412
+ this.debug('send: %o', args);
413
+ this.io.of(namespace).send(...args);
414
+ return Promise.resolve();
415
+ }
416
+
417
+ }
418
+
419
+ exports.Input = ClientInput;
420
+ exports.Output = ClientOutput;
421
+ exports.ServerInput = ServerInput;
422
+ exports.ServerOutput = ServerOutput;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuecue/socketio",
3
- "version": "0.0.26",
3
+ "version": "0.0.30",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "javascript"
@@ -29,16 +29,18 @@
29
29
  }
30
30
  ],
31
31
  "license": "ISC",
32
- "main": "lib/index.js",
32
+ "main": "dist/index.js",
33
33
  "files": [
34
- "lib"
34
+ "dist"
35
35
  ],
36
36
  "scripts": {
37
- "prepare": "../../scripts/prepare-package.sh"
37
+ "clean": "rm -rf dist",
38
+ "build": "rollup --config ../../rollup.config.js",
39
+ "prepare": "npm run clean && npm run build"
38
40
  },
39
41
  "dependencies": {
40
42
  "@babel/runtime": "^7.12.5",
41
- "@cuecue/core": "^0.0.26",
43
+ "@cuecue/core": "^0.0.30",
42
44
  "debug": "^4.3.1",
43
45
  "lodash": "^4.17.20",
44
46
  "socket.io": "^4.1.2",
@@ -48,5 +50,5 @@
48
50
  "publishConfig": {
49
51
  "access": "public"
50
52
  },
51
- "gitHead": "afce8c2fc41b6769e95299e85008d3d82666512f"
53
+ "gitHead": "78c5a9302ba7d9bb047c70e174261989d6babf5a"
52
54
  }
package/lib/index.js DELETED
@@ -1,579 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
6
- var _regeneratorRuntime = require('@babel/runtime/regenerator');
7
- var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
8
- var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
9
- var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
10
- var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
11
- var _createClass = require('@babel/runtime/helpers/createClass');
12
- var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized');
13
- var _get = require('@babel/runtime/helpers/get');
14
- var _getPrototypeOf = require('@babel/runtime/helpers/getPrototypeOf');
15
- var _inherits = require('@babel/runtime/helpers/inherits');
16
- var _createSuper = require('@babel/runtime/helpers/createSuper');
17
- var createDebug = require('debug');
18
- var isArray = require('lodash/isArray');
19
- var core = require('@cuecue/core');
20
- var socket_ioClient = require('socket.io-client');
21
-
22
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
23
-
24
- var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
25
- var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
26
- var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
27
- var _objectSpread__default = /*#__PURE__*/_interopDefaultLegacy(_objectSpread);
28
- var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
29
- var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
30
- var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
31
- var _assertThisInitialized__default = /*#__PURE__*/_interopDefaultLegacy(_assertThisInitialized);
32
- var _get__default = /*#__PURE__*/_interopDefaultLegacy(_get);
33
- var _getPrototypeOf__default = /*#__PURE__*/_interopDefaultLegacy(_getPrototypeOf);
34
- var _inherits__default = /*#__PURE__*/_interopDefaultLegacy(_inherits);
35
- var _createSuper__default = /*#__PURE__*/_interopDefaultLegacy(_createSuper);
36
- var createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
37
- var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);
38
-
39
- var Base = /*#__PURE__*/function (_BasePlugin) {
40
- _inherits__default['default'](Base, _BasePlugin);
41
-
42
- var _super = _createSuper__default['default'](Base);
43
-
44
- function Base() {
45
- var _this;
46
-
47
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
48
- _ref$commands = _ref.commands,
49
- commands = _ref$commands === void 0 ? null : _ref$commands,
50
- opts = _objectWithoutProperties__default['default'](_ref, ["commands"]);
51
-
52
- _classCallCheck__default['default'](this, Base);
53
-
54
- _this = _super.call(this, _objectSpread__default['default']({
55
- host: process.env.SOCKETIO_HOST || 'localhost',
56
- namespace: process.env.SOCKETIO_NAMESPACE || null
57
- }, opts));
58
- _this.onConnect = _this.onConnect.bind(_assertThisInitialized__default['default'](_this));
59
- _this.commands = commands;
60
- _this.debug = createDebug__default['default']('cuecue:socketio');
61
- return _this;
62
- }
63
-
64
- _createClass__default['default'](Base, [{
65
- key: "onInit",
66
- value: function () {
67
- var _onInit = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee() {
68
- return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
69
- while (1) {
70
- switch (_context.prev = _context.next) {
71
- case 0:
72
- _context.next = 2;
73
- return _get__default['default'](_getPrototypeOf__default['default'](Base.prototype), "onInit", this).call(this);
74
-
75
- case 2:
76
- _context.next = 4;
77
- return this.connectSocket();
78
-
79
- case 4:
80
- case "end":
81
- return _context.stop();
82
- }
83
- }
84
- }, _callee, this);
85
- }));
86
-
87
- function onInit() {
88
- return _onInit.apply(this, arguments);
89
- }
90
-
91
- return onInit;
92
- }()
93
- }, {
94
- key: "onDestroy",
95
- value: function () {
96
- var _onDestroy = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2() {
97
- return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
98
- while (1) {
99
- switch (_context2.prev = _context2.next) {
100
- case 0:
101
- _context2.next = 2;
102
- return this.closeSocket();
103
-
104
- case 2:
105
- _context2.next = 4;
106
- return _get__default['default'](_getPrototypeOf__default['default'](Base.prototype), "onDestroy", this).call(this);
107
-
108
- case 4:
109
- case "end":
110
- return _context2.stop();
111
- }
112
- }
113
- }, _callee2, this);
114
- }));
115
-
116
- function onDestroy() {
117
- return _onDestroy.apply(this, arguments);
118
- }
119
-
120
- return onDestroy;
121
- }()
122
- }, {
123
- key: "connectSocket",
124
- value: function () {
125
- var _connectSocket = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee3() {
126
- var _this$options, host, namespace;
127
-
128
- return _regeneratorRuntime__default['default'].wrap(function _callee3$(_context3) {
129
- while (1) {
130
- switch (_context3.prev = _context3.next) {
131
- case 0:
132
- _this$options = this.options, host = _this$options.host, namespace = _this$options.namespace;
133
- this.socket = socket_ioClient.io(namespace !== null ? host.replace(/\/?$/, "/".concat(namespace.replace(/^\//, ''))) : host);
134
- this.socket.on('connect', this.onConnect);
135
- return _context3.abrupt("return", Promise.resolve());
136
-
137
- case 4:
138
- case "end":
139
- return _context3.stop();
140
- }
141
- }
142
- }, _callee3, this);
143
- }));
144
-
145
- function connectSocket() {
146
- return _connectSocket.apply(this, arguments);
147
- }
148
-
149
- return connectSocket;
150
- }()
151
- }, {
152
- key: "closeSocket",
153
- value: function () {
154
- var _closeSocket = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee4() {
155
- return _regeneratorRuntime__default['default'].wrap(function _callee4$(_context4) {
156
- while (1) {
157
- switch (_context4.prev = _context4.next) {
158
- case 0:
159
- this.socket.off('connect', this.onConnect);
160
- this.socket.close();
161
- return _context4.abrupt("return", Promise.resolve());
162
-
163
- case 3:
164
- case "end":
165
- return _context4.stop();
166
- }
167
- }
168
- }, _callee4, this);
169
- }));
170
-
171
- function closeSocket() {
172
- return _closeSocket.apply(this, arguments);
173
- }
174
-
175
- return closeSocket;
176
- }()
177
- }, {
178
- key: "onConnect",
179
- value: function onConnect() {
180
- var _this$options2 = this.options,
181
- host = _this$options2.host,
182
- namespace = _this$options2.namespace;
183
- this.debug('Connected on %s/%s', host, namespace || '');
184
- }
185
- }]);
186
-
187
- return Base;
188
- }(core.BasePlugin);
189
-
190
- var SocketIOInput = /*#__PURE__*/function (_Base) {
191
- _inherits__default['default'](SocketIOInput, _Base);
192
-
193
- var _super = _createSuper__default['default'](SocketIOInput);
194
-
195
- function SocketIOInput() {
196
- var _this;
197
-
198
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
199
- _ref$commands = _ref.commands,
200
- commands = _ref$commands === void 0 ? null : _ref$commands,
201
- opts = _objectWithoutProperties__default['default'](_ref, ["commands"]);
202
-
203
- _classCallCheck__default['default'](this, SocketIOInput);
204
-
205
- _this = _super.call(this, _objectSpread__default['default']({
206
- namespace: process.env.SOCKETIO_INPUT_NAMESPACE || null
207
- }, opts));
208
- _this.onMessage = _this.onMessage.bind(_assertThisInitialized__default['default'](_this));
209
- _this.commands = commands;
210
- _this.debug = createDebug__default['default']('cuecue:input:socketio');
211
- return _this;
212
- }
213
-
214
- _createClass__default['default'](SocketIOInput, [{
215
- key: "setInputCommands",
216
- value: function setInputCommands(commands) {
217
- this.commands = commands;
218
- return this;
219
- }
220
- }, {
221
- key: "onInit",
222
- value: function () {
223
- var _onInit = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee() {
224
- return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
225
- while (1) {
226
- switch (_context.prev = _context.next) {
227
- case 0:
228
- _context.next = 2;
229
- return _get__default['default'](_getPrototypeOf__default['default'](SocketIOInput.prototype), "onInit", this).call(this);
230
-
231
- case 2:
232
- this.socket.on('message', this.onMessage);
233
-
234
- case 3:
235
- case "end":
236
- return _context.stop();
237
- }
238
- }
239
- }, _callee, this);
240
- }));
241
-
242
- function onInit() {
243
- return _onInit.apply(this, arguments);
244
- }
245
-
246
- return onInit;
247
- }()
248
- }, {
249
- key: "onDestroy",
250
- value: function () {
251
- var _onDestroy = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2() {
252
- return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
253
- while (1) {
254
- switch (_context2.prev = _context2.next) {
255
- case 0:
256
- this.socket.off('message', this.onMessage);
257
- _context2.next = 3;
258
- return _get__default['default'](_getPrototypeOf__default['default'](SocketIOInput.prototype), "onDestroy", this).call(this);
259
-
260
- case 3:
261
- case "end":
262
- return _context2.stop();
263
- }
264
- }
265
- }, _callee2, this);
266
- }));
267
-
268
- function onDestroy() {
269
- return _onDestroy.apply(this, arguments);
270
- }
271
-
272
- return onDestroy;
273
- }()
274
- }, {
275
- key: "onMessage",
276
- value: function () {
277
- var _onMessage = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee3(message) {
278
- var _this$options, _this$options$transfo, transformMessage, _this$options$transfo2, transformCommand, _ref2, _ref2$command, command, _ref2$args, args, _ref3, _ref3$command, finalCommand, _ref3$args, finalArgs;
279
-
280
- return _regeneratorRuntime__default['default'].wrap(function _callee3$(_context3) {
281
- while (1) {
282
- switch (_context3.prev = _context3.next) {
283
- case 0:
284
- _this$options = this.options, _this$options$transfo = _this$options.transformMessage, transformMessage = _this$options$transfo === void 0 ? null : _this$options$transfo, _this$options$transfo2 = _this$options.transformCommand, transformCommand = _this$options$transfo2 === void 0 ? null : _this$options$transfo2;
285
-
286
- if (!(transformMessage !== null)) {
287
- _context3.next = 7;
288
- break;
289
- }
290
-
291
- _context3.next = 4;
292
- return transformMessage(message);
293
-
294
- case 4:
295
- _context3.t1 = _context3.sent;
296
- _context3.next = 8;
297
- break;
298
-
299
- case 7:
300
- _context3.t1 = message;
301
-
302
- case 8:
303
- _context3.t0 = _context3.t1;
304
-
305
- if (_context3.t0) {
306
- _context3.next = 11;
307
- break;
308
- }
309
-
310
- _context3.t0 = {};
311
-
312
- case 11:
313
- _ref2 = _context3.t0;
314
- _ref2$command = _ref2.command;
315
- command = _ref2$command === void 0 ? null : _ref2$command;
316
- _ref2$args = _ref2.args;
317
- args = _ref2$args === void 0 ? [] : _ref2$args;
318
-
319
- if (!(transformCommand !== null)) {
320
- _context3.next = 22;
321
- break;
322
- }
323
-
324
- _context3.next = 19;
325
- return transformCommand(command, args);
326
-
327
- case 19:
328
- _context3.t3 = _context3.sent;
329
- _context3.next = 23;
330
- break;
331
-
332
- case 22:
333
- _context3.t3 = null;
334
-
335
- case 23:
336
- _context3.t2 = _context3.t3;
337
-
338
- if (_context3.t2) {
339
- _context3.next = 26;
340
- break;
341
- }
342
-
343
- _context3.t2 = {};
344
-
345
- case 26:
346
- _ref3 = _context3.t2;
347
- _ref3$command = _ref3.command;
348
- finalCommand = _ref3$command === void 0 ? command : _ref3$command;
349
- _ref3$args = _ref3.args;
350
- finalArgs = _ref3$args === void 0 ? args : _ref3$args;
351
-
352
- if (this.commands === null || this.commands.indexOf(finalCommand) !== -1) {
353
- this.debug('command: %s args: %o', finalCommand, finalArgs);
354
- this.emit.apply(this, ['command', command].concat(_toConsumableArray__default['default'](isArray__default['default'](finalArgs) ? finalArgs : [finalArgs])));
355
- } else {
356
- this.debug('message: %o', message);
357
- }
358
-
359
- case 32:
360
- case "end":
361
- return _context3.stop();
362
- }
363
- }
364
- }, _callee3, this);
365
- }));
366
-
367
- function onMessage(_x) {
368
- return _onMessage.apply(this, arguments);
369
- }
370
-
371
- return onMessage;
372
- }()
373
- }]);
374
-
375
- return SocketIOInput;
376
- }(Base);
377
-
378
- var SocketIOOutput = /*#__PURE__*/function (_Base) {
379
- _inherits__default['default'](SocketIOOutput, _Base);
380
-
381
- var _super = _createSuper__default['default'](SocketIOOutput);
382
-
383
- function SocketIOOutput() {
384
- var _this;
385
-
386
- var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
387
-
388
- _classCallCheck__default['default'](this, SocketIOOutput);
389
-
390
- _this = _super.call(this, _objectSpread__default['default']({
391
- namespace: process.env.SOCKETIO_OUTPUT_NAMESPACE || null
392
- }, opts));
393
- _this.socket = null;
394
- _this.debug = createDebug__default['default']('cuecue:output:socketio');
395
- return _this;
396
- }
397
-
398
- _createClass__default['default'](SocketIOOutput, [{
399
- key: "cue",
400
- value: function cue(_cue) {
401
- var extraData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
402
- this.command('cue', _cue, extraData);
403
- }
404
- }, {
405
- key: "cues",
406
- value: function cues(_cues) {
407
- this.command('cues', _cues);
408
- }
409
- }, {
410
- key: "interact",
411
- value: function interact(data) {
412
- var interactionId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
413
- this.command('interact', data, interactionId);
414
- }
415
- }, {
416
- key: "interaction",
417
- value: function interaction(_interaction) {
418
- this.command('interaction', _interaction);
419
- }
420
- }, {
421
- key: "uninteraction",
422
- value: function uninteraction(interactionId) {
423
- this.command('uninteract', interactionId);
424
- }
425
- }, {
426
- key: "uninteractions",
427
- value: function uninteractions(interactionIds) {
428
- this.command('uninteractions', interactionIds);
429
- }
430
- }, {
431
- key: "command",
432
- value: function () {
433
- var _command2 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(_command) {
434
- var _this$options,
435
- _this$options$transfo,
436
- transformCommand,
437
- _this$options$transfo2,
438
- transformMessage,
439
- _len,
440
- args,
441
- _key,
442
- value,
443
- _ref,
444
- _ref$command,
445
- finalCommand,
446
- _ref$args,
447
- finalArgs,
448
- message,
449
- payload,
450
- _args = arguments;
451
-
452
- return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
453
- while (1) {
454
- switch (_context.prev = _context.next) {
455
- case 0:
456
- _this$options = this.options, _this$options$transfo = _this$options.transformCommand, transformCommand = _this$options$transfo === void 0 ? null : _this$options$transfo, _this$options$transfo2 = _this$options.transformMessage, transformMessage = _this$options$transfo2 === void 0 ? null : _this$options$transfo2;
457
-
458
- for (_len = _args.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
459
- args[_key - 1] = _args[_key];
460
- }
461
-
462
- if (!(transformCommand !== null)) {
463
- _context.next = 8;
464
- break;
465
- }
466
-
467
- _context.next = 5;
468
- return transformCommand(_command, args);
469
-
470
- case 5:
471
- _context.t0 = _context.sent;
472
- _context.next = 9;
473
- break;
474
-
475
- case 8:
476
- _context.t0 = {
477
- command: _command,
478
- args: args
479
- };
480
-
481
- case 9:
482
- value = _context.t0;
483
-
484
- if (!(value === false)) {
485
- _context.next = 13;
486
- break;
487
- }
488
-
489
- this.debug('command canceled: %s %o', _command, args);
490
- return _context.abrupt("return", Promise.resolve());
491
-
492
- case 13:
493
- _ref = value || {}, _ref$command = _ref.command, finalCommand = _ref$command === void 0 ? _command : _ref$command, _ref$args = _ref.args, finalArgs = _ref$args === void 0 ? args : _ref$args;
494
- this.debug('command: %s message: %o', finalCommand, finalArgs);
495
- message = {
496
- command: finalCommand,
497
- args: finalArgs
498
- };
499
-
500
- if (!(transformMessage !== null)) {
501
- _context.next = 22;
502
- break;
503
- }
504
-
505
- _context.next = 19;
506
- return transformMessage(message);
507
-
508
- case 19:
509
- _context.t1 = _context.sent;
510
- _context.next = 23;
511
- break;
512
-
513
- case 22:
514
- _context.t1 = message;
515
-
516
- case 23:
517
- payload = _context.t1;
518
- return _context.abrupt("return", this.send(payload));
519
-
520
- case 25:
521
- case "end":
522
- return _context.stop();
523
- }
524
- }
525
- }, _callee, this);
526
- }));
527
-
528
- function command(_x) {
529
- return _command2.apply(this, arguments);
530
- }
531
-
532
- return command;
533
- }()
534
- }, {
535
- key: "send",
536
- value: function () {
537
- var _send = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2() {
538
- var _this$socket;
539
-
540
- var _len2,
541
- args,
542
- _key2,
543
- _args2 = arguments;
544
-
545
- return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
546
- while (1) {
547
- switch (_context2.prev = _context2.next) {
548
- case 0:
549
- for (_len2 = _args2.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
550
- args[_key2] = _args2[_key2];
551
- }
552
-
553
- this.debug('send: %o', args);
554
-
555
- (_this$socket = this.socket).send.apply(_this$socket, args);
556
-
557
- return _context2.abrupt("return", Promise.resolve());
558
-
559
- case 4:
560
- case "end":
561
- return _context2.stop();
562
- }
563
- }
564
- }, _callee2, this);
565
- }));
566
-
567
- function send() {
568
- return _send.apply(this, arguments);
569
- }
570
-
571
- return send;
572
- }()
573
- }]);
574
-
575
- return SocketIOOutput;
576
- }(Base);
577
-
578
- exports.Input = SocketIOInput;
579
- exports.Output = SocketIOOutput;