Skip to content

Commit

Permalink
Add support for more events
Browse files Browse the repository at this point in the history
This change adds support for obsSceneListChanged, obsTransitionChanged,
obsTransitionListChanged events. The event arguments match the signatures
of the corresponding getters.

Closes #363
  • Loading branch information
kevmo314 authored and Lain-B committed Nov 7, 2023
1 parent e397df5 commit 0674786
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ window.addEventListener('obsSceneChanged', function(event) {
Descriptions for these events can be [found here](https://obsproject.com/docs/reference-frontend-api.html?highlight=paused#c.obs_frontend_event).

* obsSceneChanged
* obsSceneListChanged
* obsTransitionChanged
* obsTransitionListChanged
* obsSourceVisibleChanged
* obsSourceActiveChanged
* obsStreamingStarting
Expand Down
43 changes: 43 additions & 0 deletions obs-browser-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,49 @@ static void handle_obs_frontend_event(enum obs_frontend_event event, void *)
DispatchJSEvent("obsSceneChanged", json.dump());
break;
}
case OBS_FRONTEND_EVENT_SCENE_LIST_CHANGED: {
struct obs_frontend_source_list list = {};
obs_frontend_get_scenes(&list);
std::vector<const char *> scenes_vector;
for (size_t i = 0; i < list.sources.num; i++) {
obs_source_t *source = list.sources.array[i];
scenes_vector.push_back(obs_source_get_name(source));
}
nlohmann::json json = scenes_vector;
obs_frontend_source_list_free(&list);

DispatchJSEvent("obsSceneListChanged", json.dump());
break;
}
case OBS_FRONTEND_EVENT_TRANSITION_CHANGED: {
OBSSourceAutoRelease source =
obs_frontend_get_current_transition();

if (!source)
break;

const char *name = obs_source_get_name(source);
if (!name)
break;

DispatchJSEvent("obsTransitionChanged", name);
break;
}
case OBS_FRONTEND_EVENT_TRANSITION_LIST_CHANGED: {
struct obs_frontend_source_list list = {};
obs_frontend_get_transitions(&list);
std::vector<const char *> transitions_vector;
for (size_t i = 0; i < list.sources.num; i++) {
obs_source_t *source = list.sources.array[i];
transitions_vector.push_back(
obs_source_get_name(source));
}
nlohmann::json json = transitions_vector;
obs_frontend_source_list_free(&list);

DispatchJSEvent("obsTransitionListChanged", json.dump());
break;
}
case OBS_FRONTEND_EVENT_EXIT:
DispatchJSEvent("obsExit", "");
break;
Expand Down

0 comments on commit 0674786

Please sign in to comment.