Skip to content

The module's structure makes it hard to customize #136

Open
@jean-emmanuel

Description

@jean-emmanuel

Not really an issue, but while trying to add support for utf8 encoded string arguments to my application, I found out osc's reader / writer functions could not be overridden easily due to the module's structure that uses a scoped copy of the osc variable (if I understood correctly).

Anyway, I ended up with the following workaround:

// require this file in node instead of 'osc'

var osc = require('osc/src/osc.js'),
    transports = require('osc/src/platforms/osc-node.js'),
    utf8 = require('utf8')

// import needed transport modules
osc.UDPPort = transports.UDPPort
osc.TCPSocketPort = transports.TCPSocketPort

osc.writeUtfString = (str)=>{
    return osc.writeString(utf8.encode(str))
}

osc.readUtfString = (dv, offsetState)=>{
    return utf8.decode(osc.readString(dv, offsetState))
}

osc.argumentTypes.s = osc.argumentTypes.S = {
    reader: 'readUtfString',
    writer: 'writeUtfString'
}

module.exports = osc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions