From 7981b6fdd676764e6e5b463f10e44994f210acc4 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Thu, 6 Aug 2026 12:43:23 +0200 Subject: [PATCH] osc: avoid object serialization from custom module to client --- CHANGELOG.md | 3 +++ src/server/node/osc/index.mjs | 14 +++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98cea48f..5efa2b70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/server/node/osc/index.mjs b/src/server/node/osc/index.mjs index 89870658..4b0444c0 100644 --- a/src/server/node/osc/index.mjs +++ b/src/server/node/osc/index.mjs @@ -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)} + } } }