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__ :
|
||||
- **"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__ :
|
||||
- **"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 :
|
||||
- **"name"** (string) : transition name
|
||||
- **"name"** (string, optional) : transition name
|
||||
- **"duration"** (integer, optional) : transition duration in milliseconds
|
||||
|
||||
---
|
||||
|
@ -788,13 +788,19 @@ void WSRequestHandler::HandleGetPreviewScene(WSRequestHandler *owner)
|
||||
|
||||
void WSRequestHandler::HandleSetPreviewScene(WSRequestHandler *owner)
|
||||
{
|
||||
const char* scene_name = obs_data_get_string(owner->_requestData, "scene-name");
|
||||
if (!scene_name)
|
||||
if (!Utils::IsPreviewModeActive())
|
||||
{
|
||||
owner->SendErrorResponse("studio mode not enabled");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!obs_data_has_user_value(owner->_requestData, "scene-name"))
|
||||
{
|
||||
owner->SendErrorResponse("invalid request parameters");
|
||||
return;
|
||||
}
|
||||
|
||||
const char* scene_name = obs_data_get_string(owner->_requestData, "scene-name");
|
||||
Utils::SetPreviewScene(scene_name);
|
||||
|
||||
owner->SendOKResponse();
|
||||
@ -802,28 +808,36 @@ void WSRequestHandler::HandleSetPreviewScene(WSRequestHandler *owner)
|
||||
|
||||
void WSRequestHandler::HandleTransitionToProgram(WSRequestHandler *owner)
|
||||
{
|
||||
obs_data_t* transitionInfo = obs_data_get_obj(owner->_requestData, "with-transition");
|
||||
|
||||
if (transitionInfo)
|
||||
if (!Utils::IsPreviewModeActive())
|
||||
{
|
||||
const char* transitionName = obs_data_get_string(transitionInfo, "name");
|
||||
int transitionDuration = obs_data_get_int(transitionInfo, "duration");
|
||||
owner->SendErrorResponse("studio mode not enabled");
|
||||
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");
|
||||
return;
|
||||
const char* transitionName = obs_data_get_string(transitionInfo, "name");
|
||||
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 (!success)
|
||||
if (obs_data_has_user_value(transitionInfo, "duration"))
|
||||
{
|
||||
owner->SendErrorResponse("unknown error while trying to change current transition");
|
||||
return;
|
||||
}
|
||||
|
||||
if (transitionDuration > 0)
|
||||
int transitionDuration = obs_data_get_int(transitionInfo, "duration");
|
||||
Utils::SetTransitionDuration(transitionDuration);
|
||||
}
|
||||
|
||||
obs_data_release(transitionInfo);
|
||||
}
|
||||
|
||||
Utils::TransitionToProgram();
|
||||
|
Loading…
x
Reference in New Issue
Block a user