osc: avoid object serialization from custom module to client

This commit is contained in:
jean-emmanuel 2026-08-06 12:43:23 +02:00
parent 27d87f2238
commit 7981b6fdd6
2 changed files with 14 additions and 3 deletions

View file

@ -5,6 +5,9 @@
- bug fixes
- midi: unrecognized `no_auto_note_off` option
- custom module
- objects transmitted using `receive()` will be reiceved as objects by the client app (instead of a json string)
## 1.30.4
- bug fixes

View file

@ -53,13 +53,13 @@ export default class OscServer {
if (typeof lastArg === 'object' && lastArg !== null && lastArg.clientId !== undefined) {
options = args.pop()
}
this.receiveOsc({host, port, address, args:args.map(x=>this.parseArg(x)), cm: 1}, options.clientId)
this.receiveOsc({host, port, address, args:args.map(x=>this.parseArg(x, null, true)), cm: 1}, options.clientId)
},
}) : {}
}
parseArg(arg, type){
parseArg(arg, type, allowObjects = false){
if (arg === null) return null
@ -95,7 +95,15 @@ export default class OscServer {
case 'string':
return {type: 's', value: arg}
default:
return {type: 's', value: JSON.stringify(arg)}
if (allowObjects) {
// Allow js objects in args when receiving from a custom module
// they will eventually be serialized (as json) with the rest of
// the ws message but the client will de-serialize it automatically
// note: type "o" is off-spec, but we don't use typetag in this case anyway
return {type: 'o', value: arg}
} else {
return {type: 's', value: JSON.stringify(arg)}
}
}
}