Skip to content

Commit

Permalink
Fix handling frontend JS events
Browse files Browse the repository at this point in the history
When handling frontend events, DispatchJSEvent expects JSON passed as a
std::string. An empty string will cause the event to never be
dispatched. An empty nlohmann::json object converted to a std::string is
represented by the string "null". Passing this exact string as the JSON
string to DispatchJSEvent makes the events work. This is probably
because an empty unquoted string by itself is not valid JSON. Two
double-quotes with nothing inside them or the unquoted string "null" are
considered valid JSON.
  • Loading branch information
RytoEX committed Nov 17, 2023
1 parent 9143687 commit ec68d7d
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions obs-browser-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,55 +549,55 @@ static void handle_obs_frontend_event(enum obs_frontend_event event, void *)
{
switch (event) {
case OBS_FRONTEND_EVENT_STREAMING_STARTING:
DispatchJSEvent("obsStreamingStarting", "");
DispatchJSEvent("obsStreamingStarting", "null");
break;
case OBS_FRONTEND_EVENT_STREAMING_STARTED:
DispatchJSEvent("obsStreamingStarted", "");
DispatchJSEvent("obsStreamingStarted", "null");
break;
case OBS_FRONTEND_EVENT_STREAMING_STOPPING:
DispatchJSEvent("obsStreamingStopping", "");
DispatchJSEvent("obsStreamingStopping", "null");
break;
case OBS_FRONTEND_EVENT_STREAMING_STOPPED:
DispatchJSEvent("obsStreamingStopped", "");
DispatchJSEvent("obsStreamingStopped", "null");
break;
case OBS_FRONTEND_EVENT_RECORDING_STARTING:
DispatchJSEvent("obsRecordingStarting", "");
DispatchJSEvent("obsRecordingStarting", "null");
break;
case OBS_FRONTEND_EVENT_RECORDING_STARTED:
DispatchJSEvent("obsRecordingStarted", "");
DispatchJSEvent("obsRecordingStarted", "null");
break;
case OBS_FRONTEND_EVENT_RECORDING_PAUSED:
DispatchJSEvent("obsRecordingPaused", "");
DispatchJSEvent("obsRecordingPaused", "null");
break;
case OBS_FRONTEND_EVENT_RECORDING_UNPAUSED:
DispatchJSEvent("obsRecordingUnpaused", "");
DispatchJSEvent("obsRecordingUnpaused", "null");
break;
case OBS_FRONTEND_EVENT_RECORDING_STOPPING:
DispatchJSEvent("obsRecordingStopping", "");
DispatchJSEvent("obsRecordingStopping", "null");
break;
case OBS_FRONTEND_EVENT_RECORDING_STOPPED:
DispatchJSEvent("obsRecordingStopped", "");
DispatchJSEvent("obsRecordingStopped", "null");
break;
case OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTING:
DispatchJSEvent("obsReplaybufferStarting", "");
DispatchJSEvent("obsReplaybufferStarting", "null");
break;
case OBS_FRONTEND_EVENT_REPLAY_BUFFER_STARTED:
DispatchJSEvent("obsReplaybufferStarted", "");
DispatchJSEvent("obsReplaybufferStarted", "null");
break;
case OBS_FRONTEND_EVENT_REPLAY_BUFFER_SAVED:
DispatchJSEvent("obsReplaybufferSaved", "");
DispatchJSEvent("obsReplaybufferSaved", "null");
break;
case OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPING:
DispatchJSEvent("obsReplaybufferStopping", "");
DispatchJSEvent("obsReplaybufferStopping", "null");
break;
case OBS_FRONTEND_EVENT_REPLAY_BUFFER_STOPPED:
DispatchJSEvent("obsReplaybufferStopped", "");
DispatchJSEvent("obsReplaybufferStopped", "null");
break;
case OBS_FRONTEND_EVENT_VIRTUALCAM_STARTED:
DispatchJSEvent("obsVirtualcamStarted", "");
DispatchJSEvent("obsVirtualcamStarted", "null");
break;
case OBS_FRONTEND_EVENT_VIRTUALCAM_STOPPED:
DispatchJSEvent("obsVirtualcamStopped", "");
DispatchJSEvent("obsVirtualcamStopped", "null");
break;
case OBS_FRONTEND_EVENT_SCENE_CHANGED: {
OBSSourceAutoRelease source = obs_frontend_get_current_scene();
Expand Down Expand Up @@ -663,7 +663,7 @@ static void handle_obs_frontend_event(enum obs_frontend_event event, void *)
break;
}
case OBS_FRONTEND_EVENT_EXIT:
DispatchJSEvent("obsExit", "");
DispatchJSEvent("obsExit", "null");
break;
default:;
}
Expand Down

0 comments on commit ec68d7d

Please sign in to comment.