Request info from /web/


I want to write a OBS-Overlay that request info from the bot every 5 Minutes. How can I send something via Socket to the server and response to this request? I only can send info from a script inside /scripts/ to the web and handle this info - but I didn’t find out how this works the other direction - I only found an example where we send a PING to the server…

Thanks for your help

The WebSocket is available to scripts in both directions

On the web side send the following json to the socket { socket_event: callback_id, script: script, args: { arguments: String(argsString), args: args } }

Where callback_id is a unique string representing the request, script is the path to the bot script to send the event to (same path that !module enable would use), argsString is a string-form argument, and args is a JSON Array form of String arguments (You can use just 1 argument type and leave the other as empty string/array if desired)

On the bot script side $.bind to webPanelSocketUpdate and use event.getScript(), event.getArguments() (String-form), and event.getArgs() (String[] form from the JSON Array)

To reply from the bot script side, use $.panelsocketserver.sendToAll(JSON.stringify({ query_id: callback_id, jsonDataHere })); and just replace jsonDataHere with your valid JSON payload

To receive on the web side, just hook to the onmessage callback of the websocket

1 Like

Thanks for the explanation - I will try this out

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.