node-osc 11.0.0 → 11.1.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.
- package/README.md +1 -3
- package/dist/lib/internal/osc.js +20 -19
- package/dist/test/test-e2e.js +4 -4
- package/lib/internal/osc.mjs +2 -0
- package/package.json +1 -1
- package/rollup.config.mjs +6 -2
- package/test/test-e2e.mjs +4 -4
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ npm install node-osc
|
|
|
11
11
|
|
|
12
12
|
## Written using ESM supports CJS
|
|
13
13
|
|
|
14
|
-
Supports the latest versions of Node.js
|
|
14
|
+
Supports the latest versions of Node.js 20, 22, and 24 in both ESM + CJS
|
|
15
15
|
|
|
16
16
|
## Example
|
|
17
17
|
|
|
@@ -58,8 +58,6 @@ client.send(bundle));
|
|
|
58
58
|
|
|
59
59
|
### Listening for OSC bundles:
|
|
60
60
|
|
|
61
|
-
**WARNING**: Bundle support is Experimental and subject to change at any point.
|
|
62
|
-
|
|
63
61
|
```js
|
|
64
62
|
import { Server } from 'node-osc';
|
|
65
63
|
|
package/dist/lib/internal/osc.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var node_buffer = require('node:buffer');
|
|
4
|
+
|
|
3
5
|
// OSC 1.0 Protocol Implementation
|
|
4
6
|
// Based on http://opensoundcontrol.org/spec-1_0
|
|
5
7
|
|
|
6
|
-
// Helper functions for OSC encoding/decoding
|
|
7
8
|
|
|
8
9
|
function padString(str) {
|
|
9
10
|
const nullTerminated = str + '\0';
|
|
@@ -23,7 +24,7 @@ function readString(buffer, offset) {
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
function writeInt32(value) {
|
|
26
|
-
const buffer = Buffer.alloc(4);
|
|
27
|
+
const buffer = node_buffer.Buffer.alloc(4);
|
|
27
28
|
buffer.writeInt32BE(value, 0);
|
|
28
29
|
return buffer;
|
|
29
30
|
}
|
|
@@ -34,7 +35,7 @@ function readInt32(buffer, offset) {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
function writeFloat32(value) {
|
|
37
|
-
const buffer = Buffer.alloc(4);
|
|
38
|
+
const buffer = node_buffer.Buffer.alloc(4);
|
|
38
39
|
buffer.writeFloatBE(value, 0);
|
|
39
40
|
return buffer;
|
|
40
41
|
}
|
|
@@ -48,8 +49,8 @@ function writeBlob(value) {
|
|
|
48
49
|
const length = value.length;
|
|
49
50
|
const lengthBuffer = writeInt32(length);
|
|
50
51
|
const padding = 4 - (length % 4);
|
|
51
|
-
const paddingBuffer = Buffer.alloc(padding === 4 ? 0 : padding);
|
|
52
|
-
return Buffer.concat([lengthBuffer, value, paddingBuffer]);
|
|
52
|
+
const paddingBuffer = node_buffer.Buffer.alloc(padding === 4 ? 0 : padding);
|
|
53
|
+
return node_buffer.Buffer.concat([lengthBuffer, value, paddingBuffer]);
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
function readBlob(buffer, offset) {
|
|
@@ -64,7 +65,7 @@ function readBlob(buffer, offset) {
|
|
|
64
65
|
function writeTimeTag(value) {
|
|
65
66
|
// For now, treat timetag as a double (8 bytes)
|
|
66
67
|
// OSC timetag is 64-bit: 32-bit seconds since 1900, 32-bit fractional
|
|
67
|
-
const buffer = Buffer.alloc(8);
|
|
68
|
+
const buffer = node_buffer.Buffer.alloc(8);
|
|
68
69
|
if (typeof value === 'number') {
|
|
69
70
|
// Convert to OSC timetag format
|
|
70
71
|
const seconds = Math.floor(value);
|
|
@@ -99,9 +100,9 @@ function readTimeTag(buffer, offset) {
|
|
|
99
100
|
|
|
100
101
|
function writeMidi(value) {
|
|
101
102
|
// MIDI message is 4 bytes: port id, status byte, data1, data2
|
|
102
|
-
const buffer = Buffer.alloc(4);
|
|
103
|
+
const buffer = node_buffer.Buffer.alloc(4);
|
|
103
104
|
|
|
104
|
-
if (Buffer.isBuffer(value)) {
|
|
105
|
+
if (node_buffer.Buffer.isBuffer(value)) {
|
|
105
106
|
if (value.length !== 4) {
|
|
106
107
|
throw new Error('MIDI message must be exactly 4 bytes');
|
|
107
108
|
}
|
|
@@ -140,7 +141,7 @@ function encodeArgument(arg) {
|
|
|
140
141
|
return { tag: 'f', data: writeFloat32(arg.value) };
|
|
141
142
|
case 's':
|
|
142
143
|
case 'string':
|
|
143
|
-
return { tag: 's', data: Buffer.from(padString(arg.value)) };
|
|
144
|
+
return { tag: 's', data: node_buffer.Buffer.from(padString(arg.value)) };
|
|
144
145
|
case 'b':
|
|
145
146
|
case 'blob':
|
|
146
147
|
return { tag: 'b', data: writeBlob(arg.value) };
|
|
@@ -150,7 +151,7 @@ function encodeArgument(arg) {
|
|
|
150
151
|
return { tag: 'f', data: writeFloat32(arg.value) };
|
|
151
152
|
case 'T':
|
|
152
153
|
case 'boolean':
|
|
153
|
-
return arg.value ? { tag: 'T', data: Buffer.alloc(0) } : { tag: 'F', data: Buffer.alloc(0) };
|
|
154
|
+
return arg.value ? { tag: 'T', data: node_buffer.Buffer.alloc(0) } : { tag: 'F', data: node_buffer.Buffer.alloc(0) };
|
|
154
155
|
case 'm':
|
|
155
156
|
case 'midi':
|
|
156
157
|
return { tag: 'm', data: writeMidi(arg.value) };
|
|
@@ -168,11 +169,11 @@ function encodeArgument(arg) {
|
|
|
168
169
|
return { tag: 'f', data: writeFloat32(arg) };
|
|
169
170
|
}
|
|
170
171
|
case 'string':
|
|
171
|
-
return { tag: 's', data: Buffer.from(padString(arg)) };
|
|
172
|
+
return { tag: 's', data: node_buffer.Buffer.from(padString(arg)) };
|
|
172
173
|
case 'boolean':
|
|
173
|
-
return arg ? { tag: 'T', data: Buffer.alloc(0) } : { tag: 'F', data: Buffer.alloc(0) };
|
|
174
|
+
return arg ? { tag: 'T', data: node_buffer.Buffer.alloc(0) } : { tag: 'F', data: node_buffer.Buffer.alloc(0) };
|
|
174
175
|
default:
|
|
175
|
-
if (Buffer.isBuffer(arg)) {
|
|
176
|
+
if (node_buffer.Buffer.isBuffer(arg)) {
|
|
176
177
|
return { tag: 'b', data: writeBlob(arg) };
|
|
177
178
|
}
|
|
178
179
|
throw new Error(`Don't know how to encode argument: ${arg}`);
|
|
@@ -217,15 +218,15 @@ function encodeMessageToBuffer(message) {
|
|
|
217
218
|
// Arguments (encoded according to type tags)
|
|
218
219
|
|
|
219
220
|
const address = padString(message.address);
|
|
220
|
-
const addressBuffer = Buffer.from(address);
|
|
221
|
+
const addressBuffer = node_buffer.Buffer.from(address);
|
|
221
222
|
|
|
222
223
|
const encodedArgs = message.args.map(encodeArgument);
|
|
223
224
|
const typeTags = ',' + encodedArgs.map(arg => arg.tag).join('');
|
|
224
|
-
const typeTagsBuffer = Buffer.from(padString(typeTags));
|
|
225
|
+
const typeTagsBuffer = node_buffer.Buffer.from(padString(typeTags));
|
|
225
226
|
|
|
226
227
|
const argumentBuffers = encodedArgs.map(arg => arg.data);
|
|
227
228
|
|
|
228
|
-
return Buffer.concat([addressBuffer, typeTagsBuffer, ...argumentBuffers]);
|
|
229
|
+
return node_buffer.Buffer.concat([addressBuffer, typeTagsBuffer, ...argumentBuffers]);
|
|
229
230
|
}
|
|
230
231
|
|
|
231
232
|
function encodeBundleToBuffer(bundle) {
|
|
@@ -235,7 +236,7 @@ function encodeBundleToBuffer(bundle) {
|
|
|
235
236
|
// Elements (each prefixed with size)
|
|
236
237
|
|
|
237
238
|
const bundleString = padString('#bundle');
|
|
238
|
-
const bundleStringBuffer = Buffer.from(bundleString);
|
|
239
|
+
const bundleStringBuffer = node_buffer.Buffer.from(bundleString);
|
|
239
240
|
|
|
240
241
|
const timetagBuffer = writeTimeTag(bundle.timetag);
|
|
241
242
|
|
|
@@ -247,10 +248,10 @@ function encodeBundleToBuffer(bundle) {
|
|
|
247
248
|
elementBuffer = encodeMessageToBuffer(element);
|
|
248
249
|
}
|
|
249
250
|
const sizeBuffer = writeInt32(elementBuffer.length);
|
|
250
|
-
return Buffer.concat([sizeBuffer, elementBuffer]);
|
|
251
|
+
return node_buffer.Buffer.concat([sizeBuffer, elementBuffer]);
|
|
251
252
|
});
|
|
252
253
|
|
|
253
|
-
return Buffer.concat([bundleStringBuffer, timetagBuffer, ...elementBuffers]);
|
|
254
|
+
return node_buffer.Buffer.concat([bundleStringBuffer, timetagBuffer, ...elementBuffers]);
|
|
254
255
|
}
|
|
255
256
|
|
|
256
257
|
function fromBuffer(buffer) {
|
package/dist/test/test-e2e.js
CHANGED
|
@@ -18,8 +18,8 @@ function skip(t) {
|
|
|
18
18
|
tap.test('osc: argument message no callback', (t) => {
|
|
19
19
|
if (flaky()) return skip(t);
|
|
20
20
|
|
|
21
|
-
const oscServer = new nodeOsc.Server(t.context.port, '
|
|
22
|
-
const client = new nodeOsc.Client('
|
|
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);
|
|
23
23
|
|
|
24
24
|
t.plan(1);
|
|
25
25
|
|
|
@@ -35,8 +35,8 @@ tap.test('osc: argument message no callback', (t) => {
|
|
|
35
35
|
tap.test('osc: client with callback and message as arguments', (t) => {
|
|
36
36
|
if (flaky()) return skip(t);
|
|
37
37
|
|
|
38
|
-
const oscServer = new nodeOsc.Server(t.context.port, '
|
|
39
|
-
const client = new nodeOsc.Client('
|
|
38
|
+
const oscServer = new nodeOsc.Server(t.context.port, '127.0.0.1');
|
|
39
|
+
const client = new nodeOsc.Client('127.0.0.1', t.context.port);
|
|
40
40
|
|
|
41
41
|
t.plan(2);
|
|
42
42
|
|
package/lib/internal/osc.mjs
CHANGED
package/package.json
CHANGED
package/rollup.config.mjs
CHANGED
|
@@ -34,8 +34,10 @@ function walkLib(config) {
|
|
|
34
34
|
external: [
|
|
35
35
|
'node:dgram',
|
|
36
36
|
'node:events',
|
|
37
|
+
'node:buffer',
|
|
37
38
|
'jspack',
|
|
38
|
-
'#decode'
|
|
39
|
+
'#decode',
|
|
40
|
+
'#osc'
|
|
39
41
|
]
|
|
40
42
|
});
|
|
41
43
|
});
|
|
@@ -57,9 +59,11 @@ function walkTest(config) {
|
|
|
57
59
|
external: [
|
|
58
60
|
'node:dgram',
|
|
59
61
|
'node:net',
|
|
62
|
+
'node:buffer',
|
|
60
63
|
'node-osc',
|
|
61
64
|
'tap',
|
|
62
|
-
'#decode'
|
|
65
|
+
'#decode',
|
|
66
|
+
'#osc'
|
|
63
67
|
]
|
|
64
68
|
});
|
|
65
69
|
});
|
package/test/test-e2e.mjs
CHANGED
|
@@ -17,8 +17,8 @@ function skip(t) {
|
|
|
17
17
|
test('osc: argument message no callback', (t) => {
|
|
18
18
|
if (flaky()) return skip(t);
|
|
19
19
|
|
|
20
|
-
const oscServer = new Server(t.context.port, '
|
|
21
|
-
const client = new Client('
|
|
20
|
+
const oscServer = new Server(t.context.port, '127.0.0.1');
|
|
21
|
+
const client = new Client('127.0.0.1', t.context.port);
|
|
22
22
|
|
|
23
23
|
t.plan(1);
|
|
24
24
|
|
|
@@ -34,8 +34,8 @@ test('osc: argument message no callback', (t) => {
|
|
|
34
34
|
test('osc: client with callback and message as arguments', (t) => {
|
|
35
35
|
if (flaky()) return skip(t);
|
|
36
36
|
|
|
37
|
-
const oscServer = new Server(t.context.port, '
|
|
38
|
-
const client = new Client('
|
|
37
|
+
const oscServer = new Server(t.context.port, '127.0.0.1');
|
|
38
|
+
const client = new Client('127.0.0.1', t.context.port);
|
|
39
39
|
|
|
40
40
|
t.plan(2);
|
|
41
41
|
|