@cuecue/socketio 0.0.43 → 0.0.44
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 +8 -65
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var createDebug = require('debug');
|
|
6
4
|
var isArray = require('lodash/isArray');
|
|
7
5
|
var core = require('@cuecue/core');
|
|
8
6
|
var socket_ioClient = require('socket.io-client');
|
|
9
7
|
var socket_io = require('socket.io');
|
|
10
8
|
|
|
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
|
-
|
|
16
9
|
class Base extends core.BasePlugin {
|
|
17
10
|
constructor({
|
|
18
11
|
commands = null,
|
|
@@ -26,19 +19,16 @@ class Base extends core.BasePlugin {
|
|
|
26
19
|
});
|
|
27
20
|
this.onConnect = this.onConnect.bind(this);
|
|
28
21
|
this.commands = commands;
|
|
29
|
-
this.debug =
|
|
22
|
+
this.debug = createDebug('cuecue:socketio');
|
|
30
23
|
}
|
|
31
|
-
|
|
32
24
|
async onInit() {
|
|
33
25
|
await super.onInit();
|
|
34
26
|
await this.connectSocket();
|
|
35
27
|
}
|
|
36
|
-
|
|
37
28
|
async onDestroy() {
|
|
38
29
|
await this.closeSocket();
|
|
39
30
|
await super.onDestroy();
|
|
40
31
|
}
|
|
41
|
-
|
|
42
32
|
async connectSocket() {
|
|
43
33
|
const {
|
|
44
34
|
host,
|
|
@@ -51,13 +41,11 @@ class Base extends core.BasePlugin {
|
|
|
51
41
|
this.socket.on('connect', this.onConnect);
|
|
52
42
|
return Promise.resolve();
|
|
53
43
|
}
|
|
54
|
-
|
|
55
44
|
async closeSocket() {
|
|
56
45
|
this.socket.off('connect', this.onConnect);
|
|
57
46
|
this.socket.close();
|
|
58
47
|
return Promise.resolve();
|
|
59
48
|
}
|
|
60
|
-
|
|
61
49
|
onConnect() {
|
|
62
50
|
const {
|
|
63
51
|
host,
|
|
@@ -66,7 +54,6 @@ class Base extends core.BasePlugin {
|
|
|
66
54
|
} = this.options;
|
|
67
55
|
this.debug('Connected on %s/%s', host, namespace || '', path || '');
|
|
68
56
|
}
|
|
69
|
-
|
|
70
57
|
}
|
|
71
58
|
|
|
72
59
|
class ClientInput extends Base {
|
|
@@ -80,24 +67,20 @@ class ClientInput extends Base {
|
|
|
80
67
|
});
|
|
81
68
|
this.onMessage = this.onMessage.bind(this);
|
|
82
69
|
this.commands = commands;
|
|
83
|
-
this.debug =
|
|
70
|
+
this.debug = createDebug('cuecue:input:socketio');
|
|
84
71
|
}
|
|
85
|
-
|
|
86
72
|
setInputCommands(commands) {
|
|
87
73
|
this.commands = commands;
|
|
88
74
|
return this;
|
|
89
75
|
}
|
|
90
|
-
|
|
91
76
|
async onInit() {
|
|
92
77
|
await super.onInit();
|
|
93
78
|
this.socket.on('message', this.onMessage);
|
|
94
79
|
}
|
|
95
|
-
|
|
96
80
|
async onDestroy() {
|
|
97
81
|
this.socket.off('message', this.onMessage);
|
|
98
82
|
await super.onDestroy();
|
|
99
83
|
}
|
|
100
|
-
|
|
101
84
|
async onMessage(message) {
|
|
102
85
|
const {
|
|
103
86
|
transformMessage = null,
|
|
@@ -111,15 +94,13 @@ class ClientInput extends Base {
|
|
|
111
94
|
command: finalCommand = command,
|
|
112
95
|
args: finalArgs = args
|
|
113
96
|
} = (transformCommand !== null ? await transformCommand(command, args) : null) || {};
|
|
114
|
-
|
|
115
97
|
if (this.commands === null || this.commands.indexOf(finalCommand) !== -1) {
|
|
116
98
|
this.debug('command: %s args: %o', finalCommand, finalArgs);
|
|
117
|
-
this.emit('command', command, ...(
|
|
99
|
+
this.emit('command', command, ...(isArray(finalArgs) ? finalArgs : [finalArgs]));
|
|
118
100
|
} else {
|
|
119
101
|
this.debug('message: %o', message);
|
|
120
102
|
}
|
|
121
103
|
}
|
|
122
|
-
|
|
123
104
|
}
|
|
124
105
|
|
|
125
106
|
class ClientOutput extends Base {
|
|
@@ -129,33 +110,26 @@ class ClientOutput extends Base {
|
|
|
129
110
|
...opts
|
|
130
111
|
});
|
|
131
112
|
this.socket = null;
|
|
132
|
-
this.debug =
|
|
113
|
+
this.debug = createDebug('cuecue:output:socketio');
|
|
133
114
|
}
|
|
134
|
-
|
|
135
115
|
cue(cue, extraData = null) {
|
|
136
116
|
this.command('cue', cue, extraData);
|
|
137
117
|
}
|
|
138
|
-
|
|
139
118
|
cues(cues) {
|
|
140
119
|
this.command('cues', cues);
|
|
141
120
|
}
|
|
142
|
-
|
|
143
121
|
interact(data, interactionId = null) {
|
|
144
122
|
this.command('interact', data, interactionId);
|
|
145
123
|
}
|
|
146
|
-
|
|
147
124
|
interaction(interaction) {
|
|
148
125
|
this.command('interaction', interaction);
|
|
149
126
|
}
|
|
150
|
-
|
|
151
127
|
uninteraction(interactionId) {
|
|
152
128
|
this.command('uninteract', interactionId);
|
|
153
129
|
}
|
|
154
|
-
|
|
155
130
|
uninteractions(interactionIds) {
|
|
156
131
|
this.command('uninteractions', interactionIds);
|
|
157
132
|
}
|
|
158
|
-
|
|
159
133
|
async command(command, ...args) {
|
|
160
134
|
const {
|
|
161
135
|
transformCommand = null,
|
|
@@ -166,22 +140,18 @@ class ClientOutput extends Base {
|
|
|
166
140
|
command,
|
|
167
141
|
args
|
|
168
142
|
};
|
|
169
|
-
|
|
170
143
|
if (value === false) {
|
|
171
144
|
this.debug('command canceled: %s %o', command, args);
|
|
172
145
|
return Promise.resolve();
|
|
173
146
|
}
|
|
174
|
-
|
|
175
147
|
const {
|
|
176
148
|
command: finalCommand = command,
|
|
177
149
|
args: finalArgs = args
|
|
178
150
|
} = value || {};
|
|
179
|
-
|
|
180
151
|
if (acceptCommand !== null && !acceptCommand(finalCommand, finalArgs)) {
|
|
181
152
|
this.debug('command refused: %s %o', finalCommand, finalArgs);
|
|
182
153
|
return Promise.resolve();
|
|
183
154
|
}
|
|
184
|
-
|
|
185
155
|
this.debug('command: %s message: %o', finalCommand, finalArgs);
|
|
186
156
|
const message = {
|
|
187
157
|
command: finalCommand,
|
|
@@ -190,13 +160,11 @@ class ClientOutput extends Base {
|
|
|
190
160
|
const payload = transformMessage !== null ? await transformMessage(message) : message;
|
|
191
161
|
return this.send(payload);
|
|
192
162
|
}
|
|
193
|
-
|
|
194
163
|
async send(...args) {
|
|
195
164
|
this.debug('send: %o', args);
|
|
196
165
|
this.socket.send(...args);
|
|
197
166
|
return Promise.resolve();
|
|
198
167
|
}
|
|
199
|
-
|
|
200
168
|
}
|
|
201
169
|
|
|
202
170
|
class BaseServer extends core.BasePlugin {
|
|
@@ -216,19 +184,16 @@ class BaseServer extends core.BasePlugin {
|
|
|
216
184
|
this.namespace = null;
|
|
217
185
|
this.onConnection = this.onConnection.bind(this);
|
|
218
186
|
this.commands = commands;
|
|
219
|
-
this.debug =
|
|
187
|
+
this.debug = createDebug('cuecue:socketio-server');
|
|
220
188
|
}
|
|
221
|
-
|
|
222
189
|
async onInit() {
|
|
223
190
|
await super.onInit();
|
|
224
191
|
await this.createServer();
|
|
225
192
|
}
|
|
226
|
-
|
|
227
193
|
async onDestroy() {
|
|
228
194
|
await this.closeServer();
|
|
229
195
|
await super.onDestroy();
|
|
230
196
|
}
|
|
231
|
-
|
|
232
197
|
async createServer() {
|
|
233
198
|
const {
|
|
234
199
|
server,
|
|
@@ -248,7 +213,6 @@ class BaseServer extends core.BasePlugin {
|
|
|
248
213
|
this.namespace.on('connection', this.onConnection);
|
|
249
214
|
return Promise.resolve();
|
|
250
215
|
}
|
|
251
|
-
|
|
252
216
|
async closeServer() {
|
|
253
217
|
this.namespace.off('connection', this.onConnection);
|
|
254
218
|
return new Promise(resolve => {
|
|
@@ -257,11 +221,9 @@ class BaseServer extends core.BasePlugin {
|
|
|
257
221
|
});
|
|
258
222
|
});
|
|
259
223
|
}
|
|
260
|
-
|
|
261
224
|
onConnection(socket) {
|
|
262
225
|
this.debug('Client connected %s', socket.id);
|
|
263
226
|
}
|
|
264
|
-
|
|
265
227
|
}
|
|
266
228
|
|
|
267
229
|
class ServerInput extends BaseServer {
|
|
@@ -276,20 +238,17 @@ class ServerInput extends BaseServer {
|
|
|
276
238
|
this.onConnection = this.onConnection.bind(this);
|
|
277
239
|
this.onMessage = this.onMessage.bind(this);
|
|
278
240
|
this.commands = commands;
|
|
279
|
-
this.debug =
|
|
241
|
+
this.debug = createDebug('cuecue:input:socketio-server');
|
|
280
242
|
this.debug('started on: %O %s', opts, process.env.SOCKETIO_INPUT_NAMESPACE);
|
|
281
243
|
}
|
|
282
|
-
|
|
283
244
|
setInputCommands(commands) {
|
|
284
245
|
this.commands = commands;
|
|
285
246
|
return this;
|
|
286
247
|
}
|
|
287
|
-
|
|
288
248
|
async onConnection(socket) {
|
|
289
249
|
await super.onConnection(socket);
|
|
290
250
|
socket.on('message', this.onMessage);
|
|
291
251
|
}
|
|
292
|
-
|
|
293
252
|
async onMessage(message) {
|
|
294
253
|
const {
|
|
295
254
|
transformMessage = null,
|
|
@@ -303,15 +262,13 @@ class ServerInput extends BaseServer {
|
|
|
303
262
|
command: finalCommand = command,
|
|
304
263
|
args: finalArgs = args
|
|
305
264
|
} = (transformCommand !== null ? await transformCommand(command, args) : null) || {};
|
|
306
|
-
|
|
307
265
|
if (this.commands === null || this.commands.indexOf(finalCommand) !== -1) {
|
|
308
266
|
this.debug('command: %s args: %o', finalCommand, finalArgs);
|
|
309
|
-
this.emit('command', command, ...(
|
|
267
|
+
this.emit('command', command, ...(isArray(finalArgs) ? finalArgs : [finalArgs]));
|
|
310
268
|
} else {
|
|
311
269
|
this.debug('message: %o', message);
|
|
312
270
|
}
|
|
313
271
|
}
|
|
314
|
-
|
|
315
272
|
}
|
|
316
273
|
|
|
317
274
|
class ServerOutput extends BaseServer {
|
|
@@ -321,34 +278,27 @@ class ServerOutput extends BaseServer {
|
|
|
321
278
|
...opts
|
|
322
279
|
});
|
|
323
280
|
this.socket = null;
|
|
324
|
-
this.debug =
|
|
281
|
+
this.debug = createDebug('cuecue:output:socketio-server');
|
|
325
282
|
this.debug('started on: %O %s', opts, process.env.SOCKETIO_OUTPUT_NAMESPACE);
|
|
326
283
|
}
|
|
327
|
-
|
|
328
284
|
cue(cue, extraData = null) {
|
|
329
285
|
this.command('cue', cue, extraData);
|
|
330
286
|
}
|
|
331
|
-
|
|
332
287
|
cues(cues) {
|
|
333
288
|
this.command('cues', cues);
|
|
334
289
|
}
|
|
335
|
-
|
|
336
290
|
interact(data, interactionId = null) {
|
|
337
291
|
this.command('interact', data, interactionId);
|
|
338
292
|
}
|
|
339
|
-
|
|
340
293
|
interaction(interaction) {
|
|
341
294
|
this.command('interaction', interaction);
|
|
342
295
|
}
|
|
343
|
-
|
|
344
296
|
uninteraction(interactionId) {
|
|
345
297
|
this.command('uninteract', interactionId);
|
|
346
298
|
}
|
|
347
|
-
|
|
348
299
|
uninteractions(interactionIds) {
|
|
349
300
|
this.command('uninteractions', interactionIds);
|
|
350
301
|
}
|
|
351
|
-
|
|
352
302
|
async command(command, ...args) {
|
|
353
303
|
const {
|
|
354
304
|
transformCommand = null,
|
|
@@ -359,23 +309,19 @@ class ServerOutput extends BaseServer {
|
|
|
359
309
|
command,
|
|
360
310
|
args
|
|
361
311
|
};
|
|
362
|
-
|
|
363
312
|
if (value === false) {
|
|
364
313
|
this.debug('command canceled: %s %o', command, args);
|
|
365
314
|
return Promise.resolve();
|
|
366
315
|
}
|
|
367
|
-
|
|
368
316
|
const {
|
|
369
317
|
command: finalCommand = command,
|
|
370
318
|
args: finalArgs = args,
|
|
371
319
|
namespace = null
|
|
372
320
|
} = value || {};
|
|
373
|
-
|
|
374
321
|
if (acceptCommand !== null && !acceptCommand(finalCommand, finalArgs)) {
|
|
375
322
|
this.debug('command refused: %s %o', finalCommand, finalArgs);
|
|
376
323
|
return Promise.resolve();
|
|
377
324
|
}
|
|
378
|
-
|
|
379
325
|
this.debug('command: %s message: %o', finalCommand, finalArgs);
|
|
380
326
|
const message = {
|
|
381
327
|
command: finalCommand,
|
|
@@ -384,19 +330,16 @@ class ServerOutput extends BaseServer {
|
|
|
384
330
|
const payload = transformMessage !== null ? await transformMessage(message) : message;
|
|
385
331
|
return namespace !== null ? this.sendToNamespace(payload) : this.send(payload);
|
|
386
332
|
}
|
|
387
|
-
|
|
388
333
|
async send(...args) {
|
|
389
334
|
this.debug('send: %o', args);
|
|
390
335
|
this.namespace.send(...args);
|
|
391
336
|
return Promise.resolve();
|
|
392
337
|
}
|
|
393
|
-
|
|
394
338
|
async sendToNamespace(namespace, ...args) {
|
|
395
339
|
this.debug('send: %o', args);
|
|
396
340
|
this.io.of(namespace).send(...args);
|
|
397
341
|
return Promise.resolve();
|
|
398
342
|
}
|
|
399
|
-
|
|
400
343
|
}
|
|
401
344
|
|
|
402
345
|
exports.Input = ClientInput;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cuecue/socketio",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.44",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript"
|
|
@@ -29,26 +29,26 @@
|
|
|
29
29
|
}
|
|
30
30
|
],
|
|
31
31
|
"license": "ISC",
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=22"
|
|
34
|
+
},
|
|
32
35
|
"main": "dist/index.js",
|
|
33
36
|
"files": [
|
|
34
37
|
"dist"
|
|
35
38
|
],
|
|
36
39
|
"scripts": {
|
|
37
40
|
"clean": "rm -rf dist",
|
|
38
|
-
"build": "rollup --config ../../rollup.config.
|
|
39
|
-
"
|
|
41
|
+
"build": "rollup --config ../../rollup.config.mjs",
|
|
42
|
+
"prepack": "npm run clean && npm run build"
|
|
40
43
|
},
|
|
41
44
|
"dependencies": {
|
|
42
|
-
"@
|
|
43
|
-
"@cuecue/core": "^0.0.43",
|
|
45
|
+
"@cuecue/core": "^0.0.44",
|
|
44
46
|
"debug": "^4.3.1",
|
|
45
47
|
"lodash": "^4.17.21",
|
|
46
48
|
"socket.io": "^4.1.2",
|
|
47
|
-
"socket.io-client": "^4.1.2"
|
|
48
|
-
"uuid": "^8.3.2"
|
|
49
|
+
"socket.io-client": "^4.1.2"
|
|
49
50
|
},
|
|
50
51
|
"publishConfig": {
|
|
51
52
|
"access": "public"
|
|
52
|
-
}
|
|
53
|
-
"gitHead": "59235dd281e2779bf0f964cb069f539ba85a8066"
|
|
53
|
+
}
|
|
54
54
|
}
|