Initialize widget value from osc server

If I open a session full of widgets, I want the widgets to ask the osc server for their current values when it first starts up. This requires sending out an osc message that is slightly different than the widget's osc command. for example:

widget osc message: /the/thing 100
widget initial value request: /get/the/thing
When the server receives /get/the/thing,
it sends out /the/thing <current value>

I know I could setup a custom script that sends all the appropriate /get messages, but then I have to keep track of all the widgets and chages inside that script. Is there a trick to get each widget to send out its own /get message, at session start, based on a standard change to it's own osc address?

I suppose you could try something like this in your custom module:


var initialRequest = false


app.on('sessionOpened', (data, client)=>{
    initialRequest = true
    // force all widgets to send their messages
    // yes, maybe there should be a /STATE/SEND
    receive('/STATE/STORE', {clientId: client.id})
    receive('/STATE/RECALL', {clientId: client.id})
    // wait a bit and remove flag  
    setTimeout(()=>{
        initialRequest = false
    }, 250)
})

module.exports = {
    
    oscOutFilter: (data)=>{

        if (initialRequest) {
            data.address = '/get' + data.address
        }

        return data
    }
    
}

Thank you. That worked.

Just an FYI. This method works for a single client, but had problems with multiple clients in my use case. I found a JSON-RPC message for Guitarix (method: "get_parameter", params: []) that gets the server to respond with all current parameter values (among other info), so I'm using it now in my application. This obviously won't apply to most other use cases, and this method worked well for a single client for me, so just some information if you're trying to apply this to your case.