From d2605f163b57c29cfbe8ec93f2c8ad0ddaa48081 Mon Sep 17 00:00:00 2001 From: Chris Angelico Date: Mon, 6 Jan 2025 11:28:35 +1100 Subject: [PATCH] Implement getStatus and clean up the rest of the code --- httpstatic/obs.js | 30 +++++------------------------- modules/http/chan_obs.pike | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/httpstatic/obs.js b/httpstatic/obs.js index 1e801890..ac3361cb 100644 --- a/httpstatic/obs.js +++ b/httpstatic/obs.js @@ -3,6 +3,9 @@ const {} = choc; //autoimport export function render(data) {} +export function sockmsg_get_status(msg) { + obsstudio.getStatus(status => ws_sync.send({cmd: "response", key: msg.key, ...status})); +} export function sockmsg_get_scene(msg) { obsstudio.getCurrentScene(scene => ws_sync.send({cmd: "response", key: msg.key, scenename: scene.name})); } @@ -10,30 +13,7 @@ export function sockmsg_set_scene(msg) { obsstudio.setCurrentScene(msg.scenename); sockmsg_get_scene(msg); } +//TODO maybe: saveReplayBuffer? //ws_sync.send({cmd: "logme", keys: Object.keys(obsstudio).sort()}); -//obsstudio.getCurrentScene(sc => ws_sync.send({cmd: "logme", sc})); -//obsstudio.setCurrentScene("Big Head Mode"); - -/* -"getControlLevel", -"getCurrentScene", -"getCurrentTransition", -"getScenes", -"getStatus", -"getTransitions", -"pauseRecording", -"pluginVersion", -"saveReplayBuffer", -"setCurrentScene", -"setCurrentTransition", -"startRecording", -"startReplayBuffer", -"startStreaming", -"startVirtualcam", -"stopRecording", -"stopReplayBuffer", -"stopStreaming", -"stopVirtualcam", -"unpauseRecording" -*/ +//obsstudio.getControlLevel(sc => ws_sync.send({cmd: "logme", sc})); diff --git a/modules/http/chan_obs.pike b/modules/http/chan_obs.pike index da89e019..0c1e1bd2 100644 --- a/modules/http/chan_obs.pike +++ b/modules/http/chan_obs.pike @@ -23,9 +23,11 @@ Need to reset the key? [Reset key](:#resetkey) will disable any previous link an constant builtin_name = "OBS Studio"; constant builtin_description = "Manage OBS Studio"; -constant builtin_param = ({"/Action/Get scene/Switch scene", "Parameter"}); +constant builtin_param = ({"/Action/Status/Get scene/Switch scene", "Parameter"}); constant vars_provided = ([ - "{scenename}": "Current scene name", + "{scenename}": "Current scene name (get/switch scene)", + "{streaming}": "1 if streaming, 0 if not (status)", + "{recording}": "1 if recording, 0 if not (status)", ]); @retain: mapping obsstudio_inflight_messages = ([]); @@ -42,8 +44,15 @@ __async__ mapping send_obs_signal(object channel, mapping msg) { } __async__ mapping message_params(object channel, mapping person, array param, mapping cfg) { - //TODO: If no client connected, immediate error switch (param[0]) { + case "Status": { + mapping info = await(send_obs_signal(channel, (["cmd": "get_status"]))); + //Also available, if of interest: recordingPaused, replaybuffer, virtualcam + return ([ + "{streaming}": (string)(int)info->streaming, + "{recording}": (string)(int)info->recording, + ]); + } case "Get scene": { mapping info = await(send_obs_signal(channel, (["cmd": "get_scene"]))); return (["{scenename}": (string)info->scenename]);