export = Server; /** * OSC Server for receiving messages and bundles over UDP. * * Emits the following events: * - 'listening': Emitted when the server starts listening * - 'message': Emitted when an OSC message is received (receives msg array and rinfo object) * - 'bundle': Emitted when an OSC bundle is received (receives bundle object and rinfo object) * - 'error': Emitted when a socket error or decoding error occurs (receives error and rinfo) * - Address-specific events: Emitted for each message address (e.g., '/test') * * @class * @extends EventEmitter * * @fires Server#listening * @fires Server#message * @fires Server#bundle * @fires Server#error * * @example * // Create and listen for messages * const server = new Server(3333, '0.0.0.0', () => { * console.log('Server is listening'); * }); * * server.on('message', (msg, rinfo) => { * console.log('Message:', msg); * console.log('From:', rinfo.address, rinfo.port); * }); * * @example * // Using async/await with events.once * import { once } from 'node:events'; * * const server = new Server(3333, '0.0.0.0'); * await once(server, 'listening'); * * server.on('message', (msg) => { * console.log('Message:', msg); * }); * * @example * // Listen for specific OSC addresses * server.on('/note', (msg) => { * const [address, pitch, velocity] = msg; * console.log(`Note: ${pitch}, Velocity: ${velocity}`); * }); */ declare class Server { /** * Create an OSC Server. * * @param {number} port - The port to listen on. * @param {string} [host='127.0.0.1'] - The host address to bind to. Use '0.0.0.0' to listen on all interfaces. * @param {Function} [cb] - Optional callback function called when server starts listening. * * @example * // Basic server * const server = new Server(3333); * * @example * // Server on all interfaces with callback * const server = new Server(3333, '0.0.0.0', () => { * console.log('Server started'); * }); * * @example * // Host parameter can be omitted, callback as second parameter * const server = new Server(3333, () => { * console.log('Server started on 127.0.0.1'); * }); */ constructor(port: number, host?: string, cb?: Function); port: number; host: string; _isListening: boolean; _isClosed: boolean; _sock: node_dgram.Socket; /** * Send an OSC message or bundle from the server's bound socket. * * This method can be used with either a callback or as a Promise. * * @param {Message|Bundle|Array|string} message - The message, bundle, address, or array to send. * @param {number} port - The remote port to send to. * @param {string} host - The remote host to send to. * @param {Function} [cb] - Optional callback function called when send completes. * @returns {Promise|undefined} Returns a Promise if no callback is provided. * * @throws {Error} If the server socket is not yet listening. * @throws {TypeError} If the message format is invalid. * @throws {ReferenceError} If attempting to send on a closed socket. * * @example * // Send an address-only message * await server.send('/ping', 9000, '127.0.0.1'); * * @example * // Send an array message * server.send(['/ack', 1], 9000, '192.168.1.42', (err) => { * if (err) console.error(err); * }); */ send(message: Message | Bundle | any[] | string, port: number, host: string, cb?: Function): Promise | undefined; /** * Close the server socket. * * This method can be used with either a callback or as a Promise. * * @param {Function} [cb] - Optional callback function called when socket is closed. * @returns {Promise|undefined} Returns a Promise if no callback is provided. * * @example * // With callback * server.close((err) => { * if (err) console.error(err); * }); * * @example * // With async/await * await server.close(); */ close(cb?: Function): Promise | undefined; } import node_dgram = require("node:dgram"); //# sourceMappingURL=Server.d.ts.map