node-osc 11.1.1 → 11.2.1

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 (72) hide show
  1. package/.gitattributes +11 -0
  2. package/.github/workflows/bump-version.yml +5 -3
  3. package/.github/workflows/create-release.yml +4 -4
  4. package/.github/workflows/nodejs.yml +6 -3
  5. package/LICENSE +201 -165
  6. package/README.md +135 -42
  7. package/dist/lib/Bundle.js +66 -0
  8. package/dist/lib/Client.js +137 -22
  9. package/dist/lib/Message.js +90 -2
  10. package/dist/lib/Server.js +117 -6
  11. package/dist/lib/index.js +3 -0
  12. package/dist/lib/internal/decode.js +4 -4
  13. package/dist/lib/{internal/osc.js → osc.js} +73 -7
  14. package/dist/test/lib/osc.js +396 -0
  15. package/dist/test/test-client.js +174 -0
  16. package/dist/test/test-e2e.js +9 -3
  17. package/dist/test/test-encode-decode.js +1208 -0
  18. package/dist/test/test-error-handling.js +116 -0
  19. package/dist/test/test-message.js +147 -0
  20. package/dist/test/test-osc-internal.js +399 -41
  21. package/dist/test/test-promises.js +272 -0
  22. package/dist/test/test-types.js +42 -0
  23. package/dist/test/util.js +15 -8
  24. package/docs/API.md +477 -0
  25. package/docs/GUIDE.md +605 -0
  26. package/examples/README.md +119 -0
  27. package/examples/async-await.mjs +57 -0
  28. package/examples/bundle-example.mjs +92 -0
  29. package/examples/client.js +22 -5
  30. package/examples/error-handling.mjs +152 -0
  31. package/examples/esm.mjs +21 -0
  32. package/examples/server.js +16 -0
  33. package/jsdoc.json +16 -0
  34. package/lib/Bundle.mjs +66 -0
  35. package/lib/Client.mjs +137 -22
  36. package/lib/Message.mjs +90 -2
  37. package/lib/Server.mjs +117 -6
  38. package/lib/index.mjs +1 -0
  39. package/lib/internal/decode.mjs +4 -4
  40. package/lib/{internal/osc.mjs → osc.mjs} +74 -6
  41. package/package.json +12 -10
  42. package/rollup.config.mjs +49 -41
  43. package/scripts/generate-docs.mjs +229 -0
  44. package/test/fixtures/types/test-cjs-types.ts +19 -0
  45. package/test/fixtures/types/test-esm-types.ts +35 -0
  46. package/test/fixtures/types/tsconfig-cjs.test.json +17 -0
  47. package/test/fixtures/types/tsconfig-esm.test.json +17 -0
  48. package/test/test-bundle.mjs +0 -1
  49. package/test/test-client.mjs +174 -0
  50. package/test/test-e2e.mjs +9 -3
  51. package/test/test-encode-decode.mjs +1206 -0
  52. package/test/test-error-handling.mjs +115 -0
  53. package/test/test-message.mjs +147 -0
  54. package/test/test-osc-internal.mjs +400 -42
  55. package/test/test-promises.mjs +271 -0
  56. package/test/test-types.mjs +39 -0
  57. package/test/util.mjs +15 -8
  58. package/tsconfig.json +45 -0
  59. package/types/Bundle.d.mts +70 -0
  60. package/types/Bundle.d.mts.map +1 -0
  61. package/types/Client.d.mts +101 -0
  62. package/types/Client.d.mts.map +1 -0
  63. package/types/Message.d.mts +84 -0
  64. package/types/Message.d.mts.map +1 -0
  65. package/types/Server.d.mts +98 -0
  66. package/types/Server.d.mts.map +1 -0
  67. package/types/index.d.mts +6 -0
  68. package/types/index.d.mts.map +1 -0
  69. package/types/internal/decode.d.mts +4 -0
  70. package/types/internal/decode.d.mts.map +1 -0
  71. package/types/osc.d.mts +66 -0
  72. package/types/osc.d.mts.map +1 -0
@@ -0,0 +1,116 @@
1
+ 'use strict';
2
+
3
+ var tap = require('tap');
4
+ var util = require('./util.js');
5
+ var nodeOsc = require('node-osc');
6
+
7
+ tap.beforeEach(util.bootstrap);
8
+
9
+ tap.test('server: socket error event is emitted', (t) => {
10
+ t.plan(1);
11
+ const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
12
+
13
+ oscServer.on('error', (err) => {
14
+ t.ok(err, 'error event should be emitted');
15
+ oscServer.close();
16
+ });
17
+
18
+ // Simulate a socket error
19
+ oscServer._sock.emit('error', new Error('test socket error'));
20
+ });
21
+
22
+ tap.test('server: error listener can be added before listening', (t) => {
23
+ t.plan(2);
24
+ const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
25
+
26
+ oscServer.on('error', (err) => {
27
+ t.ok(err, 'error event should be emitted');
28
+ t.equal(err.message, 'socket test error', 'error message should match');
29
+ });
30
+
31
+ t.teardown(() => {
32
+ oscServer.close();
33
+ });
34
+
35
+ // Simulate a socket error
36
+ oscServer._sock.emit('error', new Error('socket test error'));
37
+ });
38
+
39
+ tap.test('client: socket error event is emitted', (t) => {
40
+ t.plan(1);
41
+ const client = new nodeOsc.Client('127.0.0.1', t.context.port);
42
+
43
+ client.on('error', (err) => {
44
+ t.ok(err, 'error event should be emitted');
45
+ client.close();
46
+ });
47
+
48
+ // Simulate a socket error
49
+ client._sock.emit('error', new Error('test client error'));
50
+ });
51
+
52
+ tap.test('client: error listener can be added at construction', (t) => {
53
+ t.plan(2);
54
+ const client = new nodeOsc.Client('127.0.0.1', t.context.port);
55
+
56
+ client.on('error', (err) => {
57
+ t.ok(err, 'error event should be emitted');
58
+ t.equal(err.message, 'client socket error', 'error message should match');
59
+ });
60
+
61
+ t.teardown(() => {
62
+ client.close();
63
+ });
64
+
65
+ // Simulate a socket error
66
+ client._sock.emit('error', new Error('client socket error'));
67
+ });
68
+
69
+ tap.test('client: is an EventEmitter instance', (t) => {
70
+ t.plan(1);
71
+ const client = new nodeOsc.Client('127.0.0.1', t.context.port);
72
+
73
+ t.ok(typeof client.on === 'function', 'client should have EventEmitter methods');
74
+
75
+ client.close();
76
+ });
77
+
78
+ tap.test('server: multiple error listeners can be attached', (t) => {
79
+ t.plan(2);
80
+ const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
81
+
82
+ oscServer.on('error', (err) => {
83
+ t.ok(err, 'first listener should receive error');
84
+ });
85
+
86
+ oscServer.on('error', (err) => {
87
+ t.ok(err, 'second listener should receive error');
88
+ });
89
+
90
+ t.teardown(() => {
91
+ oscServer.close();
92
+ });
93
+
94
+ // Simulate a socket error
95
+ oscServer._sock.emit('error', new Error('multi listener test'));
96
+ });
97
+
98
+ tap.test('client: multiple error listeners can be attached', (t) => {
99
+ t.plan(2);
100
+ const client = new nodeOsc.Client('127.0.0.1', t.context.port);
101
+
102
+ client.on('error', (err) => {
103
+ t.ok(err, 'first listener should receive error');
104
+ });
105
+
106
+ client.on('error', (err) => {
107
+ t.ok(err, 'second listener should receive error');
108
+ });
109
+
110
+ t.teardown(() => {
111
+ client.close();
112
+ });
113
+
114
+ // Simulate a socket error
115
+ client._sock.emit('error', new Error('multi listener test'));
116
+ });
@@ -173,6 +173,29 @@ tap.test('message: blob', (t) => {
173
173
  });
174
174
  });
175
175
 
176
+ tap.test('message: Buffer as blob', (t) => {
177
+ const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
178
+ const client = new nodeOsc.Client('127.0.0.1', t.context.port);
179
+ const m = new nodeOsc.Message('/address');
180
+ const buf = Buffer.from('test buffer data');
181
+ // Directly append Buffer without wrapping in object
182
+ m.append(buf);
183
+
184
+ oscServer.on('message', (msg) => {
185
+ const expected = [
186
+ '/address',
187
+ buf
188
+ ];
189
+ t.same(msg, expected, `We received the buffer payload: ${msg}`);
190
+ oscServer.close();
191
+ t.end();
192
+ });
193
+
194
+ client.send(m, () => {
195
+ client.close();
196
+ });
197
+ });
198
+
176
199
  // test('message: timetag', (t) => {
177
200
  // const oscServer = new osc.Server(3333, '127.0.0.1');
178
201
  // const client = new osc.Client('127.0.0.1', 3333);
@@ -192,6 +215,130 @@ tap.test('message: blob', (t) => {
192
215
  // });
193
216
  // });
194
217
 
218
+ tap.test('message: Buffer with multiple arguments', (t) => {
219
+ const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
220
+ const client = new nodeOsc.Client('127.0.0.1', t.context.port);
221
+ const m = new nodeOsc.Message('/address');
222
+ const buf1 = Buffer.from('first');
223
+ const buf2 = Buffer.from('second');
224
+
225
+ m.append('string');
226
+ m.append(42);
227
+ m.append(buf1);
228
+ m.append(3.14);
229
+ m.append(buf2);
230
+
231
+ oscServer.on('message', (msg) => {
232
+ t.equal(msg[0], '/address', 'Address matches');
233
+ t.equal(msg[1], 'string', 'String matches');
234
+ t.equal(msg[2], 42, 'Integer matches');
235
+ t.same(msg[3], buf1, 'First buffer matches');
236
+ t.equal(round(msg[4]), 3.14, 'Float matches');
237
+ t.same(msg[5], buf2, 'Second buffer matches');
238
+ oscServer.close();
239
+ t.end();
240
+ });
241
+
242
+ client.send(m, () => {
243
+ client.close();
244
+ });
245
+ });
246
+
247
+ tap.test('message: Buffer in constructor', (t) => {
248
+ const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
249
+ const client = new nodeOsc.Client('127.0.0.1', t.context.port);
250
+ const buf = Buffer.from('constructor buffer');
251
+ const m = new nodeOsc.Message('/address', 'test', buf, 123);
252
+
253
+ oscServer.on('message', (msg) => {
254
+ const expected = [
255
+ '/address',
256
+ 'test',
257
+ buf,
258
+ 123
259
+ ];
260
+ t.same(msg, expected, `We received the constructor buffer payload: ${msg}`);
261
+ oscServer.close();
262
+ t.end();
263
+ });
264
+
265
+ client.send(m, () => {
266
+ client.close();
267
+ });
268
+ });
269
+
270
+ tap.test('message: Buffer in array', (t) => {
271
+ const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
272
+ const client = new nodeOsc.Client('127.0.0.1', t.context.port);
273
+ const m = new nodeOsc.Message('/address');
274
+ const buf1 = Buffer.from('array1');
275
+ const buf2 = Buffer.from('array2');
276
+
277
+ m.append([buf1, 'string', buf2, 456]);
278
+
279
+ oscServer.on('message', (msg) => {
280
+ const expected = [
281
+ '/address',
282
+ buf1,
283
+ 'string',
284
+ buf2,
285
+ 456
286
+ ];
287
+ t.same(msg, expected, `We received the array with buffers: ${msg}`);
288
+ oscServer.close();
289
+ t.end();
290
+ });
291
+
292
+ client.send(m, () => {
293
+ client.close();
294
+ });
295
+ });
296
+
297
+ tap.test('message: empty Buffer', (t) => {
298
+ const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
299
+ const client = new nodeOsc.Client('127.0.0.1', t.context.port);
300
+ const m = new nodeOsc.Message('/address');
301
+ const buf = Buffer.from('');
302
+
303
+ m.append(buf);
304
+
305
+ oscServer.on('message', (msg) => {
306
+ const expected = [
307
+ '/address',
308
+ buf
309
+ ];
310
+ t.same(msg, expected, `We received the empty buffer: ${msg}`);
311
+ oscServer.close();
312
+ t.end();
313
+ });
314
+
315
+ client.send(m, () => {
316
+ client.close();
317
+ });
318
+ });
319
+
320
+ tap.test('message: large Buffer', (t) => {
321
+ const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
322
+ const client = new nodeOsc.Client('127.0.0.1', t.context.port);
323
+ const m = new nodeOsc.Message('/address');
324
+ const buf = Buffer.alloc(1024, 'x');
325
+
326
+ m.append(buf);
327
+
328
+ oscServer.on('message', (msg) => {
329
+ t.equal(msg[0], '/address', 'Address matches');
330
+ t.ok(Buffer.isBuffer(msg[1]), 'Second element is a Buffer');
331
+ t.equal(msg[1].length, 1024, 'Buffer size matches');
332
+ t.same(msg[1], buf, 'Buffer content matches');
333
+ oscServer.close();
334
+ t.end();
335
+ });
336
+
337
+ client.send(m, () => {
338
+ client.close();
339
+ });
340
+ });
341
+
195
342
  tap.test('message: error', (t) => {
196
343
  const m = new nodeOsc.Message('/address');
197
344
  t.plan(2);