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