mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
Better param checks for Studio Mode request types
This commit is contained in:
parent
e241518f8d
commit
ed4526751e
@ -377,7 +377,7 @@ Studio Mode only. Sets the specified scene as the Previewed scene in Studio Mode
|
|||||||
__Request fields__ :
|
__Request fields__ :
|
||||||
- **"scene-name"** (string) : name of the scene to selected as the preview of Studio Mode
|
- **"scene-name"** (string) : name of the scene to selected as the preview of Studio Mode
|
||||||
|
|
||||||
__Response__ : OK if specified scene exists, error otherwise.
|
__Response__ : OK if Studio Mode is enabled and specified scene exists, error otherwise.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -387,10 +387,10 @@ Studio Mode only. Transitions the currently previewed scene to Program (main out
|
|||||||
__Request fields__ :
|
__Request fields__ :
|
||||||
- **"with-transition" (object, optional) : if specified, use this transition when switching from preview to program. This will change the current transition in the frontend to this one.
|
- **"with-transition" (object, optional) : if specified, use this transition when switching from preview to program. This will change the current transition in the frontend to this one.
|
||||||
|
|
||||||
__Response__ : always OK. No additional fields
|
__Response__ : OK if studio mode is enabled and optional transition exists, error otherwise.
|
||||||
|
|
||||||
An object passed as `"with-transition"` in a request must have the following fields :
|
An object passed as `"with-transition"` in a request must have the following fields :
|
||||||
- **"name"** (string) : transition name
|
- **"name"** (string, optional) : transition name
|
||||||
- **"duration"** (integer, optional) : transition duration in milliseconds
|
- **"duration"** (integer, optional) : transition duration in milliseconds
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -788,13 +788,19 @@ void WSRequestHandler::HandleGetPreviewScene(WSRequestHandler *owner)
|
|||||||
|
|
||||||
void WSRequestHandler::HandleSetPreviewScene(WSRequestHandler *owner)
|
void WSRequestHandler::HandleSetPreviewScene(WSRequestHandler *owner)
|
||||||
{
|
{
|
||||||
const char* scene_name = obs_data_get_string(owner->_requestData, "scene-name");
|
if (!Utils::IsPreviewModeActive())
|
||||||
if (!scene_name)
|
{
|
||||||
|
owner->SendErrorResponse("studio mode not enabled");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!obs_data_has_user_value(owner->_requestData, "scene-name"))
|
||||||
{
|
{
|
||||||
owner->SendErrorResponse("invalid request parameters");
|
owner->SendErrorResponse("invalid request parameters");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* scene_name = obs_data_get_string(owner->_requestData, "scene-name");
|
||||||
Utils::SetPreviewScene(scene_name);
|
Utils::SetPreviewScene(scene_name);
|
||||||
|
|
||||||
owner->SendOKResponse();
|
owner->SendOKResponse();
|
||||||
@ -802,28 +808,36 @@ void WSRequestHandler::HandleSetPreviewScene(WSRequestHandler *owner)
|
|||||||
|
|
||||||
void WSRequestHandler::HandleTransitionToProgram(WSRequestHandler *owner)
|
void WSRequestHandler::HandleTransitionToProgram(WSRequestHandler *owner)
|
||||||
{
|
{
|
||||||
obs_data_t* transitionInfo = obs_data_get_obj(owner->_requestData, "with-transition");
|
if (!Utils::IsPreviewModeActive())
|
||||||
|
|
||||||
if (transitionInfo)
|
|
||||||
{
|
{
|
||||||
const char* transitionName = obs_data_get_string(transitionInfo, "name");
|
owner->SendErrorResponse("studio mode not enabled");
|
||||||
int transitionDuration = obs_data_get_int(transitionInfo, "duration");
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!transitionName)
|
if (obs_data_has_user_value(owner->_requestData, "with-transition"))
|
||||||
|
{
|
||||||
|
obs_data_t* transitionInfo = obs_data_get_obj(owner->_requestData, "with-transition");
|
||||||
|
|
||||||
|
if (obs_data_has_user_value(transitionInfo, "name"))
|
||||||
{
|
{
|
||||||
owner->SendErrorResponse("specified transition doesn't exist");
|
const char* transitionName = obs_data_get_string(transitionInfo, "name");
|
||||||
return;
|
bool success = Utils::SetTransitionByName(transitionName);
|
||||||
|
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
owner->SendErrorResponse("specified transition doesn't exist");
|
||||||
|
obs_data_release(transitionInfo);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success = Utils::SetTransitionByName(transitionName);
|
if (obs_data_has_user_value(transitionInfo, "duration"))
|
||||||
if (!success)
|
|
||||||
{
|
{
|
||||||
owner->SendErrorResponse("unknown error while trying to change current transition");
|
int transitionDuration = obs_data_get_int(transitionInfo, "duration");
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (transitionDuration > 0)
|
|
||||||
Utils::SetTransitionDuration(transitionDuration);
|
Utils::SetTransitionDuration(transitionDuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
obs_data_release(transitionInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::TransitionToProgram();
|
Utils::TransitionToProgram();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user