Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@ Permissions required: ALL
window.obsstudio.stopVirtualcam()
```

#### Signal the browser source
Permissions required: BASIC
```js
/**
* @param {string} signal - signal name
*/
window.obsstudio.signal(signal)
```

### Register for visibility callbacks

Expand Down
27 changes: 20 additions & 7 deletions browser-app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,26 @@ void BrowserApp::OnBeforeCommandLineProcessing(const CefString &, CefRefPtr<CefC
#endif
}

std::vector<std::string> exposedFunctions = {"getControlLevel", "getCurrentScene", "getStatus",
"startRecording", "stopRecording", "startStreaming",
"stopStreaming", "pauseRecording", "unpauseRecording",
"startReplayBuffer", "stopReplayBuffer", "saveReplayBuffer",
"startVirtualcam", "stopVirtualcam", "getScenes",
"setCurrentScene", "getTransitions", "getCurrentTransition",
"setCurrentTransition"};
std::vector<std::string> exposedFunctions = {"getControlLevel",
"getCurrentScene",
"getStatus",
"startRecording",
"stopRecording",
"startStreaming",
"stopStreaming",
"pauseRecording",
"unpauseRecording",
"startReplayBuffer",
"stopReplayBuffer",
"saveReplayBuffer",
"startVirtualcam",
"stopVirtualcam",
"getScenes",
"setCurrentScene",
"getTransitions",
"getCurrentTransition",
"setCurrentTransition",
"signal"};

void BrowserApp::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame>, CefRefPtr<CefV8Context> context)
{
Expand Down
15 changes: 15 additions & 0 deletions browser-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,21 @@ bool BrowserClient::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefR
case ControlLevel::Basic:
if (name == "saveReplayBuffer") {
obs_frontend_replay_buffer_save();
} else if (name == "signal") {
struct calldata data;
calldata_init(&data);
calldata_set_ptr(&data, "source", bs->source);
if (input_args->GetType(1) == VTYPE_STRING) {
const std::string signal = input_args->GetString(1).ToString();
calldata_set_string(&data, "signal", signal.c_str());
}
signal_handler_t *gsh = obs_get_signal_handler();
if (gsh && !obs_obj_is_private(bs->source))
signal_handler_signal(gsh, "source_browser_signal", &data);
signal_handler_t *sh = obs_source_get_signal_handler(bs->source);
if (sh)
signal_handler_signal(sh, "browser_signal", &data);
calldata_free(&data);
}
[[fallthrough]];
case ControlLevel::ReadUser:
Expand Down
1 change: 1 addition & 0 deletions obs-browser-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ bool obs_module_load(void)
cef_version_info(5), cef_version_info(6), cef_version_info(7), CEF_VERSION);

RegisterBrowserSource();
signal_handler_add(obs_get_signal_handler(), "void source_browser_signal(ptr source, string signal)");
obs_frontend_add_event_callback(handle_obs_frontend_event, nullptr);

#ifdef ENABLE_BROWSER_SHARED_TEXTURE
Expand Down
3 changes: 3 additions & 0 deletions obs-browser-source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ BrowserSource::BrowserSource(obs_data_t *, obs_source_t *source_) : source(sourc
proc_handler_add(ph, "void javascript_event(string eventName, string jsonString)", jsEventFunction,
(void *)this);

signal_handler_t *sh = obs_source_get_signal_handler(source);
signal_handler_add(sh, "void browser_signal(ptr source, string signal)");

/* defer update */
obs_source_update(source, nullptr);

Expand Down