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

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