diff --git a/CMakeLists.txt b/CMakeLists.txt index 711111f2..61ec6150 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,10 @@ set(obs-websocket_SOURCES src/eventhandler/EventHandler_Scenes.cpp src/eventhandler/EventHandler_Inputs.cpp src/eventhandler/EventHandler_Transitions.cpp + src/eventhandler/EventHandler_Filters.cpp + src/eventhandler/EventHandler_Outputs.cpp + src/eventhandler/EventHandler_SceneItems.cpp + src/eventhandler/EventHandler_MediaInputs.cpp src/requesthandler/RequestHandler.cpp src/requesthandler/RequestHandler_General.cpp src/requesthandler/rpc/Request.cpp diff --git a/src/eventhandler/EventHandler.cpp b/src/eventhandler/EventHandler.cpp index 45fa79ba..c68f5772 100644 --- a/src/eventhandler/EventHandler.cpp +++ b/src/eventhandler/EventHandler.cpp @@ -172,32 +172,46 @@ void EventHandler::OnFrontendEvent(enum obs_frontend_event event, void *private_ // Outputs case OBS_FRONTEND_EVENT_STREAMING_STARTING: + eventHandler->HandleStreamStateChanged(OBS_WEBSOCKET_OUTPUT_STARTING); break; case OBS_FRONTEND_EVENT_STREAMING_STARTED: + eventHandler->HandleStreamStateChanged(OBS_WEBSOCKET_OUTPUT_STARTED); break; case OBS_FRONTEND_EVENT_STREAMING_STOPPING: + eventHandler->HandleStreamStateChanged(OBS_WEBSOCKET_OUTPUT_STOPPING); break; case OBS_FRONTEND_EVENT_STREAMING_STOPPED: + eventHandler->HandleStreamStateChanged(OBS_WEBSOCKET_OUTPUT_STOPPED); break; case OBS_FRONTEND_EVENT_RECORDING_STARTING: + eventHandler->HandleRecordStateChanged(OBS_WEBSOCKET_OUTPUT_STARTING); break; case OBS_FRONTEND_EVENT_RECORDING_STARTED: + eventHandler->HandleRecordStateChanged(OBS_WEBSOCKET_OUTPUT_STARTED); break; case OBS_FRONTEND_EVENT_RECORDING_STOPPING: + eventHandler->HandleRecordStateChanged(OBS_WEBSOCKET_OUTPUT_STOPPING); break; case OBS_FRONTEND_EVENT_RECORDING_STOPPED: + eventHandler->HandleRecordStateChanged(OBS_WEBSOCKET_OUTPUT_STOPPED); break; case OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTING: + eventHandler->HandleReplayBufferStateChanged(OBS_WEBSOCKET_OUTPUT_STARTING); break; case OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTED: + eventHandler->HandleReplayBufferStateChanged(OBS_WEBSOCKET_OUTPUT_STARTED); break; case OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPING: + eventHandler->HandleReplayBufferStateChanged(OBS_WEBSOCKET_OUTPUT_STOPPING); break; case OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPED: + eventHandler->HandleReplayBufferStateChanged(OBS_WEBSOCKET_OUTPUT_STOPPED); break; case OBS_FRONTEND_EVENT_VIRTUALCAM_STARTED: + eventHandler->HandleVirtualcamStateChanged(OBS_WEBSOCKET_OUTPUT_STARTED); break; case OBS_FRONTEND_EVENT_VIRTUALCAM_STOPPED: + eventHandler->HandleVirtualcamStateChanged(OBS_WEBSOCKET_OUTPUT_STOPPED); break; default: diff --git a/src/eventhandler/EventHandler.h b/src/eventhandler/EventHandler.h index 23712d15..775f6521 100644 --- a/src/eventhandler/EventHandler.h +++ b/src/eventhandler/EventHandler.h @@ -8,6 +8,15 @@ #include "../WebSocketServer.h" #include "types/EventSubscription.h" +enum ObsOutputState { + OBS_WEBSOCKET_OUTPUT_STARTING, + OBS_WEBSOCKET_OUTPUT_STARTED, + OBS_WEBSOCKET_OUTPUT_STOPPING, + OBS_WEBSOCKET_OUTPUT_STOPPED, + OBS_WEBSOCKET_OUTPUT_PAUSED, + OBS_WEBSOCKET_OUTPUT_RESUMED +}; + template T* GetCalldataPointer(const calldata_t *data, const char* name) { void* ptr = nullptr; calldata_get_ptr(data, name, &ptr); @@ -76,4 +85,10 @@ class EventHandler void HandleTransitionCreated(obs_source_t *source); void HandleTransitionRemoved(obs_source_t *source); void HandleTransitionNameChanged(obs_source_t *source, std::string oldTransitionName, std::string transitionName); + + // Outputs + void HandleStreamStateChanged(ObsOutputState state); + void HandleRecordStateChanged(ObsOutputState state); + void HandleReplayBufferStateChanged(ObsOutputState state); + void HandleVirtualcamStateChanged(ObsOutputState state); }; diff --git a/src/eventhandler/EventHandler_Filters.cpp b/src/eventhandler/EventHandler_Filters.cpp new file mode 100644 index 00000000..1f7f02f6 --- /dev/null +++ b/src/eventhandler/EventHandler_Filters.cpp @@ -0,0 +1,3 @@ +#include "EventHandler.h" + +#include "../plugin-macros.generated.h" diff --git a/src/eventhandler/EventHandler_MediaInputs.cpp b/src/eventhandler/EventHandler_MediaInputs.cpp new file mode 100644 index 00000000..1f7f02f6 --- /dev/null +++ b/src/eventhandler/EventHandler_MediaInputs.cpp @@ -0,0 +1,3 @@ +#include "EventHandler.h" + +#include "../plugin-macros.generated.h" diff --git a/src/eventhandler/EventHandler_Outputs.cpp b/src/eventhandler/EventHandler_Outputs.cpp new file mode 100644 index 00000000..8f09b06e --- /dev/null +++ b/src/eventhandler/EventHandler_Outputs.cpp @@ -0,0 +1,64 @@ +#include "EventHandler.h" + +#include "../plugin-macros.generated.h" + +#define CASE(x) case x: return #x; + +std::string GetOutputStateString(ObsOutputState state) { + switch (state) { + default: + CASE(OBS_WEBSOCKET_OUTPUT_STARTING) + CASE(OBS_WEBSOCKET_OUTPUT_STARTED) + CASE(OBS_WEBSOCKET_OUTPUT_STOPPING) + CASE(OBS_WEBSOCKET_OUTPUT_STOPPED) + CASE(OBS_WEBSOCKET_OUTPUT_PAUSED) + CASE(OBS_WEBSOCKET_OUTPUT_RESUMED) + } +} + +bool GetOutputStateActive(ObsOutputState state) { + switch(state) { + case OBS_WEBSOCKET_OUTPUT_STARTED: + case OBS_WEBSOCKET_OUTPUT_RESUMED: + return true; + case OBS_WEBSOCKET_OUTPUT_STARTING: + case OBS_WEBSOCKET_OUTPUT_STOPPING: + case OBS_WEBSOCKET_OUTPUT_STOPPED: + case OBS_WEBSOCKET_OUTPUT_PAUSED: + return false; + default: + return false; + } +} + +void EventHandler::HandleStreamStateChanged(ObsOutputState state) +{ + json eventData; + eventData["outputActive"] = GetOutputStateActive(state); + eventData["outputState"] = GetOutputStateString(state); + _webSocketServer->BroadcastEvent(EventSubscription::Outputs, "StreamStateChanged", eventData); +} + +void EventHandler::HandleRecordStateChanged(ObsOutputState state) +{ + json eventData; + eventData["outputActive"] = GetOutputStateActive(state); + eventData["outputState"] = GetOutputStateString(state); + _webSocketServer->BroadcastEvent(EventSubscription::Outputs, "RecordStateChanged", eventData); +} + +void EventHandler::HandleReplayBufferStateChanged(ObsOutputState state) +{ + json eventData; + eventData["outputActive"] = GetOutputStateActive(state); + eventData["outputState"] = GetOutputStateString(state); + _webSocketServer->BroadcastEvent(EventSubscription::Outputs, "ReplayBufferStateChanged", eventData); +} + +void EventHandler::HandleVirtualcamStateChanged(ObsOutputState state) +{ + json eventData; + eventData["outputActive"] = GetOutputStateActive(state); + eventData["outputState"] = GetOutputStateString(state); + _webSocketServer->BroadcastEvent(EventSubscription::Outputs, "VirtualcamStateChanged", eventData); +} diff --git a/src/eventhandler/EventHandler_SceneItems.cpp b/src/eventhandler/EventHandler_SceneItems.cpp new file mode 100644 index 00000000..1f7f02f6 --- /dev/null +++ b/src/eventhandler/EventHandler_SceneItems.cpp @@ -0,0 +1,3 @@ +#include "EventHandler.h" + +#include "../plugin-macros.generated.h"