osc: avoid object serialization from custom module to client
This commit is contained in:
parent
27d87f2238
commit
7981b6fdd6
2 changed files with 14 additions and 3 deletions
|
|
@ -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)}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue