obs-websocket/src/eventhandler/EventHandler_Outputs.cpp
tt2468 7e1e1bc33c Base: Large plugin refactor
- Merge WebSocketProtocol into WebSocketServer
  - Having them separated was not doing anything productive
- Request: Move SessionPtr to RequestHandler
  - Less copying to do for batch requests
- Fully modularize EventHandler
  - Make BroadcastEvent a stored callback that WebSocketServer sets
- Return early on high volume events to avoid unnecessary compute
  - These events will only generate a json object when it is actually
needed
2021-09-04 10:04:00 -07:00

71 lines
2.1 KiB
C++

#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);
BroadcastEvent(EventSubscription::Outputs, "StreamStateChanged", eventData);
}
void EventHandler::HandleRecordStateChanged(ObsOutputState state)
{
json eventData;
eventData["outputActive"] = GetOutputStateActive(state);
eventData["outputState"] = GetOutputStateString(state);
BroadcastEvent(EventSubscription::Outputs, "RecordStateChanged", eventData);
}
void EventHandler::HandleReplayBufferStateChanged(ObsOutputState state)
{
json eventData;
eventData["outputActive"] = GetOutputStateActive(state);
eventData["outputState"] = GetOutputStateString(state);
BroadcastEvent(EventSubscription::Outputs, "ReplayBufferStateChanged", eventData);
}
void EventHandler::HandleVirtualcamStateChanged(ObsOutputState state)
{
json eventData;
eventData["outputActive"] = GetOutputStateActive(state);
eventData["outputState"] = GetOutputStateString(state);
BroadcastEvent(EventSubscription::Outputs, "VirtualcamStateChanged", eventData);
}
void EventHandler::HandleReplayBufferSaved()
{
json eventData;
eventData["savedReplayPath"] = Utils::Obs::StringHelper::GetLastReplayBufferFilePath();
BroadcastEvent(EventSubscription::Outputs, "ReplayBufferSaved", eventData);
}