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
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,24 @@ window.obsstudio.getCurrentTransition(function (transition) {
})
```

#### Get source visibility
Permissions required: READ_USER
```js
/**
* @callback VisibilityCallback
* @param {boolean} visibility - True -> visible, False -> hidden
*/

/**
* @param {string} scene - Name of the scene
* @param {string} source - Name of the source
* @param {VisibilityCallback} cb - The callback that receives the current visibility.
*/
window.obsstudio.getSourceVisible(scene, source, function (visibility) {
console.log(visibility)
})
```

#### Save the Replay Buffer
Permissions required: BASIC
```js
Expand Down Expand Up @@ -243,6 +261,17 @@ Permissions required: ADVANCED
window.obsstudio.setCurrentTransition(name)
```

#### Set source visibility
Permissions required: ADVANCED
```js
/**
* @param {string} scene - Name of the scene
* @param {string} source - Name of the source
* @param {boolean} visibility - True -> visible, False -> hidden
*/
window.obsstudio.setSourceVisible(scene, source, visibility)
```

#### Start streaming
Permissions required: ALL
```js
Expand Down
14 changes: 7 additions & 7 deletions browser-app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ 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", "getSourceVisible", "setSourceVisible"};

void BrowserApp::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame>, CefRefPtr<CefV8Context> context)
{
Expand Down
43 changes: 43 additions & 0 deletions browser-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,32 @@ bool BrowserClient::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefR
} else {
obs_frontend_set_current_scene(source);
}
} else if (name == "setSourceVisible") {
const std::string scene_name = input_args->GetString(1).ToString();
const std::string source_name = input_args->GetString(2).ToString();
const std::string visible = input_args->GetBool(3);
OBSSourceAutoRelease *scene = obs_get_source_by_name(scene_name.c_str());
if (!scene) {
blog(LOG_WARNING,
"Browser source '%s' tried to set the visibility of a scene item in scene '%s' which doesn't exist",
obs_source_get_name(bs->source), scene_name.c_str());
break;
}
if (!obs_source_is_scene(scene)) {
blog(LOG_WARNING,
"Browser source '%s' tried to set the visibility of a scene item in scene '%s' which isn't a scene",
obs_source_get_name(bs->source), scene_name.c_str());
break;
}
obs_sceneitem_t *item =
obs_scene_find_source_recursive(obs_scene_from_source(scene), source_name.c_str());
if (!item) {
blog(LOG_WARNING,
"Browser source '%s' tried to set the visibility of scene item '%s' which doesn't exist in scene '%s'",
obs_source_get_name(bs->source), source_name.c_str(), scene_name.c_str());
break;
}
obs_sceneitem_set_visible(item, visible);
} else if (name == "setCurrentTransition") {
const std::string transition_name = input_args->GetString(1).ToString();
obs_frontend_source_list transitions = {};
Expand Down Expand Up @@ -244,6 +270,23 @@ bool BrowserClient::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefR
json = {{"name", name},
{"width", obs_source_get_width(current_scene)},
{"height", obs_source_get_height(current_scene)}};
} else if (name == "getSourceVisible") {
const std::string scene_name = input_args->GetString(1).ToString();
const std::string source_name = input_args->GetString(2).ToString();
OBSSourceAutoRelease *scene = obs_get_source_by_name(scene_name.c_str());

if (!scene)
return false;

if (!obs_source_is_scene(scene))
return false;

obs_sceneitem_t *item =
obs_scene_find_source_recursive(obs_scene_from_source(scene), source_name.c_str());
if (!item)
return false;

json = obs_sceneitem_visible(item);
} else if (name == "getTransitions") {
struct obs_frontend_source_list list = {};
obs_frontend_get_transitions(&list);
Expand Down