diff --git a/CMakeLists.txt b/CMakeLists.txt index 397b3b43..517d4c9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,6 +89,7 @@ set(obs-websocket_SOURCES src/requesthandler/RequestHandler_General.cpp src/requesthandler/RequestHandler_Config.cpp src/requesthandler/RequestHandler_Sources.cpp + src/requesthandler/RequestHandler_Scenes.cpp src/requesthandler/rpc/Request.cpp src/requesthandler/rpc/RequestResult.cpp src/forms/SettingsDialog.cpp diff --git a/src/requesthandler/RequestHandler.cpp b/src/requesthandler/RequestHandler.cpp index 43fa9b37..9fa967bb 100644 --- a/src/requesthandler/RequestHandler.cpp +++ b/src/requesthandler/RequestHandler.cpp @@ -26,6 +26,9 @@ const std::map RequestHandler::_handlerMap {"GetSourceActive", &RequestHandler::GetSourceActive}, {"GetSourceScreenshot", &RequestHandler::GetSourceScreenshot}, {"SaveSourceScreenshot", &RequestHandler::SaveSourceScreenshot}, + + // Scenes + {"GetSceneList", &RequestHandler::GetSceneList}, }; RequestResult RequestHandler::ProcessRequest(const Request& request) diff --git a/src/requesthandler/RequestHandler.h b/src/requesthandler/RequestHandler.h index 3bfc44dd..1e4488f3 100644 --- a/src/requesthandler/RequestHandler.h +++ b/src/requesthandler/RequestHandler.h @@ -41,5 +41,8 @@ class RequestHandler { RequestResult GetSourceScreenshot(const Request&); RequestResult SaveSourceScreenshot(const Request&); + // Scenes + RequestResult GetSceneList(const Request&); + static const std::map _handlerMap; }; diff --git a/src/requesthandler/RequestHandler_Scenes.cpp b/src/requesthandler/RequestHandler_Scenes.cpp new file mode 100644 index 00000000..936e6fb9 --- /dev/null +++ b/src/requesthandler/RequestHandler_Scenes.cpp @@ -0,0 +1,22 @@ +#include "RequestHandler.h" + +#include "../plugin-macros.generated.h" + +RequestResult RequestHandler::GetSceneList(const Request& request) +{ + json responseData; + + OBSSourceAutoRelease currentProgramScene = obs_frontend_get_current_scene(); + responseData["currentProgramSceneName"] = obs_source_get_name(currentProgramScene); + + + OBSSourceAutoRelease currentPreviewScene = obs_frontend_get_current_preview_scene(); + if (currentPreviewScene) + responseData["currentPreviewSceneName"] = obs_source_get_name(currentPreviewScene); + else + responseData["currentPreviewSceneName"] = nullptr; + + responseData["scenes"] = Utils::Obs::ListHelper::GetSceneList(); + + return RequestResult::Success(responseData); +}