RequestHandler: Add more scene requests

This commit is contained in:
tt2468 2021-06-15 00:21:57 -07:00
parent c5af073780
commit b95a2e648f
3 changed files with 55 additions and 0 deletions

View File

@ -33,6 +33,8 @@ const std::map<std::string, RequestMethodHandler> RequestHandler::_handlerMap
{"SetCurrentProgramScene", &RequestHandler::SetCurrentProgramScene},
{"GetCurrentPreviewScene", &RequestHandler::GetCurrentPreviewScene},
{"SetCurrentPreviewScene", &RequestHandler::SetCurrentPreviewScene},
{"SetSceneName", &RequestHandler::SetSceneName},
{"CreateScene", &RequestHandler::CreateScene},
};
RequestResult RequestHandler::ProcessRequest(const Request& request)

View File

@ -47,6 +47,8 @@ class RequestHandler {
RequestResult SetCurrentProgramScene(const Request&);
RequestResult GetCurrentPreviewScene(const Request&);
RequestResult SetCurrentPreviewScene(const Request&);
RequestResult SetSceneName(const Request&);
RequestResult CreateScene(const Request&);
static const std::map<std::string, RequestMethodHandler> _handlerMap;
};

View File

@ -93,3 +93,54 @@ RequestResult RequestHandler::SetCurrentPreviewScene(const Request& request)
return RequestResult::Success();
}
RequestResult RequestHandler::SetSceneName(const Request& request)
{
RequestStatus::RequestStatus statusCode;
std::string comment;
if (!request.ValidateString("sceneName", statusCode, comment)) {
return RequestResult::Error(statusCode, comment);
}
if (!request.ValidateString("newSceneName", statusCode, comment)) {
return RequestResult::Error(statusCode, comment);
}
std::string sceneName = request.RequestData["sceneName"];
std::string newSceneName = request.RequestData["newSceneName"];
OBSSourceAutoRelease scene = obs_get_source_by_name(sceneName.c_str());
if (!scene)
return RequestResult::Error(RequestStatus::SceneNotFound);
if (obs_source_get_type(scene) != OBS_SOURCE_TYPE_SCENE)
return RequestResult::Error(RequestStatus::InvalidSourceType, "The specified source is not a scene.");
OBSSourceAutoRelease existingSource = obs_get_source_by_name(newSceneName.c_str());
if (existingSource)
return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that new scene name.");
obs_source_set_name(scene, newSceneName.c_str());
return RequestResult::Success();
}
RequestResult RequestHandler::CreateScene(const Request& request)
{
RequestStatus::RequestStatus statusCode;
std::string comment;
if (!request.ValidateString("sceneName", statusCode, comment)) {
return RequestResult::Error(statusCode, comment);
}
std::string sceneName = request.RequestData["sceneName"];
OBSSourceAutoRelease scene = obs_get_source_by_name(sceneName.c_str());
if (scene)
return RequestResult::Error(RequestStatus::SourceAlreadyExists, "A source already exists by that scene name.");
obs_scene_t *createdScene = obs_scene_create(sceneName.c_str());
obs_scene_release(createdScene);
return RequestResult::Success();
}