RequestHandler: Add RemoveScene

This commit is contained in:
tt2468 2021-06-15 23:57:48 -07:00
parent 9088cb4db8
commit efdea72987
3 changed files with 24 additions and 0 deletions

View File

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

View File

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

View File

@ -144,3 +144,25 @@ RequestResult RequestHandler::CreateScene(const Request& request)
return RequestResult::Success();
}
RequestResult RequestHandler::RemoveScene(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::SceneNotFound);
if (obs_source_get_type(scene) != OBS_SOURCE_TYPE_SCENE)
return RequestResult::Error(RequestStatus::InvalidSourceType, "The specified source is not a scene.");
obs_source_remove(scene);
return RequestResult::Success();
}