UNPKG

node-osc

Version:

pyOSC inspired library for sending and receiving OSC messages

36 lines (27 loc) 1.06 kB
// Test ESM TypeScript imports with Top-Level Await import { once } from 'node:events'; import { Client, Server, Message, Bundle, encode, decode } from 'node-osc'; // Create server first (typical usage pattern) const server: Server = new Server(3333, '0.0.0.0'); // Wait for server to be ready (pattern from examples) await once(server, 'listening'); server.on('message', (msg) => { console.log('Received message:', msg); }); // Create client after server const client: Client = new Client('127.0.0.1', 3333); // Test async usage with Top-Level Await (ESM feature) await client.send('/test', 1, 2, 3); await client.close(); await server.close(); // Test Message type const message: Message = new Message('/oscillator/frequency', 440); message.append(3.14); message.append('hello'); message.append(true); // Test Bundle type const bundle: Bundle = new Bundle(['/one', 1], ['/two', 2]); bundle.append(['/three', 3]); // Test encode/decode with consistent type annotations const encoded: Buffer = encode(message); const decoded: Object = decode(encoded);