handler: return obs_data_t objects

This commit is contained in:
Stéphane L
2019-01-01 17:54:29 +01:00
parent e9b43b9b2a
commit 2d973e0b90
14 changed files with 187 additions and 193 deletions

View File

@ -24,7 +24,7 @@
#include "WSRequestHandler.h" #include "WSRequestHandler.h"
QHash<QString, std::string(*)(WSRequestHandler*)> WSRequestHandler::messageMap { QHash<QString, HandlerResponse(*)(WSRequestHandler*)> WSRequestHandler::messageMap {
{ "GetVersion", WSRequestHandler::HandleGetVersion }, { "GetVersion", WSRequestHandler::HandleGetVersion },
{ "GetAuthRequired", WSRequestHandler::HandleGetAuthRequired }, { "GetAuthRequired", WSRequestHandler::HandleGetAuthRequired },
{ "Authenticate", WSRequestHandler::HandleAuthenticate }, { "Authenticate", WSRequestHandler::HandleAuthenticate },
@ -136,7 +136,7 @@ WSRequestHandler::WSRequestHandler(QVariantHash& connProperties) :
{ {
} }
std::string WSRequestHandler::processIncomingMessage(std::string& textMessage) { obs_data_t* WSRequestHandler::processIncomingMessage(std::string& textMessage) {
std::string msgContainer(textMessage); std::string msgContainer(textMessage);
const char* msg = msgContainer.c_str(); const char* msg = msgContainer.c_str();
@ -164,7 +164,7 @@ std::string WSRequestHandler::processIncomingMessage(std::string& textMessage) {
return SendErrorResponse("Not Authenticated"); return SendErrorResponse("Not Authenticated");
} }
std::string (*handlerFunc)(WSRequestHandler*) = (messageMap[_requestType]); HandlerResponse (*handlerFunc)(WSRequestHandler*) = (messageMap[_requestType]);
if (!handlerFunc) { if (!handlerFunc) {
return SendErrorResponse("invalid request type"); return SendErrorResponse("invalid request type");
} }
@ -175,45 +175,31 @@ std::string WSRequestHandler::processIncomingMessage(std::string& textMessage) {
WSRequestHandler::~WSRequestHandler() { WSRequestHandler::~WSRequestHandler() {
} }
std::string WSRequestHandler::SendOKResponse(obs_data_t* additionalFields) { HandlerResponse WSRequestHandler::SendOKResponse(obs_data_t* additionalFields) {
OBSDataAutoRelease response = obs_data_create(); return SendResponse("ok", additionalFields);
obs_data_set_string(response, "status", "ok");
obs_data_set_string(response, "message-id", _messageId);
if (additionalFields)
obs_data_apply(response, additionalFields);
return SendResponse(response);
} }
std::string WSRequestHandler::SendErrorResponse(const char* errorMessage) { HandlerResponse WSRequestHandler::SendErrorResponse(const char* errorMessage) {
OBSDataAutoRelease response = obs_data_create(); OBSDataAutoRelease fields = obs_data_create();
obs_data_set_string(response, "status", "error"); obs_data_set_string(fields, "error", errorMessage);
obs_data_set_string(response, "error", errorMessage);
obs_data_set_string(response, "message-id", _messageId);
return SendResponse(response); return SendResponse("error", fields);
} }
std::string WSRequestHandler::SendErrorResponse(obs_data_t* additionalFields) { HandlerResponse WSRequestHandler::SendErrorResponse(obs_data_t* additionalFields) {
OBSDataAutoRelease response = obs_data_create(); return SendResponse("error", additionalFields);
obs_data_set_string(response, "status", "error");
obs_data_set_string(response, "message-id", _messageId);
if (additionalFields)
obs_data_set_obj(response, "error", additionalFields);
return SendResponse(response);
} }
std::string WSRequestHandler::SendResponse(obs_data_t* response) { HandlerResponse WSRequestHandler::SendResponse(const char* status, obs_data_t* fields) {
std::string responseStr = obs_data_get_json(response); obs_data_t* response = obs_data_create();
obs_data_set_string(response, "message-id", _messageId);
obs_data_set_string(response, "status", status);
if (Config::Current()->DebugEnabled) { if (fields) {
blog(LOG_DEBUG, "Response << '%s'", responseStr.c_str()); obs_data_apply(response, fields);
} }
return responseStr; return response;
} }
bool WSRequestHandler::hasField(QString name) { bool WSRequestHandler::hasField(QString name) {

View File

@ -29,13 +29,15 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#include "obs-websocket.h" #include "obs-websocket.h"
typedef obs_data_t* HandlerResponse;
class WSRequestHandler : public QObject { class WSRequestHandler : public QObject {
Q_OBJECT Q_OBJECT
public: public:
explicit WSRequestHandler(QVariantHash& connProperties); explicit WSRequestHandler(QVariantHash& connProperties);
~WSRequestHandler(); ~WSRequestHandler();
std::string processIncomingMessage(std::string& textMessage); obs_data_t* processIncomingMessage(std::string& textMessage);
bool hasField(QString name); bool hasField(QString name);
private: private:
@ -44,109 +46,109 @@ class WSRequestHandler : public QObject {
QVariantHash& _connProperties; QVariantHash& _connProperties;
OBSDataAutoRelease data; OBSDataAutoRelease data;
std::string SendOKResponse(obs_data_t* additionalFields = NULL); HandlerResponse SendOKResponse(obs_data_t* additionalFields = nullptr);
std::string SendErrorResponse(const char* errorMessage); HandlerResponse SendErrorResponse(const char* errorMessage);
std::string SendErrorResponse(obs_data_t* additionalFields = NULL); HandlerResponse SendErrorResponse(obs_data_t* additionalFields = nullptr);
std::string SendResponse(obs_data_t* response); HandlerResponse SendResponse(const char* status, obs_data_t* additionalFields = nullptr);
static QHash<QString, std::string(*)(WSRequestHandler*)> messageMap; static QHash<QString, HandlerResponse(*)(WSRequestHandler*)> messageMap;
static QSet<QString> authNotRequired; static QSet<QString> authNotRequired;
static std::string HandleGetVersion(WSRequestHandler* req); static HandlerResponse HandleGetVersion(WSRequestHandler* req);
static std::string HandleGetAuthRequired(WSRequestHandler* req); static HandlerResponse HandleGetAuthRequired(WSRequestHandler* req);
static std::string HandleAuthenticate(WSRequestHandler* req); static HandlerResponse HandleAuthenticate(WSRequestHandler* req);
static std::string HandleSetHeartbeat(WSRequestHandler* req); static HandlerResponse HandleSetHeartbeat(WSRequestHandler* req);
static std::string HandleSetFilenameFormatting(WSRequestHandler* req); static HandlerResponse HandleSetFilenameFormatting(WSRequestHandler* req);
static std::string HandleGetFilenameFormatting(WSRequestHandler* req); static HandlerResponse HandleGetFilenameFormatting(WSRequestHandler* req);
static std::string HandleSetCurrentScene(WSRequestHandler* req); static HandlerResponse HandleSetCurrentScene(WSRequestHandler* req);
static std::string HandleGetCurrentScene(WSRequestHandler* req); static HandlerResponse HandleGetCurrentScene(WSRequestHandler* req);
static std::string HandleGetSceneList(WSRequestHandler* req); static HandlerResponse HandleGetSceneList(WSRequestHandler* req);
static std::string HandleSetSceneItemRender(WSRequestHandler* req); static HandlerResponse HandleSetSceneItemRender(WSRequestHandler* req);
static std::string HandleSetSceneItemPosition(WSRequestHandler* req); static HandlerResponse HandleSetSceneItemPosition(WSRequestHandler* req);
static std::string HandleSetSceneItemTransform(WSRequestHandler* req); static HandlerResponse HandleSetSceneItemTransform(WSRequestHandler* req);
static std::string HandleSetSceneItemCrop(WSRequestHandler* req); static HandlerResponse HandleSetSceneItemCrop(WSRequestHandler* req);
static std::string HandleGetSceneItemProperties(WSRequestHandler* req); static HandlerResponse HandleGetSceneItemProperties(WSRequestHandler* req);
static std::string HandleSetSceneItemProperties(WSRequestHandler* req); static HandlerResponse HandleSetSceneItemProperties(WSRequestHandler* req);
static std::string HandleResetSceneItem(WSRequestHandler* req); static HandlerResponse HandleResetSceneItem(WSRequestHandler* req);
static std::string HandleDuplicateSceneItem(WSRequestHandler* req); static HandlerResponse HandleDuplicateSceneItem(WSRequestHandler* req);
static std::string HandleDeleteSceneItem(WSRequestHandler* req); static HandlerResponse HandleDeleteSceneItem(WSRequestHandler* req);
static std::string HandleReorderSceneItems(WSRequestHandler* req); static HandlerResponse HandleReorderSceneItems(WSRequestHandler* req);
static std::string HandleGetStreamingStatus(WSRequestHandler* req); static HandlerResponse HandleGetStreamingStatus(WSRequestHandler* req);
static std::string HandleStartStopStreaming(WSRequestHandler* req); static HandlerResponse HandleStartStopStreaming(WSRequestHandler* req);
static std::string HandleStartStopRecording(WSRequestHandler* req); static HandlerResponse HandleStartStopRecording(WSRequestHandler* req);
static std::string HandleStartStreaming(WSRequestHandler* req); static HandlerResponse HandleStartStreaming(WSRequestHandler* req);
static std::string HandleStopStreaming(WSRequestHandler* req); static HandlerResponse HandleStopStreaming(WSRequestHandler* req);
static std::string HandleStartRecording(WSRequestHandler* req); static HandlerResponse HandleStartRecording(WSRequestHandler* req);
static std::string HandleStopRecording(WSRequestHandler* req); static HandlerResponse HandleStopRecording(WSRequestHandler* req);
static std::string HandleStartStopReplayBuffer(WSRequestHandler* req); static HandlerResponse HandleStartStopReplayBuffer(WSRequestHandler* req);
static std::string HandleStartReplayBuffer(WSRequestHandler* req); static HandlerResponse HandleStartReplayBuffer(WSRequestHandler* req);
static std::string HandleStopReplayBuffer(WSRequestHandler* req); static HandlerResponse HandleStopReplayBuffer(WSRequestHandler* req);
static std::string HandleSaveReplayBuffer(WSRequestHandler* req); static HandlerResponse HandleSaveReplayBuffer(WSRequestHandler* req);
static std::string HandleSetRecordingFolder(WSRequestHandler* req); static HandlerResponse HandleSetRecordingFolder(WSRequestHandler* req);
static std::string HandleGetRecordingFolder(WSRequestHandler* req); static HandlerResponse HandleGetRecordingFolder(WSRequestHandler* req);
static std::string HandleGetTransitionList(WSRequestHandler* req); static HandlerResponse HandleGetTransitionList(WSRequestHandler* req);
static std::string HandleGetCurrentTransition(WSRequestHandler* req); static HandlerResponse HandleGetCurrentTransition(WSRequestHandler* req);
static std::string HandleSetCurrentTransition(WSRequestHandler* req); static HandlerResponse HandleSetCurrentTransition(WSRequestHandler* req);
static std::string HandleSetVolume(WSRequestHandler* req); static HandlerResponse HandleSetVolume(WSRequestHandler* req);
static std::string HandleGetVolume(WSRequestHandler* req); static HandlerResponse HandleGetVolume(WSRequestHandler* req);
static std::string HandleToggleMute(WSRequestHandler* req); static HandlerResponse HandleToggleMute(WSRequestHandler* req);
static std::string HandleSetMute(WSRequestHandler* req); static HandlerResponse HandleSetMute(WSRequestHandler* req);
static std::string HandleGetMute(WSRequestHandler* req); static HandlerResponse HandleGetMute(WSRequestHandler* req);
static std::string HandleSetSyncOffset(WSRequestHandler* req); static HandlerResponse HandleSetSyncOffset(WSRequestHandler* req);
static std::string HandleGetSyncOffset(WSRequestHandler* req); static HandlerResponse HandleGetSyncOffset(WSRequestHandler* req);
static std::string HandleGetSpecialSources(WSRequestHandler* req); static HandlerResponse HandleGetSpecialSources(WSRequestHandler* req);
static std::string HandleGetSourcesList(WSRequestHandler* req); static HandlerResponse HandleGetSourcesList(WSRequestHandler* req);
static std::string HandleGetSourceTypesList(WSRequestHandler* req); static HandlerResponse HandleGetSourceTypesList(WSRequestHandler* req);
static std::string HandleGetSourceSettings(WSRequestHandler* req); static HandlerResponse HandleGetSourceSettings(WSRequestHandler* req);
static std::string HandleSetSourceSettings(WSRequestHandler* req); static HandlerResponse HandleSetSourceSettings(WSRequestHandler* req);
static std::string HandleGetSourceFilters(WSRequestHandler* req); static HandlerResponse HandleGetSourceFilters(WSRequestHandler* req);
static std::string HandleAddFilterToSource(WSRequestHandler* req); static HandlerResponse HandleAddFilterToSource(WSRequestHandler* req);
static std::string HandleRemoveFilterFromSource(WSRequestHandler* req); static HandlerResponse HandleRemoveFilterFromSource(WSRequestHandler* req);
static std::string HandleReorderSourceFilter(WSRequestHandler* req); static HandlerResponse HandleReorderSourceFilter(WSRequestHandler* req);
static std::string HandleMoveSourceFilter(WSRequestHandler* req); static HandlerResponse HandleMoveSourceFilter(WSRequestHandler* req);
static std::string HandleSetSourceFilterSettings(WSRequestHandler* req); static HandlerResponse HandleSetSourceFilterSettings(WSRequestHandler* req);
static std::string HandleSetCurrentSceneCollection(WSRequestHandler* req); static HandlerResponse HandleSetCurrentSceneCollection(WSRequestHandler* req);
static std::string HandleGetCurrentSceneCollection(WSRequestHandler* req); static HandlerResponse HandleGetCurrentSceneCollection(WSRequestHandler* req);
static std::string HandleListSceneCollections(WSRequestHandler* req); static HandlerResponse HandleListSceneCollections(WSRequestHandler* req);
static std::string HandleSetCurrentProfile(WSRequestHandler* req); static HandlerResponse HandleSetCurrentProfile(WSRequestHandler* req);
static std::string HandleGetCurrentProfile(WSRequestHandler* req); static HandlerResponse HandleGetCurrentProfile(WSRequestHandler* req);
static std::string HandleListProfiles(WSRequestHandler* req); static HandlerResponse HandleListProfiles(WSRequestHandler* req);
static std::string HandleSetStreamSettings(WSRequestHandler* req); static HandlerResponse HandleSetStreamSettings(WSRequestHandler* req);
static std::string HandleGetStreamSettings(WSRequestHandler* req); static HandlerResponse HandleGetStreamSettings(WSRequestHandler* req);
static std::string HandleSaveStreamSettings(WSRequestHandler* req); static HandlerResponse HandleSaveStreamSettings(WSRequestHandler* req);
static std::string HandleSetTransitionDuration(WSRequestHandler* req); static HandlerResponse HandleSetTransitionDuration(WSRequestHandler* req);
static std::string HandleGetTransitionDuration(WSRequestHandler* req); static HandlerResponse HandleGetTransitionDuration(WSRequestHandler* req);
static std::string HandleGetStudioModeStatus(WSRequestHandler* req); static HandlerResponse HandleGetStudioModeStatus(WSRequestHandler* req);
static std::string HandleGetPreviewScene(WSRequestHandler* req); static HandlerResponse HandleGetPreviewScene(WSRequestHandler* req);
static std::string HandleSetPreviewScene(WSRequestHandler* req); static HandlerResponse HandleSetPreviewScene(WSRequestHandler* req);
static std::string HandleTransitionToProgram(WSRequestHandler* req); static HandlerResponse HandleTransitionToProgram(WSRequestHandler* req);
static std::string HandleEnableStudioMode(WSRequestHandler* req); static HandlerResponse HandleEnableStudioMode(WSRequestHandler* req);
static std::string HandleDisableStudioMode(WSRequestHandler* req); static HandlerResponse HandleDisableStudioMode(WSRequestHandler* req);
static std::string HandleToggleStudioMode(WSRequestHandler* req); static HandlerResponse HandleToggleStudioMode(WSRequestHandler* req);
static std::string HandleSetTextGDIPlusProperties(WSRequestHandler* req); static HandlerResponse HandleSetTextGDIPlusProperties(WSRequestHandler* req);
static std::string HandleGetTextGDIPlusProperties(WSRequestHandler* req); static HandlerResponse HandleGetTextGDIPlusProperties(WSRequestHandler* req);
static std::string HandleSetTextFreetype2Properties(WSRequestHandler* req); static HandlerResponse HandleSetTextFreetype2Properties(WSRequestHandler* req);
static std::string HandleGetTextFreetype2Properties(WSRequestHandler* req); static HandlerResponse HandleGetTextFreetype2Properties(WSRequestHandler* req);
static std::string HandleSetBrowserSourceProperties(WSRequestHandler* req); static HandlerResponse HandleSetBrowserSourceProperties(WSRequestHandler* req);
static std::string HandleGetBrowserSourceProperties(WSRequestHandler* req); static HandlerResponse HandleGetBrowserSourceProperties(WSRequestHandler* req);
}; };
#endif // WSPROTOCOL_H #endif // WSPROTOCOL_H

View File

@ -19,7 +19,7 @@
* @category general * @category general
* @since 0.3 * @since 0.3
*/ */
std::string WSRequestHandler::HandleGetVersion(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleGetVersion(WSRequestHandler* req) {
QString obsVersion = Utils::OBSVersionString(); QString obsVersion = Utils::OBSVersionString();
QList<QString> names = req->messageMap.keys(); QList<QString> names = req->messageMap.keys();
@ -53,7 +53,7 @@ std::string WSRequestHandler::HandleGetVersion(WSRequestHandler* req) {
* @category general * @category general
* @since 0.3 * @since 0.3
*/ */
std::string WSRequestHandler::HandleGetAuthRequired(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleGetAuthRequired(WSRequestHandler* req) {
bool authRequired = Config::Current()->AuthRequired; bool authRequired = Config::Current()->AuthRequired;
OBSDataAutoRelease data = obs_data_create(); OBSDataAutoRelease data = obs_data_create();
@ -79,7 +79,7 @@ std::string WSRequestHandler::HandleGetAuthRequired(WSRequestHandler* req) {
* @category general * @category general
* @since 0.3 * @since 0.3
*/ */
std::string WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) {
if (!req->hasField("auth")) { if (!req->hasField("auth")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
} }
@ -111,7 +111,7 @@ std::string WSRequestHandler::HandleAuthenticate(WSRequestHandler* req) {
* @category general * @category general
* @since 4.3.0 * @since 4.3.0
*/ */
std::string WSRequestHandler::HandleSetHeartbeat(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleSetHeartbeat(WSRequestHandler* req) {
if (!req->hasField("enable")) { if (!req->hasField("enable")) {
return req->SendErrorResponse("Heartbeat <enable> parameter missing"); return req->SendErrorResponse("Heartbeat <enable> parameter missing");
} }
@ -134,7 +134,7 @@ std::string WSRequestHandler::HandleSetHeartbeat(WSRequestHandler* req) {
* @category general * @category general
* @since 4.3.0 * @since 4.3.0
*/ */
std::string WSRequestHandler::HandleSetFilenameFormatting(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleSetFilenameFormatting(WSRequestHandler* req) {
if (!req->hasField("filename-formatting")) { if (!req->hasField("filename-formatting")) {
return req->SendErrorResponse("<filename-formatting> parameter missing"); return req->SendErrorResponse("<filename-formatting> parameter missing");
} }
@ -158,7 +158,7 @@ std::string WSRequestHandler::HandleSetFilenameFormatting(WSRequestHandler* req)
* @category general * @category general
* @since 4.3.0 * @since 4.3.0
*/ */
std::string WSRequestHandler::HandleGetFilenameFormatting(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleGetFilenameFormatting(WSRequestHandler* req) {
OBSDataAutoRelease response = obs_data_create(); OBSDataAutoRelease response = obs_data_create();
obs_data_set_string(response, "filename-formatting", Utils::GetFilenameFormatting()); obs_data_set_string(response, "filename-formatting", Utils::GetFilenameFormatting());
return req->SendOKResponse(response); return req->SendOKResponse(response);

View File

@ -13,7 +13,7 @@
* @category profiles * @category profiles
* @since 4.0.0 * @since 4.0.0
*/ */
std::string WSRequestHandler::HandleSetCurrentProfile(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleSetCurrentProfile(WSRequestHandler* req) {
if (!req->hasField("profile-name")) { if (!req->hasField("profile-name")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
} }
@ -38,7 +38,7 @@ std::string WSRequestHandler::HandleSetCurrentProfile(WSRequestHandler* req) {
* @category profiles * @category profiles
* @since 4.0.0 * @since 4.0.0
*/ */
std::string WSRequestHandler::HandleGetCurrentProfile(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleGetCurrentProfile(WSRequestHandler* req) {
OBSDataAutoRelease response = obs_data_create(); OBSDataAutoRelease response = obs_data_create();
obs_data_set_string(response, "profile-name", obs_frontend_get_current_profile()); obs_data_set_string(response, "profile-name", obs_frontend_get_current_profile());
return req->SendOKResponse(response); return req->SendOKResponse(response);
@ -54,7 +54,7 @@ std::string WSRequestHandler::HandleGetCurrentProfile(WSRequestHandler* req) {
* @category profiles * @category profiles
* @since 4.0.0 * @since 4.0.0
*/ */
std::string WSRequestHandler::HandleListProfiles(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleListProfiles(WSRequestHandler* req) {
char** profiles = obs_frontend_get_profiles(); char** profiles = obs_frontend_get_profiles();
OBSDataArrayAutoRelease list = Utils::StringListToArray(profiles, "profile-name"); OBSDataArrayAutoRelease list = Utils::StringListToArray(profiles, "profile-name");
bfree(profiles); bfree(profiles);

View File

@ -11,7 +11,7 @@
* @category recording * @category recording
* @since 0.3 * @since 0.3
*/ */
std::string WSRequestHandler::HandleStartStopRecording(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleStartStopRecording(WSRequestHandler* req) {
if (obs_frontend_recording_active()) if (obs_frontend_recording_active())
obs_frontend_recording_stop(); obs_frontend_recording_stop();
else else
@ -29,7 +29,7 @@ std::string WSRequestHandler::HandleStartStopRecording(WSRequestHandler* req) {
* @category recording * @category recording
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleStartRecording(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleStartRecording(WSRequestHandler* req) {
if (obs_frontend_recording_active() == false) { if (obs_frontend_recording_active() == false) {
obs_frontend_recording_start(); obs_frontend_recording_start();
return req->SendOKResponse(); return req->SendOKResponse();
@ -47,7 +47,7 @@ std::string WSRequestHandler::HandleStartStopRecording(WSRequestHandler* req) {
* @category recording * @category recording
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleStopRecording(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleStopRecording(WSRequestHandler* req) {
if (obs_frontend_recording_active() == true) { if (obs_frontend_recording_active() == true) {
obs_frontend_recording_stop(); obs_frontend_recording_stop();
return req->SendOKResponse(); return req->SendOKResponse();
@ -66,7 +66,7 @@ std::string WSRequestHandler::HandleStartStopRecording(WSRequestHandler* req) {
* @category recording * @category recording
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleSetRecordingFolder(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleSetRecordingFolder(WSRequestHandler* req) {
if (!req->hasField("rec-folder")) { if (!req->hasField("rec-folder")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
} }
@ -90,7 +90,7 @@ std::string WSRequestHandler::HandleSetRecordingFolder(WSRequestHandler* req) {
* @category recording * @category recording
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleGetRecordingFolder(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleGetRecordingFolder(WSRequestHandler* req) {
const char* recFolder = Utils::GetRecordingFolder(); const char* recFolder = Utils::GetRecordingFolder();
OBSDataAutoRelease response = obs_data_create(); OBSDataAutoRelease response = obs_data_create();

View File

@ -11,7 +11,7 @@
* @category replay buffer * @category replay buffer
* @since 4.2.0 * @since 4.2.0
*/ */
std::string WSRequestHandler::HandleStartStopReplayBuffer(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleStartStopReplayBuffer(WSRequestHandler* req) {
if (obs_frontend_replay_buffer_active()) { if (obs_frontend_replay_buffer_active()) {
obs_frontend_replay_buffer_stop(); obs_frontend_replay_buffer_stop();
} else { } else {
@ -32,7 +32,7 @@ std::string WSRequestHandler::HandleStartStopReplayBuffer(WSRequestHandler* req)
* @category replay buffer * @category replay buffer
* @since 4.2.0 * @since 4.2.0
*/ */
std::string WSRequestHandler::HandleStartReplayBuffer(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleStartReplayBuffer(WSRequestHandler* req) {
if (!Utils::ReplayBufferEnabled()) { if (!Utils::ReplayBufferEnabled()) {
return req->SendErrorResponse("replay buffer disabled in settings"); return req->SendErrorResponse("replay buffer disabled in settings");
} }
@ -54,7 +54,7 @@ std::string WSRequestHandler::HandleStartReplayBuffer(WSRequestHandler* req) {
* @category replay buffer * @category replay buffer
* @since 4.2.0 * @since 4.2.0
*/ */
std::string WSRequestHandler::HandleStopReplayBuffer(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleStopReplayBuffer(WSRequestHandler* req) {
if (obs_frontend_replay_buffer_active() == true) { if (obs_frontend_replay_buffer_active() == true) {
obs_frontend_replay_buffer_stop(); obs_frontend_replay_buffer_stop();
return req->SendOKResponse(); return req->SendOKResponse();
@ -73,7 +73,7 @@ std::string WSRequestHandler::HandleStopReplayBuffer(WSRequestHandler* req) {
* @category replay buffer * @category replay buffer
* @since 4.2.0 * @since 4.2.0
*/ */
std::string WSRequestHandler::HandleSaveReplayBuffer(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleSaveReplayBuffer(WSRequestHandler* req) {
if (!obs_frontend_replay_buffer_active()) { if (!obs_frontend_replay_buffer_active()) {
return req->SendErrorResponse("replay buffer not active"); return req->SendErrorResponse("replay buffer not active");
} }

View File

@ -13,7 +13,7 @@
* @category scene collections * @category scene collections
* @since 4.0.0 * @since 4.0.0
*/ */
std::string WSRequestHandler::HandleSetCurrentSceneCollection(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleSetCurrentSceneCollection(WSRequestHandler* req) {
if (!req->hasField("sc-name")) { if (!req->hasField("sc-name")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
} }
@ -38,7 +38,7 @@ std::string WSRequestHandler::HandleSetCurrentSceneCollection(WSRequestHandler*
* @category scene collections * @category scene collections
* @since 4.0.0 * @since 4.0.0
*/ */
std::string WSRequestHandler::HandleGetCurrentSceneCollection(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleGetCurrentSceneCollection(WSRequestHandler* req) {
OBSDataAutoRelease response = obs_data_create(); OBSDataAutoRelease response = obs_data_create();
obs_data_set_string(response, "sc-name", obs_data_set_string(response, "sc-name",
obs_frontend_get_current_scene_collection()); obs_frontend_get_current_scene_collection());
@ -56,7 +56,7 @@ std::string WSRequestHandler::HandleGetCurrentSceneCollection(WSRequestHandler*
* @category scene collections * @category scene collections
* @since 4.0.0 * @since 4.0.0
*/ */
std::string WSRequestHandler::HandleListSceneCollections(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleListSceneCollections(WSRequestHandler* req) {
char** sceneCollections = obs_frontend_get_scene_collections(); char** sceneCollections = obs_frontend_get_scene_collections();
OBSDataArrayAutoRelease list = OBSDataArrayAutoRelease list =
Utils::StringListToArray(sceneCollections, "sc-name"); Utils::StringListToArray(sceneCollections, "sc-name");

View File

@ -31,7 +31,7 @@
* @category scene items * @category scene items
* @since 4.3.0 * @since 4.3.0
*/ */
std::string WSRequestHandler::HandleGetSceneItemProperties(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleGetSceneItemProperties(WSRequestHandler* req) {
if (!req->hasField("item")) { if (!req->hasField("item")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
} }
@ -153,7 +153,7 @@ std::string WSRequestHandler::HandleGetSceneItemProperties(WSRequestHandler* req
* @category scene items * @category scene items
* @since 4.3.0 * @since 4.3.0
*/ */
std::string WSRequestHandler::HandleSetSceneItemProperties(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleSetSceneItemProperties(WSRequestHandler* req) {
if (!req->hasField("item")) { if (!req->hasField("item")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
} }
@ -321,7 +321,7 @@ std::string WSRequestHandler::HandleSetSceneItemProperties(WSRequestHandler* req
* @category scene items * @category scene items
* @since 4.2.0 * @since 4.2.0
*/ */
std::string WSRequestHandler::HandleResetSceneItem(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleResetSceneItem(WSRequestHandler* req) {
// TODO: remove this request, or refactor it to ResetSource // TODO: remove this request, or refactor it to ResetSource
if (!req->hasField("item")) { if (!req->hasField("item")) {
@ -365,7 +365,7 @@ std::string WSRequestHandler::HandleResetSceneItem(WSRequestHandler* req) {
* @since 0.3 * @since 0.3
* @deprecated Since 4.3.0. Prefer the use of SetSceneItemProperties. * @deprecated Since 4.3.0. Prefer the use of SetSceneItemProperties.
*/ */
std::string WSRequestHandler::HandleSetSceneItemRender(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleSetSceneItemRender(WSRequestHandler* req) {
if (!req->hasField("source") || if (!req->hasField("source") ||
!req->hasField("render")) !req->hasField("render"))
{ {
@ -410,7 +410,7 @@ std::string WSRequestHandler::HandleSetSceneItemRender(WSRequestHandler* req) {
* @since 4.0.0 * @since 4.0.0
* @deprecated Since 4.3.0. Prefer the use of SetSceneItemProperties. * @deprecated Since 4.3.0. Prefer the use of SetSceneItemProperties.
*/ */
std::string WSRequestHandler::HandleSetSceneItemPosition(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleSetSceneItemPosition(WSRequestHandler* req) {
if (!req->hasField("item") || if (!req->hasField("item") ||
!req->hasField("x") || !req->hasField("y")) { !req->hasField("x") || !req->hasField("y")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
@ -455,7 +455,7 @@ std::string WSRequestHandler::HandleSetSceneItemPosition(WSRequestHandler* req)
* @since 4.0.0 * @since 4.0.0
* @deprecated Since 4.3.0. Prefer the use of SetSceneItemProperties. * @deprecated Since 4.3.0. Prefer the use of SetSceneItemProperties.
*/ */
std::string WSRequestHandler::HandleSetSceneItemTransform(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleSetSceneItemTransform(WSRequestHandler* req) {
if (!req->hasField("item") || if (!req->hasField("item") ||
!req->hasField("x-scale") || !req->hasField("x-scale") ||
!req->hasField("y-scale") || !req->hasField("y-scale") ||
@ -506,7 +506,7 @@ std::string WSRequestHandler::HandleSetSceneItemTransform(WSRequestHandler* req)
* @since 4.1.0 * @since 4.1.0
* @deprecated Since 4.3.0. Prefer the use of SetSceneItemProperties. * @deprecated Since 4.3.0. Prefer the use of SetSceneItemProperties.
*/ */
std::string WSRequestHandler::HandleSetSceneItemCrop(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleSetSceneItemCrop(WSRequestHandler* req) {
if (!req->hasField("item")) { if (!req->hasField("item")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
} }
@ -551,7 +551,7 @@ std::string WSRequestHandler::HandleSetSceneItemCrop(WSRequestHandler* req) {
* @category scene items * @category scene items
* @since 4.5.0 * @since 4.5.0
*/ */
std::string WSRequestHandler::HandleDeleteSceneItem(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleDeleteSceneItem(WSRequestHandler* req) {
if (!req->hasField("item")) { if (!req->hasField("item")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
} }
@ -604,7 +604,7 @@ static void DuplicateSceneItem(void *_data, obs_scene_t *scene) {
* @category scene items * @category scene items
* @since 4.5.0 * @since 4.5.0
*/ */
std::string WSRequestHandler::HandleDuplicateSceneItem(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleDuplicateSceneItem(WSRequestHandler* req) {
if (!req->hasField("item")) { if (!req->hasField("item")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
} }

View File

@ -19,7 +19,7 @@
* @category scenes * @category scenes
* @since 0.3 * @since 0.3
*/ */
std::string WSRequestHandler::HandleSetCurrentScene(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleSetCurrentScene(WSRequestHandler* req) {
if (!req->hasField("scene-name")) { if (!req->hasField("scene-name")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
} }
@ -46,7 +46,7 @@ std::string WSRequestHandler::HandleSetCurrentScene(WSRequestHandler* req) {
* @category scenes * @category scenes
* @since 0.3 * @since 0.3
*/ */
std::string WSRequestHandler::HandleGetCurrentScene(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleGetCurrentScene(WSRequestHandler* req) {
OBSSourceAutoRelease currentScene = obs_frontend_get_current_scene(); OBSSourceAutoRelease currentScene = obs_frontend_get_current_scene();
OBSDataArrayAutoRelease sceneItems = Utils::GetSceneItems(currentScene); OBSDataArrayAutoRelease sceneItems = Utils::GetSceneItems(currentScene);
@ -68,7 +68,7 @@ std::string WSRequestHandler::HandleGetCurrentScene(WSRequestHandler* req) {
* @category scenes * @category scenes
* @since 0.3 * @since 0.3
*/ */
std::string WSRequestHandler::HandleGetSceneList(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleGetSceneList(WSRequestHandler* req) {
OBSSourceAutoRelease currentScene = obs_frontend_get_current_scene(); OBSSourceAutoRelease currentScene = obs_frontend_get_current_scene();
OBSDataArrayAutoRelease scenes = Utils::GetScenes(); OBSDataArrayAutoRelease scenes = Utils::GetScenes();
@ -93,7 +93,7 @@ std::string WSRequestHandler::HandleGetSceneList(WSRequestHandler* req) {
* @category scenes * @category scenes
* @since 4.5.0 * @since 4.5.0
*/ */
std::string WSRequestHandler::HandleReorderSceneItems(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleReorderSceneItems(WSRequestHandler* req) {
QString sceneName = obs_data_get_string(req->data, "scene"); QString sceneName = obs_data_get_string(req->data, "scene");
OBSSourceAutoRelease scene = Utils::GetSceneFromNameOrCurrent(sceneName); OBSSourceAutoRelease scene = Utils::GetSceneFromNameOrCurrent(sceneName);
if (!scene) { if (!scene) {

View File

@ -30,7 +30,7 @@
* @category sources * @category sources
* @since 4.3.0 * @since 4.3.0
*/ */
std::string WSRequestHandler::HandleGetSourcesList(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleGetSourcesList(WSRequestHandler* req)
{ {
OBSDataArrayAutoRelease sourcesArray = obs_data_array_create(); OBSDataArrayAutoRelease sourcesArray = obs_data_array_create();
@ -98,7 +98,7 @@ std::string WSRequestHandler::HandleGetSourcesList(WSRequestHandler* req)
* @category sources * @category sources
* @since 4.3.0 * @since 4.3.0
*/ */
std::string WSRequestHandler::HandleGetSourceTypesList(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleGetSourceTypesList(WSRequestHandler* req)
{ {
OBSDataArrayAutoRelease idsArray = obs_data_array_create(); OBSDataArrayAutoRelease idsArray = obs_data_array_create();
@ -168,7 +168,7 @@ std::string WSRequestHandler::HandleGetSourceTypesList(WSRequestHandler* req)
* @category sources * @category sources
* @since 4.0.0 * @since 4.0.0
*/ */
std::string WSRequestHandler::HandleGetVolume(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleGetVolume(WSRequestHandler* req)
{ {
if (!req->hasField("source")) { if (!req->hasField("source")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
@ -203,7 +203,7 @@ std::string WSRequestHandler::HandleGetVolume(WSRequestHandler* req)
* @category sources * @category sources
* @since 4.0.0 * @since 4.0.0
*/ */
std::string WSRequestHandler::HandleSetVolume(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleSetVolume(WSRequestHandler* req)
{ {
if (!req->hasField("source") || !req->hasField("volume")) { if (!req->hasField("source") || !req->hasField("volume")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
@ -238,7 +238,7 @@ std::string WSRequestHandler::HandleSetVolume(WSRequestHandler* req)
* @category sources * @category sources
* @since 4.0.0 * @since 4.0.0
*/ */
std::string WSRequestHandler::HandleGetMute(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleGetMute(WSRequestHandler* req)
{ {
if (!req->hasField("source")) { if (!req->hasField("source")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
@ -272,7 +272,7 @@ std::string WSRequestHandler::HandleGetMute(WSRequestHandler* req)
* @category sources * @category sources
* @since 4.0.0 * @since 4.0.0
*/ */
std::string WSRequestHandler::HandleSetMute(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleSetMute(WSRequestHandler* req)
{ {
if (!req->hasField("source") || !req->hasField("mute")) { if (!req->hasField("source") || !req->hasField("mute")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
@ -304,7 +304,7 @@ std::string WSRequestHandler::HandleSetMute(WSRequestHandler* req)
* @category sources * @category sources
* @since 4.0.0 * @since 4.0.0
*/ */
std::string WSRequestHandler::HandleToggleMute(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleToggleMute(WSRequestHandler* req)
{ {
if (!req->hasField("source")) { if (!req->hasField("source")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
@ -335,7 +335,7 @@ std::string WSRequestHandler::HandleToggleMute(WSRequestHandler* req)
* @category sources * @category sources
* @since 4.2.0 * @since 4.2.0
*/ */
std::string WSRequestHandler::HandleSetSyncOffset(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleSetSyncOffset(WSRequestHandler* req)
{ {
if (!req->hasField("source") || !req->hasField("offset")) { if (!req->hasField("source") || !req->hasField("offset")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
@ -370,7 +370,7 @@ std::string WSRequestHandler::HandleSetSyncOffset(WSRequestHandler* req)
* @category sources * @category sources
* @since 4.2.0 * @since 4.2.0
*/ */
std::string WSRequestHandler::HandleGetSyncOffset(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleGetSyncOffset(WSRequestHandler* req)
{ {
if (!req->hasField("source")) { if (!req->hasField("source")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
@ -408,7 +408,7 @@ std::string WSRequestHandler::HandleGetSyncOffset(WSRequestHandler* req)
* @category sources * @category sources
* @since 4.3.0 * @since 4.3.0
*/ */
std::string WSRequestHandler::HandleGetSourceSettings(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleGetSourceSettings(WSRequestHandler* req)
{ {
if (!req->hasField("sourceName")) { if (!req->hasField("sourceName")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
@ -455,7 +455,7 @@ std::string WSRequestHandler::HandleGetSourceSettings(WSRequestHandler* req)
* @category sources * @category sources
* @since 4.3.0 * @since 4.3.0
*/ */
std::string WSRequestHandler::HandleSetSourceSettings(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleSetSourceSettings(WSRequestHandler* req)
{ {
if (!req->hasField("sourceName") || !req->hasField("sourceSettings")) { if (!req->hasField("sourceName") || !req->hasField("sourceSettings")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
@ -533,7 +533,7 @@ std::string WSRequestHandler::HandleSetSourceSettings(WSRequestHandler* req)
* @category sources * @category sources
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleGetTextGDIPlusProperties(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleGetTextGDIPlusProperties(WSRequestHandler* req)
{ {
const char* sourceName = obs_data_get_string(req->data, "source"); const char* sourceName = obs_data_get_string(req->data, "source");
if (!sourceName) { if (!sourceName) {
@ -594,7 +594,7 @@ std::string WSRequestHandler::HandleGetTextGDIPlusProperties(WSRequestHandler* r
* @category sources * @category sources
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleSetTextGDIPlusProperties(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleSetTextGDIPlusProperties(WSRequestHandler* req)
{ {
if (!req->hasField("source")) { if (!req->hasField("source")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
@ -764,7 +764,7 @@ std::string WSRequestHandler::HandleSetTextGDIPlusProperties(WSRequestHandler* r
* @category sources * @category sources
* @since 4.5.0 * @since 4.5.0
*/ */
std::string WSRequestHandler::HandleGetTextFreetype2Properties(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleGetTextFreetype2Properties(WSRequestHandler* req)
{ {
const char* sourceName = obs_data_get_string(req->data, "source"); const char* sourceName = obs_data_get_string(req->data, "source");
if (!sourceName) { if (!sourceName) {
@ -812,7 +812,7 @@ std::string WSRequestHandler::HandleGetTextFreetype2Properties(WSRequestHandler*
* @category sources * @category sources
* @since 4.5.0 * @since 4.5.0
*/ */
std::string WSRequestHandler::HandleSetTextFreetype2Properties(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleSetTextFreetype2Properties(WSRequestHandler* req)
{ {
const char* sourceName = obs_data_get_string(req->data, "source"); const char* sourceName = obs_data_get_string(req->data, "source");
if (!sourceName) { if (!sourceName) {
@ -919,7 +919,7 @@ std::string WSRequestHandler::HandleSetTextFreetype2Properties(WSRequestHandler*
* @category sources * @category sources
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleGetBrowserSourceProperties(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleGetBrowserSourceProperties(WSRequestHandler* req)
{ {
const char* sourceName = obs_data_get_string(req->data, "source"); const char* sourceName = obs_data_get_string(req->data, "source");
if (!sourceName) { if (!sourceName) {
@ -961,7 +961,7 @@ std::string WSRequestHandler::HandleGetBrowserSourceProperties(WSRequestHandler*
* @category sources * @category sources
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleSetBrowserSourceProperties(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleSetBrowserSourceProperties(WSRequestHandler* req)
{ {
if (!req->hasField("source")) { if (!req->hasField("source")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
@ -1039,7 +1039,7 @@ std::string WSRequestHandler::HandleSetBrowserSourceProperties(WSRequestHandler*
* @category sources * @category sources
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleGetSpecialSources(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleGetSpecialSources(WSRequestHandler* req)
{ {
OBSDataAutoRelease response = obs_data_create(); OBSDataAutoRelease response = obs_data_create();
@ -1079,7 +1079,7 @@ std::string WSRequestHandler::HandleGetSpecialSources(WSRequestHandler* req)
* @category sources * @category sources
* @since 4.5.0 * @since 4.5.0
*/ */
std::string WSRequestHandler::HandleGetSourceFilters(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleGetSourceFilters(WSRequestHandler* req)
{ {
if (!req->hasField("sourceName")) { if (!req->hasField("sourceName")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
@ -1120,7 +1120,7 @@ std::string WSRequestHandler::HandleGetSourceFilters(WSRequestHandler* req)
* @category sources * @category sources
* @since 4.5.0 * @since 4.5.0
*/ */
std::string WSRequestHandler::HandleAddFilterToSource(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleAddFilterToSource(WSRequestHandler* req)
{ {
if (!req->hasField("sourceName") || !req->hasField("filterName") || if (!req->hasField("sourceName") || !req->hasField("filterName") ||
!req->hasField("filterType") || !req->hasField("filterSettings")) !req->hasField("filterType") || !req->hasField("filterSettings"))
@ -1167,7 +1167,7 @@ std::string WSRequestHandler::HandleAddFilterToSource(WSRequestHandler* req)
* @category sources * @category sources
* @since 4.5.0 * @since 4.5.0
*/ */
std::string WSRequestHandler::HandleRemoveFilterFromSource(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleRemoveFilterFromSource(WSRequestHandler* req)
{ {
if (!req->hasField("sourceName") || !req->hasField("filterName")) { if (!req->hasField("sourceName") || !req->hasField("filterName")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
@ -1203,7 +1203,7 @@ std::string WSRequestHandler::HandleRemoveFilterFromSource(WSRequestHandler* req
* @category sources * @category sources
* @since 4.5.0 * @since 4.5.0
*/ */
std::string WSRequestHandler::HandleReorderSourceFilter(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleReorderSourceFilter(WSRequestHandler* req)
{ {
if (!req->hasField("sourceName") || !req->hasField("filterName") || !req->hasField("newIndex")) { if (!req->hasField("sourceName") || !req->hasField("filterName") || !req->hasField("newIndex")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
@ -1276,7 +1276,7 @@ std::string WSRequestHandler::HandleReorderSourceFilter(WSRequestHandler* req)
* @category sources * @category sources
* @since 4.5.0 * @since 4.5.0
*/ */
std::string WSRequestHandler::HandleMoveSourceFilter(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleMoveSourceFilter(WSRequestHandler* req)
{ {
if (!req->hasField("sourceName") || !req->hasField("filterName") || !req->hasField("movementType")) { if (!req->hasField("sourceName") || !req->hasField("filterName") || !req->hasField("movementType")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
@ -1330,7 +1330,7 @@ std::string WSRequestHandler::HandleMoveSourceFilter(WSRequestHandler* req)
* @category sources * @category sources
* @since 4.5.0 * @since 4.5.0
*/ */
std::string WSRequestHandler::HandleSetSourceFilterSettings(WSRequestHandler* req) HandlerResponse WSRequestHandler::HandleSetSourceFilterSettings(WSRequestHandler* req)
{ {
if (!req->hasField("sourceName") || !req->hasField("filterName") || !req->hasField("filterSettings")) { if (!req->hasField("sourceName") || !req->hasField("filterName") || !req->hasField("filterSettings")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");

View File

@ -20,7 +20,7 @@
* @category streaming * @category streaming
* @since 0.3 * @since 0.3
*/ */
std::string WSRequestHandler::HandleGetStreamingStatus(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleGetStreamingStatus(WSRequestHandler* req) {
auto events = WSEvents::Current(); auto events = WSEvents::Current();
OBSDataAutoRelease data = obs_data_create(); OBSDataAutoRelease data = obs_data_create();
@ -52,7 +52,7 @@ std::string WSRequestHandler::HandleGetStreamingStatus(WSRequestHandler* req) {
* @category streaming * @category streaming
* @since 0.3 * @since 0.3
*/ */
std::string WSRequestHandler::HandleStartStopStreaming(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleStartStopStreaming(WSRequestHandler* req) {
if (obs_frontend_streaming_active()) if (obs_frontend_streaming_active())
return HandleStopStreaming(req); return HandleStopStreaming(req);
else else
@ -78,7 +78,7 @@ std::string WSRequestHandler::HandleStartStopStreaming(WSRequestHandler* req) {
* @category streaming * @category streaming
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleStartStreaming(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleStartStreaming(WSRequestHandler* req) {
if (obs_frontend_streaming_active() == false) { if (obs_frontend_streaming_active() == false) {
OBSService configuredService = obs_frontend_get_streaming_service(); OBSService configuredService = obs_frontend_get_streaming_service();
OBSService newService = nullptr; OBSService newService = nullptr;
@ -174,7 +174,7 @@ std::string WSRequestHandler::HandleStartStreaming(WSRequestHandler* req) {
* @category streaming * @category streaming
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleStopStreaming(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleStopStreaming(WSRequestHandler* req) {
if (obs_frontend_streaming_active() == true) { if (obs_frontend_streaming_active() == true) {
obs_frontend_streaming_stop(); obs_frontend_streaming_stop();
return req->SendOKResponse(); return req->SendOKResponse();
@ -200,7 +200,7 @@ std::string WSRequestHandler::HandleStopStreaming(WSRequestHandler* req) {
* @category streaming * @category streaming
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleSetStreamSettings(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleSetStreamSettings(WSRequestHandler* req) {
OBSService service = obs_frontend_get_streaming_service(); OBSService service = obs_frontend_get_streaming_service();
OBSDataAutoRelease requestSettings = obs_data_get_obj(req->data, "settings"); OBSDataAutoRelease requestSettings = obs_data_get_obj(req->data, "settings");
@ -262,7 +262,7 @@ std::string WSRequestHandler::HandleSetStreamSettings(WSRequestHandler* req) {
* @category streaming * @category streaming
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleGetStreamSettings(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleGetStreamSettings(WSRequestHandler* req) {
OBSService service = obs_frontend_get_streaming_service(); OBSService service = obs_frontend_get_streaming_service();
const char* serviceType = obs_service_get_type(service); const char* serviceType = obs_service_get_type(service);
@ -283,7 +283,7 @@ std::string WSRequestHandler::HandleGetStreamSettings(WSRequestHandler* req) {
* @category streaming * @category streaming
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleSaveStreamSettings(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleSaveStreamSettings(WSRequestHandler* req) {
obs_frontend_save_streaming_service(); obs_frontend_save_streaming_service();
return req->SendOKResponse(); return req->SendOKResponse();
} }

View File

@ -13,7 +13,7 @@
* @category studio mode * @category studio mode
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleGetStudioModeStatus(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleGetStudioModeStatus(WSRequestHandler* req) {
bool previewActive = obs_frontend_preview_program_mode_active(); bool previewActive = obs_frontend_preview_program_mode_active();
OBSDataAutoRelease response = obs_data_create(); OBSDataAutoRelease response = obs_data_create();
@ -34,7 +34,7 @@ std::string WSRequestHandler::HandleGetStudioModeStatus(WSRequestHandler* req) {
* @category studio mode * @category studio mode
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleGetPreviewScene(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleGetPreviewScene(WSRequestHandler* req) {
if (!obs_frontend_preview_program_mode_active()) { if (!obs_frontend_preview_program_mode_active()) {
return req->SendErrorResponse("studio mode not enabled"); return req->SendErrorResponse("studio mode not enabled");
} }
@ -60,7 +60,7 @@ std::string WSRequestHandler::HandleGetPreviewScene(WSRequestHandler* req) {
* @category studio mode * @category studio mode
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleSetPreviewScene(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleSetPreviewScene(WSRequestHandler* req) {
if (!obs_frontend_preview_program_mode_active()) { if (!obs_frontend_preview_program_mode_active()) {
return req->SendErrorResponse("studio mode not enabled"); return req->SendErrorResponse("studio mode not enabled");
} }
@ -92,7 +92,7 @@ std::string WSRequestHandler::HandleSetPreviewScene(WSRequestHandler* req) {
* @category studio mode * @category studio mode
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleTransitionToProgram(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleTransitionToProgram(WSRequestHandler* req) {
if (!obs_frontend_preview_program_mode_active()) { if (!obs_frontend_preview_program_mode_active()) {
return req->SendErrorResponse("studio mode not enabled"); return req->SendErrorResponse("studio mode not enabled");
} }
@ -133,7 +133,7 @@ std::string WSRequestHandler::HandleTransitionToProgram(WSRequestHandler* req) {
* @category studio mode * @category studio mode
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleEnableStudioMode(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleEnableStudioMode(WSRequestHandler* req) {
obs_frontend_set_preview_program_mode(true); obs_frontend_set_preview_program_mode(true);
return req->SendOKResponse(); return req->SendOKResponse();
} }
@ -146,7 +146,7 @@ std::string WSRequestHandler::HandleEnableStudioMode(WSRequestHandler* req) {
* @category studio mode * @category studio mode
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleDisableStudioMode(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleDisableStudioMode(WSRequestHandler* req) {
obs_frontend_set_preview_program_mode(false); obs_frontend_set_preview_program_mode(false);
return req->SendOKResponse(); return req->SendOKResponse();
} }
@ -159,7 +159,7 @@ std::string WSRequestHandler::HandleDisableStudioMode(WSRequestHandler* req) {
* @category studio mode * @category studio mode
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleToggleStudioMode(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleToggleStudioMode(WSRequestHandler* req) {
bool previewProgramMode = obs_frontend_preview_program_mode_active(); bool previewProgramMode = obs_frontend_preview_program_mode_active();
obs_frontend_set_preview_program_mode(!previewProgramMode); obs_frontend_set_preview_program_mode(!previewProgramMode);
return req->SendOKResponse(); return req->SendOKResponse();

View File

@ -15,7 +15,7 @@
* @category transitions * @category transitions
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleGetTransitionList(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleGetTransitionList(WSRequestHandler* req) {
OBSSourceAutoRelease currentTransition = obs_frontend_get_current_transition(); OBSSourceAutoRelease currentTransition = obs_frontend_get_current_transition();
obs_frontend_source_list transitionList = {}; obs_frontend_source_list transitionList = {};
obs_frontend_get_transitions(&transitionList); obs_frontend_get_transitions(&transitionList);
@ -49,7 +49,7 @@ std::string WSRequestHandler::HandleGetTransitionList(WSRequestHandler* req) {
* @category transitions * @category transitions
* @since 0.3 * @since 0.3
*/ */
std::string WSRequestHandler::HandleGetCurrentTransition(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleGetCurrentTransition(WSRequestHandler* req) {
OBSSourceAutoRelease currentTransition = obs_frontend_get_current_transition(); OBSSourceAutoRelease currentTransition = obs_frontend_get_current_transition();
OBSDataAutoRelease response = obs_data_create(); OBSDataAutoRelease response = obs_data_create();
@ -72,7 +72,7 @@ std::string WSRequestHandler::HandleGetCurrentTransition(WSRequestHandler* req)
* @category transitions * @category transitions
* @since 0.3 * @since 0.3
*/ */
std::string WSRequestHandler::HandleSetCurrentTransition(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleSetCurrentTransition(WSRequestHandler* req) {
if (!req->hasField("transition-name")) { if (!req->hasField("transition-name")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
} }
@ -96,7 +96,7 @@ std::string WSRequestHandler::HandleSetCurrentTransition(WSRequestHandler* req)
* @category transitions * @category transitions
* @since 4.0.0 * @since 4.0.0
*/ */
std::string WSRequestHandler::HandleSetTransitionDuration(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleSetTransitionDuration(WSRequestHandler* req) {
if (!req->hasField("duration")) { if (!req->hasField("duration")) {
return req->SendErrorResponse("missing request parameters"); return req->SendErrorResponse("missing request parameters");
} }
@ -116,7 +116,7 @@ std::string WSRequestHandler::HandleSetTransitionDuration(WSRequestHandler* req)
* @category transitions * @category transitions
* @since 4.1.0 * @since 4.1.0
*/ */
std::string WSRequestHandler::HandleGetTransitionDuration(WSRequestHandler* req) { HandlerResponse WSRequestHandler::HandleGetTransitionDuration(WSRequestHandler* req) {
OBSDataAutoRelease response = obs_data_create(); OBSDataAutoRelease response = obs_data_create();
obs_data_set_int(response, "transition-duration", Utils::GetTransitionDuration()); obs_data_set_int(response, "transition-duration", Utils::GetTransitionDuration());
return req->SendOKResponse(response); return req->SendOKResponse(response);

View File

@ -139,7 +139,13 @@ void WSServer::onMessage(connection_hdl hdl, server::message_ptr message)
locker.unlock(); locker.unlock();
WSRequestHandler handler(connProperties); WSRequestHandler handler(connProperties);
std::string response = handler.processIncomingMessage(payload); OBSDataAutoRelease responseData = handler.processIncomingMessage(payload);
std::string response = obs_data_get_json(responseData);
if (Config::Current()->DebugEnabled) {
blog(LOG_DEBUG, "Response << '%s'", response.c_str());
}
_server.send(hdl, response, websocketpp::frame::opcode::text); _server.send(hdl, response, websocketpp::frame::opcode::text);