node-osc 11.1.0 → 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.
- package/.gitattributes +11 -0
- package/.github/workflows/bump-version.yml +2 -0
- package/.github/workflows/nodejs.yml +3 -0
- package/LICENSE +201 -165
- package/README.md +135 -42
- package/dist/lib/Bundle.js +66 -0
- package/dist/lib/Client.js +137 -22
- package/dist/lib/Message.js +87 -1
- package/dist/lib/Server.js +117 -6
- package/dist/lib/index.js +3 -0
- package/dist/lib/internal/decode.js +4 -4
- package/{lib/internal/osc.mjs → dist/lib/osc.js} +94 -23
- package/dist/test/lib/osc.js +395 -0
- package/dist/test/test-client.js +152 -0
- package/dist/test/test-e2e.js +9 -3
- package/dist/test/test-encode-decode.js +849 -0
- package/dist/test/test-error-handling.js +116 -0
- package/dist/test/test-osc-internal.js +399 -41
- package/dist/test/test-promises.js +250 -0
- package/dist/test/test-types.js +42 -0
- package/dist/test/util.js +15 -8
- package/docs/API.md +477 -0
- package/docs/GUIDE.md +605 -0
- package/examples/README.md +119 -0
- package/examples/async-await.mjs +57 -0
- package/examples/bundle-example.mjs +92 -0
- package/examples/client.js +22 -5
- package/examples/error-handling.mjs +152 -0
- package/examples/esm.mjs +21 -0
- package/examples/server.js +16 -0
- package/jsdoc.json +16 -0
- package/lib/Bundle.mjs +66 -0
- package/lib/Client.mjs +137 -22
- package/lib/Message.mjs +87 -1
- package/lib/Server.mjs +117 -6
- package/lib/index.mjs +1 -0
- package/lib/internal/decode.mjs +4 -4
- package/{dist/lib/internal/osc.js → lib/osc.mjs} +71 -7
- package/package.json +12 -10
- package/rollup.config.mjs +48 -37
- package/scripts/generate-docs.mjs +229 -0
- package/test/fixtures/types/test-cjs-types.ts +19 -0
- package/test/fixtures/types/test-esm-types.ts +35 -0
- package/test/fixtures/types/tsconfig-cjs.test.json +17 -0
- package/test/fixtures/types/tsconfig-esm.test.json +17 -0
- package/test/test-bundle.mjs +0 -1
- package/test/test-client.mjs +152 -0
- package/test/test-e2e.mjs +9 -3
- package/test/test-encode-decode.mjs +847 -0
- package/test/test-error-handling.mjs +115 -0
- package/test/test-osc-internal.mjs +400 -42
- package/test/test-promises.mjs +249 -0
- package/test/test-types.mjs +39 -0
- package/test/util.mjs +15 -8
- package/tsconfig.json +45 -0
- package/types/Bundle.d.mts +70 -0
- package/types/Bundle.d.mts.map +1 -0
- package/types/Client.d.mts +101 -0
- package/types/Client.d.mts.map +1 -0
- package/types/Message.d.mts +84 -0
- package/types/Message.d.mts.map +1 -0
- package/types/Server.d.mts +98 -0
- package/types/Server.d.mts.map +1 -0
- package/types/index.d.mts +6 -0
- package/types/index.d.mts.map +1 -0
- package/types/internal/decode.d.mts +4 -0
- package/types/internal/decode.d.mts.map +1 -0
- package/types/osc.d.mts +66 -0
- package/types/osc.d.mts.map +1 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export default Server;
|
|
2
|
+
/**
|
|
3
|
+
* OSC Server for receiving messages and bundles over UDP.
|
|
4
|
+
*
|
|
5
|
+
* Emits the following events:
|
|
6
|
+
* - 'listening': Emitted when the server starts listening
|
|
7
|
+
* - 'message': Emitted when an OSC message is received (receives msg array and rinfo object)
|
|
8
|
+
* - 'bundle': Emitted when an OSC bundle is received (receives bundle object and rinfo object)
|
|
9
|
+
* - 'error': Emitted when a socket error or decoding error occurs (receives error and rinfo)
|
|
10
|
+
* - Address-specific events: Emitted for each message address (e.g., '/test')
|
|
11
|
+
*
|
|
12
|
+
* @class
|
|
13
|
+
* @extends EventEmitter
|
|
14
|
+
*
|
|
15
|
+
* @fires Server#listening
|
|
16
|
+
* @fires Server#message
|
|
17
|
+
* @fires Server#bundle
|
|
18
|
+
* @fires Server#error
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Create and listen for messages
|
|
22
|
+
* const server = new Server(3333, '0.0.0.0', () => {
|
|
23
|
+
* console.log('Server is listening');
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* server.on('message', (msg, rinfo) => {
|
|
27
|
+
* console.log('Message:', msg);
|
|
28
|
+
* console.log('From:', rinfo.address, rinfo.port);
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* // Using async/await with events.once
|
|
33
|
+
* import { once } from 'node:events';
|
|
34
|
+
*
|
|
35
|
+
* const server = new Server(3333, '0.0.0.0');
|
|
36
|
+
* await once(server, 'listening');
|
|
37
|
+
*
|
|
38
|
+
* server.on('message', (msg) => {
|
|
39
|
+
* console.log('Message:', msg);
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* // Listen for specific OSC addresses
|
|
44
|
+
* server.on('/note', (msg) => {
|
|
45
|
+
* const [address, pitch, velocity] = msg;
|
|
46
|
+
* console.log(`Note: ${pitch}, Velocity: ${velocity}`);
|
|
47
|
+
* });
|
|
48
|
+
*/
|
|
49
|
+
declare class Server extends EventEmitter<[never]> {
|
|
50
|
+
/**
|
|
51
|
+
* Create an OSC Server.
|
|
52
|
+
*
|
|
53
|
+
* @param {number} port - The port to listen on.
|
|
54
|
+
* @param {string} [host='127.0.0.1'] - The host address to bind to. Use '0.0.0.0' to listen on all interfaces.
|
|
55
|
+
* @param {Function} [cb] - Optional callback function called when server starts listening.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* // Basic server
|
|
59
|
+
* const server = new Server(3333);
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* // Server on all interfaces with callback
|
|
63
|
+
* const server = new Server(3333, '0.0.0.0', () => {
|
|
64
|
+
* console.log('Server started');
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* // Host parameter can be omitted, callback as second parameter
|
|
69
|
+
* const server = new Server(3333, () => {
|
|
70
|
+
* console.log('Server started on 127.0.0.1');
|
|
71
|
+
* });
|
|
72
|
+
*/
|
|
73
|
+
constructor(port: number, host?: string, cb?: Function);
|
|
74
|
+
port: number;
|
|
75
|
+
host: string;
|
|
76
|
+
_sock: import("dgram").Socket;
|
|
77
|
+
/**
|
|
78
|
+
* Close the server socket.
|
|
79
|
+
*
|
|
80
|
+
* This method can be used with either a callback or as a Promise.
|
|
81
|
+
*
|
|
82
|
+
* @param {Function} [cb] - Optional callback function called when socket is closed.
|
|
83
|
+
* @returns {Promise<void>|undefined} Returns a Promise if no callback is provided.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* // With callback
|
|
87
|
+
* server.close((err) => {
|
|
88
|
+
* if (err) console.error(err);
|
|
89
|
+
* });
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* // With async/await
|
|
93
|
+
* await server.close();
|
|
94
|
+
*/
|
|
95
|
+
close(cb?: Function): Promise<void> | undefined;
|
|
96
|
+
}
|
|
97
|
+
import { EventEmitter } from 'node:events';
|
|
98
|
+
//# sourceMappingURL=Server.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Server.d.mts","sourceRoot":"","sources":["../lib/Server.mjs"],"names":[],"mappings":";AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH;IACE;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,kBApBW,MAAM,SACN,MAAM,iBAqEhB;IA1CC,aAAgB;IAChB,aAAgB;IAChB,8BAGE;IAsCJ;;;;;;;;;;;;;;;;;OAiBG;IACH,sBAZa,OAAO,CAAC,IAAI,CAAC,GAAC,SAAS,CAuBnC;CACF;6BA5J4B,aAAa"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as Message } from "./Message.mjs";
|
|
2
|
+
export { default as Bundle } from "./Bundle.mjs";
|
|
3
|
+
export { default as Server } from "./Server.mjs";
|
|
4
|
+
export { default as Client } from "./Client.mjs";
|
|
5
|
+
export { encode, decode } from "./osc.mjs";
|
|
6
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../lib/index.mjs"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.d.mts","sourceRoot":"","sources":["../../lib/internal/decode.mjs"],"names":[],"mappings":";AAmBA,iFAWC;uBA9BsB,YAAY"}
|
package/types/osc.d.mts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encode an OSC message or bundle to a Buffer.
|
|
3
|
+
*
|
|
4
|
+
* This low-level function converts OSC messages and bundles into binary format
|
|
5
|
+
* for transmission or storage. Useful for sending OSC over custom transports
|
|
6
|
+
* (WebSocket, TCP, HTTP), storing to files, or implementing custom OSC routers.
|
|
7
|
+
*
|
|
8
|
+
* @param {Object} message - OSC message or bundle object with oscType property
|
|
9
|
+
* @returns {Buffer} The encoded OSC data ready for transmission
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // Encode a message
|
|
13
|
+
* import { Message, encode } from 'node-osc';
|
|
14
|
+
*
|
|
15
|
+
* const message = new Message('/oscillator/frequency', 440);
|
|
16
|
+
* const buffer = encode(message);
|
|
17
|
+
* console.log('Encoded bytes:', buffer.length);
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // Encode a bundle
|
|
21
|
+
* import { Bundle, encode } from 'node-osc';
|
|
22
|
+
*
|
|
23
|
+
* const bundle = new Bundle(['/one', 1], ['/two', 2]);
|
|
24
|
+
* const buffer = encode(bundle);
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Send over WebSocket
|
|
28
|
+
* const buffer = encode(message);
|
|
29
|
+
* websocket.send(buffer);
|
|
30
|
+
*/
|
|
31
|
+
export function encode(message: any): Buffer;
|
|
32
|
+
/**
|
|
33
|
+
* Decode a Buffer containing OSC data into a message or bundle object.
|
|
34
|
+
*
|
|
35
|
+
* This low-level function parses binary OSC data back into JavaScript objects.
|
|
36
|
+
* Useful for receiving OSC over custom transports, reading from files,
|
|
37
|
+
* or implementing custom OSC routers.
|
|
38
|
+
*
|
|
39
|
+
* @param {Buffer} buffer - The Buffer containing OSC data
|
|
40
|
+
* @returns {Object} The decoded OSC message or bundle. Messages have
|
|
41
|
+
* {oscType: 'message', address: string, args: Array}, bundles have
|
|
42
|
+
* {oscType: 'bundle', timetag: number, elements: Array}
|
|
43
|
+
* @throws {Error} If the buffer contains malformed OSC data
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* // Decode received data
|
|
47
|
+
* import { decode } from 'node-osc';
|
|
48
|
+
*
|
|
49
|
+
* const decoded = decode(buffer);
|
|
50
|
+
* if (decoded.oscType === 'message') {
|
|
51
|
+
* console.log('Address:', decoded.address);
|
|
52
|
+
* console.log('Arguments:', decoded.args);
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* // Round-trip encode/decode
|
|
57
|
+
* import { Message, encode, decode } from 'node-osc';
|
|
58
|
+
*
|
|
59
|
+
* const original = new Message('/test', 42, 'hello');
|
|
60
|
+
* const buffer = encode(original);
|
|
61
|
+
* const decoded = decode(buffer);
|
|
62
|
+
* console.log(decoded.address); // '/test'
|
|
63
|
+
*/
|
|
64
|
+
export function decode(buffer: Buffer): any;
|
|
65
|
+
import { Buffer } from 'node:buffer';
|
|
66
|
+
//# sourceMappingURL=osc.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"osc.d.mts","sourceRoot":"","sources":["../lib/osc.mjs"],"names":[],"mappings":"AA+MA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,sCAtBa,MAAM,CA4BlB;AA6CD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,+BAzBW,MAAM,OAgChB;uBAlUsB,aAAa"}
|