custom module: receive() and send() now accept host and port to be provided as a single string argument joined by a colon

This commit is contained in:
jean-emmanuel 2025-01-11 16:41:07 +01:00
parent 857e0408be
commit bdd83657c8
3 changed files with 19 additions and 0 deletions

View file

@ -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

View file

@ -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)`

View file

@ -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 = {}