RequestHandler: More transition requests

This commit is contained in:
tt2468 2021-12-23 01:07:27 -08:00
parent 5cbf439f55
commit 14238027cc
3 changed files with 73 additions and 0 deletions

View File

@ -88,6 +88,9 @@ const std::map<std::string, RequestMethodHandler> RequestHandler::_handlerMap
// Transitions
{"GetTransitionKindList", &RequestHandler::GetTransitionKindList},
{"GetSceneTransitionList", &RequestHandler::GetSceneTransitionList},
{"GetCurrentSceneTransition", &RequestHandler::GetCurrentSceneTransition},
{"SetCurrentSceneTransition", &RequestHandler::SetCurrentSceneTransition},
// Scene Items
{"GetSceneItemList", &RequestHandler::GetSceneItemList},

View File

@ -110,6 +110,9 @@ class RequestHandler {
// Transitions
RequestResult GetTransitionKindList(const Request&);
RequestResult GetSceneTransitionList(const Request&);
RequestResult GetCurrentSceneTransition(const Request&);
RequestResult SetCurrentSceneTransition(const Request&);
// Scene Items
RequestResult GetSceneItemList(const Request&);

View File

@ -25,3 +25,70 @@ RequestResult RequestHandler::GetTransitionKindList(const Request&)
responseData["transitionKinds"] = Utils::Obs::ArrayHelper::GetTransitionKindList();
return RequestResult::Success(responseData);
}
RequestResult RequestHandler::GetSceneTransitionList(const Request&)
{
json responseData;
OBSSourceAutoRelease transition = obs_frontend_get_current_transition();
if (transition) {
responseData["currentSceneTransitionName"] = obs_source_get_name(transition);
responseData["currentSceneTransitionKind"] = obs_source_get_id(transition);
} else {
responseData["currentSceneTransitionName"] = nullptr;
responseData["currentSceneTransitionKind"] = nullptr;
}
responseData["transitions"] = Utils::Obs::ArrayHelper::GetSceneTransitionList();
return RequestResult::Success(responseData);
}
RequestResult RequestHandler::GetCurrentSceneTransition(const Request&)
{
OBSSourceAutoRelease transition = obs_frontend_get_current_transition();
if (!transition)
return RequestResult::Error(RequestStatus::InvalidResourceState, "OBS does not currently have a scene transition set."); // This should not happen!
json responseData;
responseData["transitionName"] = obs_source_get_name(transition);
responseData["transitionKind"] = obs_source_get_id(transition);
if (obs_transition_fixed(transition)) {
responseData["transitionFixed"] = true;
responseData["transitionDuration"] = nullptr;
} else {
responseData["transitionFixed"] = false;
responseData["transitionDuration"] = obs_frontend_get_transition_duration();
}
if (obs_source_configurable(transition)) {
responseData["transitionConfigurable"] = true;
OBSDataAutoRelease transitionSettings = obs_source_get_settings(transition);
responseData["transitionSettings"] = Utils::Json::ObsDataToJson(transitionSettings);
} else {
responseData["transitionConfigurable"] = false;
responseData["transitionSettings"] = nullptr;
}
return RequestResult::Success(responseData);
}
// Transition names being unique are a UI concept and are not enforced by libobs
RequestResult RequestHandler::SetCurrentSceneTransition(const Request& request)
{
RequestStatus::RequestStatus statusCode;
std::string comment;
if (!request.ValidateString("transitionName", statusCode, comment))
return RequestResult::Error(statusCode, comment);
std::string transitionName = request.RequestData["transitionName"];
OBSSourceAutoRelease transition = Utils::Obs::SearchHelper::GetSceneTransitionByName(transitionName);
if (!transition)
return RequestResult::Error(RequestStatus::ResourceNotFound, "No scene transition was found by that name.");
obs_frontend_set_current_transition(transition);
return RequestResult::Success();
}