Merge pull request #45 from mikhailswift/toggle_source_on_specified_scene

Toggle source on specified scene
This commit is contained in:
Stéphane L
2017-02-26 23:24:02 +01:00
committed by GitHub
2 changed files with 24 additions and 11 deletions

View File

@ -273,6 +273,7 @@ Show or hide a specific source in the current scene.
__Request fields__ : __Request fields__ :
- **"source"** (string) : name of the source in the currently active scene. - **"source"** (string) : name of the source in the currently active scene.
- **"render"** (bool) : desired visibility - **"render"** (bool) : desired visibility
- **"scene-name"** (string; optional) : name of the scene the source belongs to. defaults to current scene.
__Response__ : OK if source exists in the current scene, error otherwise. __Response__ : OK if source exists in the current scene, error otherwise.

View File

@ -262,9 +262,21 @@ void WSRequestHandler::HandleSetSourceRender(WSRequestHandler *owner)
return; return;
} }
obs_source_t* currentScene = obs_frontend_get_current_scene(); obs_source_t* scene;
const char *sceneName = obs_data_get_string(owner->_requestData, "scene-name");
if (!sceneName || !strlen(sceneName)) {
scene = obs_frontend_get_current_scene();
}
else {
scene = obs_get_source_by_name(sceneName);
}
obs_sceneitem_t *sceneItem = Utils::GetSceneItemFromName(currentScene, itemName); if (scene == NULL) {
owner->SendErrorResponse("requested scene doesn't exist");
return;
}
obs_sceneitem_t *sceneItem = Utils::GetSceneItemFromName(scene, itemName);
if (sceneItem != NULL) if (sceneItem != NULL)
{ {
obs_sceneitem_set_visible(sceneItem, isVisible); obs_sceneitem_set_visible(sceneItem, isVisible);
@ -276,7 +288,7 @@ void WSRequestHandler::HandleSetSourceRender(WSRequestHandler *owner)
owner->SendErrorResponse("specified scene item doesn't exist"); owner->SendErrorResponse("specified scene item doesn't exist");
} }
obs_source_release(currentScene); obs_source_release(scene);
} }
void WSRequestHandler::HandleGetStreamingStatus(WSRequestHandler *owner) void WSRequestHandler::HandleGetStreamingStatus(WSRequestHandler *owner)