node-osc 11.2.0 → 11.2.2

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 (48) hide show
  1. package/.github/workflows/bump-version.yml +3 -3
  2. package/.github/workflows/create-release.yml +4 -4
  3. package/.github/workflows/nodejs.yml +4 -4
  4. package/README.md +3 -2
  5. package/agent.md +330 -0
  6. package/dist/lib/Client.js +1 -1
  7. package/dist/lib/Message.js +3 -1
  8. package/dist/lib/Server.js +7 -12
  9. package/dist/lib/internal/decode.js +3 -1
  10. package/dist/lib/osc.js +32 -3
  11. package/dist/test/lib/osc.js +32 -3
  12. package/dist/test/test-bundle.js +13 -12
  13. package/dist/test/test-client.js +68 -37
  14. package/dist/test/test-decode.js +35 -0
  15. package/dist/test/test-e2e.js +9 -9
  16. package/dist/test/test-encode-decode.js +455 -0
  17. package/dist/test/test-error-handling.js +14 -13
  18. package/dist/test/test-message.js +261 -64
  19. package/dist/test/test-osc-internal.js +151 -0
  20. package/dist/test/test-promises.js +90 -26
  21. package/dist/test/test-server.js +19 -16
  22. package/docs/README.md +81 -0
  23. package/examples/README.md +3 -1
  24. package/lib/Client.mjs +1 -1
  25. package/lib/Message.mjs +3 -1
  26. package/lib/Server.mjs +7 -12
  27. package/lib/internal/decode.mjs +3 -1
  28. package/lib/osc.mjs +32 -3
  29. package/package.json +2 -2
  30. package/rollup.config.mjs +1 -0
  31. package/test/test-bundle.mjs +14 -13
  32. package/test/test-client.mjs +69 -38
  33. package/test/test-decode.mjs +35 -0
  34. package/test/test-e2e.mjs +10 -10
  35. package/test/test-encode-decode.mjs +455 -0
  36. package/test/test-error-handling.mjs +15 -14
  37. package/test/test-message.mjs +262 -66
  38. package/test/test-osc-internal.mjs +151 -0
  39. package/test/test-promises.mjs +91 -27
  40. package/test/test-server.mjs +20 -17
  41. package/types/Message.d.mts.map +1 -1
  42. package/types/Server.d.mts.map +1 -1
  43. package/types/internal/decode.d.mts.map +1 -1
  44. package/types/osc.d.mts.map +1 -1
  45. package/dist/test/test-getPort.js +0 -20
  46. package/dist/test/util.js +0 -34
  47. package/test/test-getPort.mjs +0 -18
  48. package/test/util.mjs +0 -34
@@ -1,14 +1,13 @@
1
1
  'use strict';
2
2
 
3
+ var node_events = require('node:events');
3
4
  var tap = require('tap');
4
5
  var nodeOsc = require('node-osc');
5
- var util = require('./util.js');
6
6
 
7
- tap.beforeEach(util.bootstrap);
8
-
9
- tap.test('bundle: verbose bundle', (t) => {
10
- const server = new nodeOsc.Server(t.context.port, '127.0.0.1');
11
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
7
+ tap.test('bundle: verbose bundle', async (t) => {
8
+ const server = new nodeOsc.Server(0, '127.0.0.1');
9
+ await node_events.once(server, 'listening');
10
+ const client = new nodeOsc.Client('127.0.0.1', server.port);
12
11
 
13
12
  t.plan(2);
14
13
 
@@ -35,9 +34,10 @@ tap.test('bundle: verbose bundle', (t) => {
35
34
  }));
36
35
  });
37
36
 
38
- tap.test('bundle: array syntax', (t) => {
39
- const server = new nodeOsc.Server(t.context.port, '127.0.0.1');
40
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
37
+ tap.test('bundle: array syntax', async (t) => {
38
+ const server = new nodeOsc.Server(0, '127.0.0.1');
39
+ await node_events.once(server, 'listening');
40
+ const client = new nodeOsc.Client('127.0.0.1', server.port);
41
41
 
42
42
  t.plan(2);
43
43
 
@@ -57,9 +57,10 @@ tap.test('bundle: array syntax', (t) => {
57
57
  ));
58
58
  });
59
59
 
60
- tap.test('bundle: nested bundle', (t) => {
61
- const server = new nodeOsc.Server(t.context.port, '127.0.0.1');
62
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
60
+ tap.test('bundle: nested bundle', async (t) => {
61
+ const server = new nodeOsc.Server(0, '127.0.0.1');
62
+ await node_events.once(server, 'listening');
63
+ const client = new nodeOsc.Client('127.0.0.1', server.port);
63
64
 
64
65
  t.plan(4);
65
66
 
@@ -1,14 +1,13 @@
1
1
  'use strict';
2
2
 
3
+ var node_events = require('node:events');
3
4
  var tap = require('tap');
4
- var util = require('./util.js');
5
5
  var nodeOsc = require('node-osc');
6
6
 
7
- tap.beforeEach(util.bootstrap);
8
-
9
- tap.test('client: with array', (t) => {
10
- const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
11
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
7
+ tap.test('client: with array', async (t) => {
8
+ const oscServer = new nodeOsc.Server(0, '127.0.0.1');
9
+ await node_events.once(oscServer, 'listening');
10
+ const client = new nodeOsc.Client('127.0.0.1', oscServer.port);
12
11
 
13
12
  t.plan(2);
14
13
 
@@ -23,9 +22,33 @@ tap.test('client: with array', (t) => {
23
22
  });
24
23
  });
25
24
 
26
- tap.test('client: with string', (t) => {
27
- const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
28
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
25
+ tap.test('client: array is not mutated when sent', async (t) => {
26
+ const oscServer = new nodeOsc.Server(0, '127.0.0.1');
27
+ await node_events.once(oscServer, 'listening');
28
+ const client = new nodeOsc.Client('127.0.0.1', oscServer.port);
29
+
30
+ t.plan(3);
31
+
32
+ const originalArray = ['/test', 0, 1, 'testing', true];
33
+ const expectedArray = ['/test', 0, 1, 'testing', true];
34
+
35
+ oscServer.on('message', (msg) => {
36
+ oscServer.close();
37
+ t.same(msg, ['/test', 0, 1, 'testing', true], 'We should receive expected payload');
38
+ // Verify the original array was not mutated
39
+ t.same(originalArray, expectedArray, 'Original array should not be mutated');
40
+ });
41
+
42
+ client.send(originalArray, (err) => {
43
+ t.error(err, 'there should be no error');
44
+ client.close();
45
+ });
46
+ });
47
+
48
+ tap.test('client: with string', async (t) => {
49
+ const oscServer = new nodeOsc.Server(0, '127.0.0.1');
50
+ await node_events.once(oscServer, 'listening');
51
+ const client = new nodeOsc.Client('127.0.0.1', oscServer.port);
29
52
 
30
53
  t.plan(2);
31
54
 
@@ -40,9 +63,10 @@ tap.test('client: with string', (t) => {
40
63
  });
41
64
  });
42
65
 
43
- tap.test('client: with Message object', (t) => {
44
- const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
45
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
66
+ tap.test('client: with Message object', async (t) => {
67
+ const oscServer = new nodeOsc.Server(0, '127.0.0.1');
68
+ await node_events.once(oscServer, 'listening');
69
+ const client = new nodeOsc.Client('127.0.0.1', oscServer.port);
46
70
 
47
71
  t.plan(2);
48
72
 
@@ -66,9 +90,10 @@ tap.test('client: with Message object', (t) => {
66
90
  });
67
91
  });
68
92
 
69
- tap.test('client: with Bundle object', (t) => {
70
- const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
71
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
93
+ tap.test('client: with Bundle object', async (t) => {
94
+ const oscServer = new nodeOsc.Server(0, '127.0.0.1');
95
+ await node_events.once(oscServer, 'listening');
96
+ const client = new nodeOsc.Client('127.0.0.1', oscServer.port);
72
97
 
73
98
  t.plan(2);
74
99
 
@@ -92,8 +117,8 @@ tap.test('client: with Bundle object', (t) => {
92
117
  });
93
118
  });
94
119
 
95
- tap.test('client: failure', (t) => {
96
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
120
+ tap.test('client: failure', async (t) => {
121
+ const client = new nodeOsc.Client('127.0.0.1', 9999);
97
122
 
98
123
  t.plan(2);
99
124
 
@@ -108,8 +133,8 @@ tap.test('client: failure', (t) => {
108
133
  });
109
134
  });
110
135
 
111
- tap.test('client: close with callback', (t) => {
112
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
136
+ tap.test('client: close with callback', async (t) => {
137
+ const client = new nodeOsc.Client('127.0.0.1', 9999);
113
138
 
114
139
  t.plan(1);
115
140
 
@@ -118,9 +143,10 @@ tap.test('client: close with callback', (t) => {
118
143
  });
119
144
  });
120
145
 
121
- tap.test('client: send bundle with non-numeric timetag', (t) => {
122
- const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
123
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
146
+ tap.test('client: send bundle with non-numeric timetag', async (t) => {
147
+ const oscServer = new nodeOsc.Server(0, '127.0.0.1');
148
+ await node_events.once(oscServer, 'listening');
149
+ const client = new nodeOsc.Client('127.0.0.1', oscServer.port);
124
150
 
125
151
  t.plan(2);
126
152
 
@@ -147,9 +173,10 @@ tap.test('client: send bundle with non-numeric timetag', (t) => {
147
173
  client.send(bundle);
148
174
  });
149
175
 
150
- tap.test('client: send bundle with null timetag', (t) => {
151
- const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
152
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
176
+ tap.test('client: send bundle with null timetag', async (t) => {
177
+ const oscServer = new nodeOsc.Server(0, '127.0.0.1');
178
+ await node_events.once(oscServer, 'listening');
179
+ const client = new nodeOsc.Client('127.0.0.1', oscServer.port);
153
180
 
154
181
  t.plan(2);
155
182
 
@@ -176,9 +203,10 @@ tap.test('client: send bundle with null timetag', (t) => {
176
203
  client.send(bundle);
177
204
  });
178
205
 
179
- tap.test('client: send message with float type arg', (t) => {
180
- const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
181
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
206
+ tap.test('client: send message with float type arg', async (t) => {
207
+ const oscServer = new nodeOsc.Server(0, '127.0.0.1');
208
+ await node_events.once(oscServer, 'listening');
209
+ const client = new nodeOsc.Client('127.0.0.1', oscServer.port);
182
210
 
183
211
  t.plan(2);
184
212
 
@@ -197,9 +225,10 @@ tap.test('client: send message with float type arg', (t) => {
197
225
  });
198
226
  });
199
227
 
200
- tap.test('client: send message with blob type arg', (t) => {
201
- const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
202
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
228
+ tap.test('client: send message with blob type arg', async (t) => {
229
+ const oscServer = new nodeOsc.Server(0, '127.0.0.1');
230
+ await node_events.once(oscServer, 'listening');
231
+ const client = new nodeOsc.Client('127.0.0.1', oscServer.port);
203
232
 
204
233
  t.plan(2);
205
234
 
@@ -218,9 +247,10 @@ tap.test('client: send message with blob type arg', (t) => {
218
247
  });
219
248
  });
220
249
 
221
- tap.test('client: send message with double type arg', (t) => {
222
- const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
223
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
250
+ tap.test('client: send message with double type arg', async (t) => {
251
+ const oscServer = new nodeOsc.Server(0, '127.0.0.1');
252
+ await node_events.once(oscServer, 'listening');
253
+ const client = new nodeOsc.Client('127.0.0.1', oscServer.port);
224
254
 
225
255
  t.plan(2);
226
256
 
@@ -239,9 +269,10 @@ tap.test('client: send message with double type arg', (t) => {
239
269
  });
240
270
  });
241
271
 
242
- tap.test('client: send message with midi type arg', (t) => {
243
- const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
244
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
272
+ tap.test('client: send message with midi type arg', async (t) => {
273
+ const oscServer = new nodeOsc.Server(0, '127.0.0.1');
274
+ await node_events.once(oscServer, 'listening');
275
+ const client = new nodeOsc.Client('127.0.0.1', oscServer.port);
245
276
 
246
277
  t.plan(2);
247
278
 
@@ -107,3 +107,38 @@ tap.test('decode: malformed structure with unexpected oscType', async (t) => {
107
107
 
108
108
  t.end();
109
109
  });
110
+
111
+ tap.test('decode: message without args defaults to empty array', (t) => {
112
+ const mockFromBuffer = () => ({
113
+ oscType: 'message',
114
+ address: '/test'
115
+ });
116
+
117
+ t.same(
118
+ decode(Buffer.from('test'), mockFromBuffer),
119
+ ['/test'],
120
+ 'should default args to empty array'
121
+ );
122
+ t.end();
123
+ });
124
+
125
+ tap.test('decode: bundle element must be message or bundle', (t) => {
126
+ const mockFromBuffer = () => ({
127
+ oscType: 'bundle',
128
+ elements: [
129
+ {
130
+ oscType: 'message',
131
+ address: '/ok',
132
+ args: []
133
+ },
134
+ {
135
+ oscType: 'nope'
136
+ }
137
+ ]
138
+ });
139
+
140
+ t.throws(() => {
141
+ decode(Buffer.from('test'), mockFromBuffer);
142
+ }, /Malformed Packet/, 'should throw for invalid bundle element');
143
+ t.end();
144
+ });
@@ -1,11 +1,9 @@
1
1
  'use strict';
2
2
 
3
+ var node_events = require('node:events');
3
4
  var tap = require('tap');
4
- var util = require('./util.js');
5
5
  var nodeOsc = require('node-osc');
6
6
 
7
- tap.beforeEach(util.bootstrap);
8
-
9
7
  function flaky() {
10
8
  return process.release.lts === 'Dubnium' && process.platform === 'win32';
11
9
  }
@@ -15,11 +13,12 @@ function skip(t) {
15
13
  t.end();
16
14
  }
17
15
 
18
- tap.test('osc: argument message no callback', (t) => {
16
+ tap.test('osc: argument message no callback', async (t) => {
19
17
  if (flaky()) return skip(t);
20
18
 
21
- const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
22
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
19
+ const oscServer = new nodeOsc.Server(0, '127.0.0.1');
20
+ await node_events.once(oscServer, 'listening');
21
+ const client = new nodeOsc.Client('127.0.0.1', oscServer.port);
23
22
 
24
23
  t.plan(1);
25
24
 
@@ -35,11 +34,12 @@ tap.test('osc: argument message no callback', (t) => {
35
34
  client.send('/test', 1, 2, 'testing');
36
35
  });
37
36
 
38
- tap.test('osc: client with callback and message as arguments', (t) => {
37
+ tap.test('osc: client with callback and message as arguments', async (t) => {
39
38
  if (flaky()) return skip(t);
40
39
 
41
- const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
42
- const client = new nodeOsc.Client('127.0.0.1', t.context.port);
40
+ const oscServer = new nodeOsc.Server(0, '127.0.0.1');
41
+ await node_events.once(oscServer, 'listening');
42
+ const client = new nodeOsc.Client('127.0.0.1', oscServer.port);
43
43
 
44
44
  t.plan(2);
45
45