From bdd83657c84134b26fbef681b97d7d6220c6f29e Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sat, 11 Jan 2025 16:41:07 +0100 Subject: [PATCH] custom module: `receive()` and `send()` now accept `host` and `port` to be provided as a single string argument joined by a colon --- CHANGELOG.md | 3 +++ resources/docs/docs/custom-module/custom-module.md | 2 ++ src/server/osc/index.js | 14 ++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6dc35a8..b93a0ad5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ - widgets - matrix: don't implicitely override children's `label`, do it explicitely in `props`' default +- custom module + - `receive()` and `send()` now accept `host` and `port` to be provided as a single string argument joined by a colon. + ## 1.27.1 - bug fixes diff --git a/resources/docs/docs/custom-module/custom-module.md b/resources/docs/docs/custom-module/custom-module.md index eac6bc0a..3615e4fc 100644 --- a/resources/docs/docs/custom-module/custom-module.md +++ b/resources/docs/docs/custom-module/custom-module.md @@ -90,6 +90,8 @@ Send osc/midi message to connected clients. `host` and `port` can be specified t - `args`: value or `{type: "OSC_TYPE_LETTER", value: VALUE}` `object` (objects that don't match this format will simply be turned to a JSON string). - `options` (optional): set to `{clientId: id}` to define which client receives the message (where `id` is the client's id as retrieved from `app` events or `oscOutFilter`) +For convenience, `host` and `port` can be provided both as single string argument joined with a colon. + ---- #### `send(host, port, address, ...args)` diff --git a/src/server/osc/index.js b/src/server/osc/index.js index 8061369d..85046ce2 100644 --- a/src/server/osc/index.js +++ b/src/server/osc/index.js @@ -22,6 +22,14 @@ class OscServer { sendOsc: this.sendOsc.bind(this), receiveOsc: this.receiveOsc.bind(this), send: (host, port, address, ...args)=>{ + if (host.indexOf(':') > -1) { + args.unshift(address) + address = port + var split = host.split(':') + host = split[0] + port = parseInt(split[1]) + } + this.sendOsc({host, port, address, args:args.map(x=>this.parseArg(x))}) }, receive: (host, port, address, ...args)=>{ @@ -31,6 +39,12 @@ class OscServer { if (port !== undefined) args.unshift(port) address = host host = port = undefined + } else if (host.indexOf(':') > -1) { + args.unshift(address) + address = port + var split = host.split(':') + host = split[0] + port = parseInt(split[1]) } var lastArg = args[args.length - 1], options = {}