Skip to content
Merged
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
10 changes: 8 additions & 2 deletions browser-app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#endif
#endif

#include "include/cef_command_line.h"

#if defined(USE_UI_LOOP) && defined(__APPLE__)
#include "browser-mac.h"
#endif
Expand Down Expand Up @@ -139,6 +141,8 @@ void BrowserApp::OnBeforeCommandLineProcessing(
"enable-media-stream", "1");
}
}
command_line->AppendSwitchWithValue("remote-debugging-port", "9222");
command_line->AppendSwitchWithValue("remote-allow-origins", "http://localhost:9222");
#ifdef __APPLE__
command_line->AppendSwitch("use-mock-keychain");
#endif
Expand All @@ -151,7 +155,7 @@ std::vector<std::string> exposedFunctions = {
"startReplayBuffer", "stopReplayBuffer", "saveReplayBuffer",
"startVirtualcam", "stopVirtualcam", "getScenes",
"setCurrentScene", "getTransitions", "getCurrentTransition",
"setCurrentTransition"};
"setCurrentTransition","messageFromApp", "messageToApp"};

void BrowserApp::OnContextCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame>,
Expand Down Expand Up @@ -411,8 +415,10 @@ bool BrowserApp::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,

CefRefPtr<CefV8Value> dispatchEvent =
globalObj->GetValue("dispatchEvent");
dispatchEvent->ExecuteFunction(nullptr, arguments);

if (dispatchEvent && dispatchEvent->IsFunction()) {
dispatchEvent->ExecuteFunction(nullptr, arguments);
}
context->Exit();
}

Expand Down
28 changes: 27 additions & 1 deletion browser-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ bool BrowserClient::OnProcessMessageReceived(
const std::string &name = message->GetName();
CefRefPtr<CefListValue> input_args = message->GetArgumentList();
nlohmann::json json;

blog(LOG_INFO, "[BrowserMessage] OnProcessMessageReceived: %s", name.c_str());
if (!valid()) {
return false;
}
Expand Down Expand Up @@ -259,6 +259,32 @@ bool BrowserClient::OnProcessMessageReceived(
}
}
#else
switch (webpage_control_level) {
case ControlLevel::All:

[[fallthrough]];
case ControlLevel::Advanced:

[[fallthrough]];
case ControlLevel::Basic:

[[fallthrough]];
case ControlLevel::ReadUser:

[[fallthrough]];
case ControlLevel::ReadObs:

[[fallthrough]];
case ControlLevel::None:
if (name == "getControlLevel") {
json = (int)webpage_control_level;
} else if (name == "messageToApp") {
const std::string message = input_args->GetString(1).ToString();
blog(LOG_INFO, "[BrowserMessage] messageToApp called: arguments %zu, arg2 %s", input_args->GetSize(), message.c_str());
std::lock_guard<std::mutex> lock(bs->messagesToAppMutex);
bs->messagesToApp.push_back(message);
}
}
UNUSED_PARAMETER(name);
#endif

Expand Down
28 changes: 28 additions & 0 deletions obs-browser-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,28 @@ static obs_missing_files_t *browser_source_missingfiles(void *data)
return files;
}

static obs_data_array_t *browser_source_get_messages(void *data)
{
BrowserSource *bs = static_cast<BrowserSource *>(data);
obs_data_array_t *messages = nullptr;

if (bs) {
std::lock_guard<std::mutex> lock(bs->messagesToAppMutex);
if (!bs->messagesToApp.empty()) {
messages = obs_data_array_create();
for (const auto &message : bs->messagesToApp) {
obs_data_t *msg_data = obs_data_create();
obs_data_set_string(msg_data, "message", message.c_str());
obs_data_array_push_back(messages, msg_data);
obs_data_release(msg_data);
}
bs->messagesToApp.clear();
}
}

return messages;
}

static CefRefPtr<BrowserApp> app;

static void BrowserInit(obs_data_t *settings_obs)
Expand Down Expand Up @@ -632,6 +654,12 @@ void RegisterBrowserSource()
bs->Refresh();
bs->SetActive(true);
};
info.message = [](void *data, obs_data_t *settings) {
BrowserSource *bs = static_cast<BrowserSource *>(data);
const char *message = obs_data_get_string(settings, "message");
bs->MessageToBrowser(message);
};
info.get_messages = browser_source_get_messages;
info.deactivate = [](void *data) {
static_cast<BrowserSource *>(data)->SetActive(false);
};
Expand Down
14 changes: 13 additions & 1 deletion obs-browser-source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void BrowserSource::Destroy()

void BrowserSource::ExecuteOnBrowser(BrowserFunc func, bool async)
{
if (!async) {
if (!async) {
#ifdef ENABLE_BROWSER_QT_LOOP
if (QThread::currentThread() == qApp->thread()) {
if (!!cefBrowser)
Expand Down Expand Up @@ -477,6 +477,18 @@ void BrowserSource::SetActive(bool active)
DispatchJSEvent("obsSourceActiveChanged", json.dump(), this);
}

void BrowserSource::MessageToBrowser(const char* message)
{
if (destroying)
return;

blog(LOG_INFO, "[BrowserMessage] MessageToBrowser: %s", message);

nlohmann::json json;
json["message"] = message;
DispatchJSEvent("messageFromApp", json.dump(), this);
}

void BrowserSource::Refresh()
{
ExecuteOnBrowser(
Expand Down
3 changes: 3 additions & 0 deletions obs-browser-source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ struct BrowserSource {
bool create_browser = false;
std::recursive_mutex lockBrowser;
CefRefPtr<CefBrowser> cefBrowser;
std::vector<std::string> messagesToApp;
std::mutex messagesToAppMutex;

std::string url;
std::string css;
Expand Down Expand Up @@ -150,6 +152,7 @@ struct BrowserSource {
void SendKeyClick(const struct obs_key_event *event, bool key_up);
void SetShowing(bool showing);
void SetActive(bool active);
void MessageToBrowser(const char* message);
void Refresh();

#if defined(BROWSER_EXTERNAL_BEGIN_FRAME_ENABLED) && \
Expand Down
Loading