node-osc 11.1.1 → 11.2.0

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 (69) hide show
  1. package/.gitattributes +11 -0
  2. package/.github/workflows/bump-version.yml +2 -0
  3. package/.github/workflows/nodejs.yml +3 -0
  4. package/LICENSE +201 -165
  5. package/README.md +135 -42
  6. package/dist/lib/Bundle.js +66 -0
  7. package/dist/lib/Client.js +137 -22
  8. package/dist/lib/Message.js +87 -1
  9. package/dist/lib/Server.js +117 -6
  10. package/dist/lib/index.js +3 -0
  11. package/dist/lib/internal/decode.js +4 -4
  12. package/dist/lib/{internal/osc.js → osc.js} +70 -5
  13. package/dist/test/lib/osc.js +395 -0
  14. package/dist/test/test-client.js +152 -0
  15. package/dist/test/test-e2e.js +9 -3
  16. package/dist/test/test-encode-decode.js +849 -0
  17. package/dist/test/test-error-handling.js +116 -0
  18. package/dist/test/test-osc-internal.js +399 -41
  19. package/dist/test/test-promises.js +250 -0
  20. package/dist/test/test-types.js +42 -0
  21. package/dist/test/util.js +15 -8
  22. package/docs/API.md +477 -0
  23. package/docs/GUIDE.md +605 -0
  24. package/examples/README.md +119 -0
  25. package/examples/async-await.mjs +57 -0
  26. package/examples/bundle-example.mjs +92 -0
  27. package/examples/client.js +22 -5
  28. package/examples/error-handling.mjs +152 -0
  29. package/examples/esm.mjs +21 -0
  30. package/examples/server.js +16 -0
  31. package/jsdoc.json +16 -0
  32. package/lib/Bundle.mjs +66 -0
  33. package/lib/Client.mjs +137 -22
  34. package/lib/Message.mjs +87 -1
  35. package/lib/Server.mjs +117 -6
  36. package/lib/index.mjs +1 -0
  37. package/lib/internal/decode.mjs +4 -4
  38. package/lib/{internal/osc.mjs → osc.mjs} +71 -4
  39. package/package.json +12 -10
  40. package/rollup.config.mjs +48 -41
  41. package/scripts/generate-docs.mjs +229 -0
  42. package/test/fixtures/types/test-cjs-types.ts +19 -0
  43. package/test/fixtures/types/test-esm-types.ts +35 -0
  44. package/test/fixtures/types/tsconfig-cjs.test.json +17 -0
  45. package/test/fixtures/types/tsconfig-esm.test.json +17 -0
  46. package/test/test-bundle.mjs +0 -1
  47. package/test/test-client.mjs +152 -0
  48. package/test/test-e2e.mjs +9 -3
  49. package/test/test-encode-decode.mjs +847 -0
  50. package/test/test-error-handling.mjs +115 -0
  51. package/test/test-osc-internal.mjs +400 -42
  52. package/test/test-promises.mjs +249 -0
  53. package/test/test-types.mjs +39 -0
  54. package/test/util.mjs +15 -8
  55. package/tsconfig.json +45 -0
  56. package/types/Bundle.d.mts +70 -0
  57. package/types/Bundle.d.mts.map +1 -0
  58. package/types/Client.d.mts +101 -0
  59. package/types/Client.d.mts.map +1 -0
  60. package/types/Message.d.mts +84 -0
  61. package/types/Message.d.mts.map +1 -0
  62. package/types/Server.d.mts +98 -0
  63. package/types/Server.d.mts.map +1 -0
  64. package/types/index.d.mts +6 -0
  65. package/types/index.d.mts.map +1 -0
  66. package/types/internal/decode.d.mts +4 -0
  67. package/types/internal/decode.d.mts.map +1 -0
  68. package/types/osc.d.mts +66 -0
  69. package/types/osc.d.mts.map +1 -0
@@ -107,3 +107,155 @@ tap.test('client: failure', (t) => {
107
107
  t.equal(err.code, 'ERR_SOCKET_DGRAM_NOT_RUNNING');
108
108
  });
109
109
  });
110
+
111
+ tap.test('client: close with callback', (t) => {
112
+ const client = new nodeOsc.Client('127.0.0.1', t.context.port);
113
+
114
+ t.plan(1);
115
+
116
+ client.close((err) => {
117
+ t.error(err, 'close should not error');
118
+ });
119
+ });
120
+
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);
124
+
125
+ t.plan(2);
126
+
127
+ oscServer.on('bundle', (bundle) => {
128
+ oscServer.close();
129
+ t.equal(bundle.timetag, 0, 'should receive immediate execution timetag as 0');
130
+ t.ok(bundle.elements.length > 0, 'should have elements');
131
+ client.close();
132
+ });
133
+
134
+ // Send bundle with non-numeric timetag (will be encoded as immediate execution)
135
+ const bundle = {
136
+ oscType: 'bundle',
137
+ timetag: 'immediate', // Non-numeric, will trigger the else branch in writeTimeTag
138
+ elements: [
139
+ {
140
+ oscType: 'message',
141
+ address: '/test1',
142
+ args: [{ type: 'i', value: 42 }]
143
+ }
144
+ ]
145
+ };
146
+
147
+ client.send(bundle);
148
+ });
149
+
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);
153
+
154
+ t.plan(2);
155
+
156
+ oscServer.on('bundle', (bundle) => {
157
+ oscServer.close();
158
+ t.equal(bundle.timetag, 0, 'should receive immediate execution timetag as 0');
159
+ t.ok(bundle.elements.length > 0, 'should have elements');
160
+ client.close();
161
+ });
162
+
163
+ // Send bundle with null timetag (will be encoded as immediate execution)
164
+ const bundle = {
165
+ oscType: 'bundle',
166
+ timetag: null, // Null, will trigger the else branch in writeTimeTag
167
+ elements: [
168
+ {
169
+ oscType: 'message',
170
+ address: '/test2',
171
+ args: [{ type: 's', value: 'hello' }]
172
+ }
173
+ ]
174
+ };
175
+
176
+ client.send(bundle);
177
+ });
178
+
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);
182
+
183
+ t.plan(2);
184
+
185
+ oscServer.on('message', (msg) => {
186
+ oscServer.close();
187
+ t.equal(msg[0], '/float-test', 'should receive address');
188
+ t.ok(Math.abs(msg[1] - 9.876) < 0.001, 'should receive float value');
189
+ client.close();
190
+ });
191
+
192
+ // Send raw message with 'float' type to hit that case label
193
+ client.send({
194
+ oscType: 'message',
195
+ address: '/float-test',
196
+ args: [{ type: 'float', value: 9.876 }]
197
+ });
198
+ });
199
+
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);
203
+
204
+ t.plan(2);
205
+
206
+ oscServer.on('message', (msg) => {
207
+ oscServer.close();
208
+ t.equal(msg[0], '/blob-test', 'should receive address');
209
+ t.ok(Buffer.isBuffer(msg[1]), 'should receive blob as buffer');
210
+ client.close();
211
+ });
212
+
213
+ // Send raw message with 'blob' type to hit that case label
214
+ client.send({
215
+ oscType: 'message',
216
+ address: '/blob-test',
217
+ args: [{ type: 'blob', value: Buffer.from([0xAA, 0xBB]) }]
218
+ });
219
+ });
220
+
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);
224
+
225
+ t.plan(2);
226
+
227
+ oscServer.on('message', (msg) => {
228
+ oscServer.close();
229
+ t.equal(msg[0], '/double-test', 'should receive address');
230
+ t.ok(Math.abs(msg[1] - 1.23456789) < 0.001, 'should receive double value as float');
231
+ client.close();
232
+ });
233
+
234
+ // Send raw message with 'double' type to hit that case label
235
+ client.send({
236
+ oscType: 'message',
237
+ address: '/double-test',
238
+ args: [{ type: 'double', value: 1.23456789 }]
239
+ });
240
+ });
241
+
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);
245
+
246
+ t.plan(2);
247
+
248
+ oscServer.on('message', (msg) => {
249
+ oscServer.close();
250
+ t.equal(msg[0], '/midi-test', 'should receive address');
251
+ t.ok(Buffer.isBuffer(msg[1]), 'should receive MIDI as buffer');
252
+ client.close();
253
+ });
254
+
255
+ // Send raw message with 'midi' type to hit that case label
256
+ client.send({
257
+ oscType: 'message',
258
+ address: '/midi-test',
259
+ args: [{ type: 'midi', value: Buffer.from([0x00, 0x90, 0x40, 0x60]) }]
260
+ });
261
+ });
@@ -23,9 +23,12 @@ tap.test('osc: argument message no callback', (t) => {
23
23
 
24
24
  t.plan(1);
25
25
 
26
- oscServer.on('message', (msg) => {
26
+ t.teardown(() => {
27
27
  oscServer.close();
28
28
  client.close();
29
+ });
30
+
31
+ oscServer.on('message', (msg) => {
29
32
  t.same(msg, ['/test', 1, 2, 'testing'], 'We should receive expected payload');
30
33
  });
31
34
 
@@ -40,13 +43,16 @@ tap.test('osc: client with callback and message as arguments', (t) => {
40
43
 
41
44
  t.plan(2);
42
45
 
43
- oscServer.on('message', (msg) => {
46
+ t.teardown(() => {
44
47
  oscServer.close();
48
+ client.close();
49
+ });
50
+
51
+ oscServer.on('message', (msg) => {
45
52
  t.same(msg, ['/test', 1, 2, 'testing'], 'We should receive expected payload');
46
53
  });
47
54
 
48
55
  client.send('/test', 1, 2, 'testing', (err) => {
49
56
  t.error(err, 'there should be no error');
50
- client.close();
51
57
  });
52
58
  });