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__ :
- **"source"** (string) : name of the source in the currently active scene.
- **"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.

View File

@ -41,7 +41,7 @@ WSRequestHandler::WSRequestHandler(QWebSocket *client) :
messageMap["SetSceneItemRender"] = WSRequestHandler::HandleSetSourceRender;
messageMap["SetSceneItemPosition"] = WSRequestHandler::HandleSetSceneItemPosition;
messageMap["SetSceneItemTransform"] = WSRequestHandler::HandleSetSceneItemTransform;
messageMap["GetStreamingStatus"] = WSRequestHandler::HandleGetStreamingStatus;
messageMap["StartStopStreaming"] = WSRequestHandler::HandleStartStopStreaming;
messageMap["StartStopRecording"] = WSRequestHandler::HandleStartStopRecording;
@ -125,7 +125,7 @@ void WSRequestHandler::SendOKResponse(obs_data_t *additionalFields)
obs_data_set_string(response, "status", "ok");
obs_data_set_string(response, "message-id", _messageId);
if (additionalFields != NULL)
if (additionalFields != NULL)
{
obs_data_apply(response, additionalFields);
}
@ -169,7 +169,7 @@ void WSRequestHandler::HandleGetAuthRequired(WSRequestHandler *owner)
obs_data_t *data = obs_data_create();
obs_data_set_bool(data, "authRequired", authRequired);
if (authRequired)
if (authRequired)
{
obs_data_set_string(data, "challenge", Config::Current()->SessionChallenge);
obs_data_set_string(data, "salt", Config::Current()->Salt);
@ -183,18 +183,18 @@ void WSRequestHandler::HandleGetAuthRequired(WSRequestHandler *owner)
void WSRequestHandler::HandleAuthenticate(WSRequestHandler *owner)
{
const char *auth = obs_data_get_string(owner->_requestData, "auth");
if (!auth || strlen(auth) < 1)
if (!auth || strlen(auth) < 1)
{
owner->SendErrorResponse("auth not specified!");
return;
}
if ((owner->_client->property(PROP_AUTHENTICATED).toBool() == false) && Config::Current()->CheckAuth(auth))
if ((owner->_client->property(PROP_AUTHENTICATED).toBool() == false) && Config::Current()->CheckAuth(auth))
{
owner->_client->setProperty(PROP_AUTHENTICATED, true);
owner->SendOKResponse();
}
else
else
{
owner->SendErrorResponse("Authentication Failed.");
}
@ -262,9 +262,21 @@ void WSRequestHandler::HandleSetSourceRender(WSRequestHandler *owner)
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)
{
obs_sceneitem_set_visible(sceneItem, isVisible);
@ -276,7 +288,7 @@ void WSRequestHandler::HandleSetSourceRender(WSRequestHandler *owner)
owner->SendErrorResponse("specified scene item doesn't exist");
}
obs_source_release(currentScene);
obs_source_release(scene);
}
void WSRequestHandler::HandleGetStreamingStatus(WSRequestHandler *owner)
@ -539,7 +551,7 @@ void WSRequestHandler::HandleSetSceneItemTransform(WSRequestHandler *owner)
void WSRequestHandler::HandleSetCurrentSceneCollection(WSRequestHandler *owner)
{
const char* scene_collection = obs_data_get_string(owner->_requestData, "sc-name");
if (scene_collection)
{
// TODO : Check if profile exists
@ -617,4 +629,4 @@ void WSRequestHandler::HandleListProfiles(WSRequestHandler *owner)
void WSRequestHandler::ErrNotImplemented(WSRequestHandler *owner)
{
owner->SendErrorResponse("not implemented");
}
}