mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
request handler: use static request QHash
Inspired by @yinzara's fork
This commit is contained in:
parent
488a095fdf
commit
53936a4f76
@ -36,94 +36,99 @@ bool str_valid(const char* str) {
|
|||||||
return (str != nullptr && strlen(str) > 0);
|
return (str != nullptr && strlen(str) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QHash<QString, void(*)(WSRequestHandler*)> WSRequestHandler::messageMap {
|
||||||
|
{ "GetVersion", WSRequestHandler::HandleGetVersion },
|
||||||
|
{ "GetAuthRequired", WSRequestHandler::HandleGetAuthRequired },
|
||||||
|
{ "Authenticate", WSRequestHandler::HandleAuthenticate },
|
||||||
|
|
||||||
|
{ "SetHeartbeat", WSRequestHandler::HandleSetHeartbeat },
|
||||||
|
|
||||||
|
{ "SetCurrentScene", WSRequestHandler::HandleSetCurrentScene },
|
||||||
|
{ "GetCurrentScene", WSRequestHandler::HandleGetCurrentScene },
|
||||||
|
{ "GetSceneList", WSRequestHandler::HandleGetSceneList },
|
||||||
|
|
||||||
|
{ "SetSourceRender", WSRequestHandler::HandleSetSceneItemRender }, // Retrocompat
|
||||||
|
{ "SetSceneItemRender", WSRequestHandler::HandleSetSceneItemRender },
|
||||||
|
{ "SetSceneItemPosition", WSRequestHandler::HandleSetSceneItemPosition },
|
||||||
|
{ "SetSceneItemTransform", WSRequestHandler::HandleSetSceneItemTransform },
|
||||||
|
{ "SetSceneItemCrop", WSRequestHandler::HandleSetSceneItemCrop },
|
||||||
|
{ "GetSceneItemProperties", WSRequestHandler::HandleGetSceneItemProperties },
|
||||||
|
{ "SetSceneItemProperties", WSRequestHandler::HandleSetSceneItemProperties },
|
||||||
|
{ "ResetSceneItem", WSRequestHandler::HandleResetSceneItem },
|
||||||
|
|
||||||
|
{ "GetStreamingStatus", WSRequestHandler::HandleGetStreamingStatus },
|
||||||
|
{ "StartStopStreaming", WSRequestHandler::HandleStartStopStreaming },
|
||||||
|
{ "StartStopRecording", WSRequestHandler::HandleStartStopRecording },
|
||||||
|
{ "StartStreaming", WSRequestHandler::HandleStartStreaming },
|
||||||
|
{ "StopStreaming", WSRequestHandler::HandleStopStreaming },
|
||||||
|
{ "StartRecording", WSRequestHandler::HandleStartRecording },
|
||||||
|
{ "StopRecording", WSRequestHandler::HandleStopRecording },
|
||||||
|
|
||||||
|
{ "StartStopReplayBuffer", WSRequestHandler::HandleStartStopReplayBuffer },
|
||||||
|
{ "StartReplayBuffer", WSRequestHandler::HandleStartReplayBuffer },
|
||||||
|
{ "StopReplayBuffer", WSRequestHandler::HandleStopReplayBuffer },
|
||||||
|
{ "SaveReplayBuffer", WSRequestHandler::HandleSaveReplayBuffer },
|
||||||
|
|
||||||
|
{ "SetRecordingFolder", WSRequestHandler::HandleSetRecordingFolder },
|
||||||
|
{ "GetRecordingFolder", WSRequestHandler::HandleGetRecordingFolder },
|
||||||
|
|
||||||
|
{ "GetTransitionList", WSRequestHandler::HandleGetTransitionList },
|
||||||
|
{ "GetCurrentTransition", WSRequestHandler::HandleGetCurrentTransition },
|
||||||
|
{ "SetCurrentTransition", WSRequestHandler::HandleSetCurrentTransition },
|
||||||
|
{ "SetTransitionDuration", WSRequestHandler::HandleSetTransitionDuration },
|
||||||
|
{ "GetTransitionDuration", WSRequestHandler::HandleGetTransitionDuration },
|
||||||
|
|
||||||
|
{ "SetVolume", WSRequestHandler::HandleSetVolume },
|
||||||
|
{ "GetVolume", WSRequestHandler::HandleGetVolume },
|
||||||
|
{ "ToggleMute", WSRequestHandler::HandleToggleMute },
|
||||||
|
{ "SetMute", WSRequestHandler::HandleSetMute },
|
||||||
|
{ "GetMute", WSRequestHandler::HandleGetMute },
|
||||||
|
{ "SetSyncOffset", WSRequestHandler::HandleSetSyncOffset },
|
||||||
|
{ "GetSyncOffset", WSRequestHandler::HandleGetSyncOffset },
|
||||||
|
{ "GetSpecialSources", WSRequestHandler::HandleGetSpecialSources },
|
||||||
|
{ "GetSourcesList", WSRequestHandler::HandleGetSourcesList },
|
||||||
|
{ "GetSourceSettings", WSRequestHandler::HandleGetSourceSettings },
|
||||||
|
{ "SetSourceSettings", WSRequestHandler::HandleSetSourceSettings },
|
||||||
|
|
||||||
|
{ "SetCurrentSceneCollection", WSRequestHandler::HandleSetCurrentSceneCollection },
|
||||||
|
{ "GetCurrentSceneCollection", WSRequestHandler::HandleGetCurrentSceneCollection },
|
||||||
|
{ "ListSceneCollections", WSRequestHandler::HandleListSceneCollections },
|
||||||
|
|
||||||
|
{ "SetCurrentProfile", WSRequestHandler::HandleSetCurrentProfile },
|
||||||
|
{ "GetCurrentProfile", WSRequestHandler::HandleGetCurrentProfile },
|
||||||
|
{ "ListProfiles", WSRequestHandler::HandleListProfiles },
|
||||||
|
|
||||||
|
{ "SetStreamSettings", WSRequestHandler::HandleSetStreamSettings },
|
||||||
|
{ "GetStreamSettings", WSRequestHandler::HandleGetStreamSettings },
|
||||||
|
{ "SaveStreamSettings", WSRequestHandler::HandleSaveStreamSettings },
|
||||||
|
|
||||||
|
{ "GetStudioModeStatus", WSRequestHandler::HandleGetStudioModeStatus },
|
||||||
|
{ "GetPreviewScene", WSRequestHandler::HandleGetPreviewScene },
|
||||||
|
{ "SetPreviewScene", WSRequestHandler::HandleSetPreviewScene },
|
||||||
|
{ "TransitionToProgram", WSRequestHandler::HandleTransitionToProgram },
|
||||||
|
{ "EnableStudioMode", WSRequestHandler::HandleEnableStudioMode },
|
||||||
|
{ "DisableStudioMode", WSRequestHandler::HandleDisableStudioMode },
|
||||||
|
{ "ToggleStudioMode", WSRequestHandler::HandleToggleStudioMode },
|
||||||
|
|
||||||
|
{ "SetTextGDIPlusProperties", WSRequestHandler::HandleSetTextGDIPlusProperties },
|
||||||
|
{ "GetTextGDIPlusProperties", WSRequestHandler::HandleGetTextGDIPlusProperties },
|
||||||
|
|
||||||
|
{ "GetBrowserSourceProperties", WSRequestHandler::HandleGetBrowserSourceProperties },
|
||||||
|
{ "SetBrowserSourceProperties", WSRequestHandler::HandleSetBrowserSourceProperties }
|
||||||
|
};
|
||||||
|
|
||||||
|
QSet<QString> WSRequestHandler::authNotRequired {
|
||||||
|
"GetVersion",
|
||||||
|
"GetAuthRequired",
|
||||||
|
"Authenticate"
|
||||||
|
};
|
||||||
|
|
||||||
WSRequestHandler::WSRequestHandler(QWebSocket* client) :
|
WSRequestHandler::WSRequestHandler(QWebSocket* client) :
|
||||||
_messageId(0),
|
_messageId(0),
|
||||||
_requestType(""),
|
_requestType(""),
|
||||||
data(nullptr),
|
data(nullptr),
|
||||||
_client(client)
|
_client(client)
|
||||||
{
|
{
|
||||||
messageMap["GetVersion"] = WSRequestHandler::HandleGetVersion;
|
|
||||||
messageMap["GetAuthRequired"] = WSRequestHandler::HandleGetAuthRequired;
|
|
||||||
messageMap["Authenticate"] = WSRequestHandler::HandleAuthenticate;
|
|
||||||
|
|
||||||
messageMap["SetHeartbeat"] = WSRequestHandler::HandleSetHeartbeat;
|
|
||||||
|
|
||||||
messageMap["SetCurrentScene"] = WSRequestHandler::HandleSetCurrentScene;
|
|
||||||
messageMap["GetCurrentScene"] = WSRequestHandler::HandleGetCurrentScene;
|
|
||||||
messageMap["GetSceneList"] = WSRequestHandler::HandleGetSceneList;
|
|
||||||
|
|
||||||
messageMap["SetSourceRender"] = WSRequestHandler::HandleSetSceneItemRender; // Retrocompat
|
|
||||||
messageMap["SetSceneItemRender"] = WSRequestHandler::HandleSetSceneItemRender;
|
|
||||||
messageMap["SetSceneItemPosition"] = WSRequestHandler::HandleSetSceneItemPosition;
|
|
||||||
messageMap["SetSceneItemTransform"] = WSRequestHandler::HandleSetSceneItemTransform;
|
|
||||||
messageMap["SetSceneItemCrop"] = WSRequestHandler::HandleSetSceneItemCrop;
|
|
||||||
messageMap["GetSceneItemProperties"] = WSRequestHandler::HandleGetSceneItemProperties;
|
|
||||||
messageMap["SetSceneItemProperties"] = WSRequestHandler::HandleSetSceneItemProperties;
|
|
||||||
messageMap["ResetSceneItem"] = WSRequestHandler::HandleResetSceneItem;
|
|
||||||
|
|
||||||
messageMap["GetStreamingStatus"] = WSRequestHandler::HandleGetStreamingStatus;
|
|
||||||
messageMap["StartStopStreaming"] = WSRequestHandler::HandleStartStopStreaming;
|
|
||||||
messageMap["StartStopRecording"] = WSRequestHandler::HandleStartStopRecording;
|
|
||||||
messageMap["StartStreaming"] = WSRequestHandler::HandleStartStreaming;
|
|
||||||
messageMap["StopStreaming"] = WSRequestHandler::HandleStopStreaming;
|
|
||||||
messageMap["StartRecording"] = WSRequestHandler::HandleStartRecording;
|
|
||||||
messageMap["StopRecording"] = WSRequestHandler::HandleStopRecording;
|
|
||||||
|
|
||||||
messageMap["StartStopReplayBuffer"] = WSRequestHandler::HandleStartStopReplayBuffer;
|
|
||||||
messageMap["StartReplayBuffer"] = WSRequestHandler::HandleStartReplayBuffer;
|
|
||||||
messageMap["StopReplayBuffer"] = WSRequestHandler::HandleStopReplayBuffer;
|
|
||||||
messageMap["SaveReplayBuffer"] = WSRequestHandler::HandleSaveReplayBuffer;
|
|
||||||
|
|
||||||
messageMap["SetRecordingFolder"] = WSRequestHandler::HandleSetRecordingFolder;
|
|
||||||
messageMap["GetRecordingFolder"] = WSRequestHandler::HandleGetRecordingFolder;
|
|
||||||
|
|
||||||
messageMap["GetTransitionList"] = WSRequestHandler::HandleGetTransitionList;
|
|
||||||
messageMap["GetCurrentTransition"] = WSRequestHandler::HandleGetCurrentTransition;
|
|
||||||
messageMap["SetCurrentTransition"] = WSRequestHandler::HandleSetCurrentTransition;
|
|
||||||
messageMap["SetTransitionDuration"] = WSRequestHandler::HandleSetTransitionDuration;
|
|
||||||
messageMap["GetTransitionDuration"] = WSRequestHandler::HandleGetTransitionDuration;
|
|
||||||
|
|
||||||
messageMap["SetVolume"] = WSRequestHandler::HandleSetVolume;
|
|
||||||
messageMap["GetVolume"] = WSRequestHandler::HandleGetVolume;
|
|
||||||
messageMap["ToggleMute"] = WSRequestHandler::HandleToggleMute;
|
|
||||||
messageMap["SetMute"] = WSRequestHandler::HandleSetMute;
|
|
||||||
messageMap["GetMute"] = WSRequestHandler::HandleGetMute;
|
|
||||||
messageMap["SetSyncOffset"] = WSRequestHandler::HandleSetSyncOffset;
|
|
||||||
messageMap["GetSyncOffset"] = WSRequestHandler::HandleGetSyncOffset;
|
|
||||||
messageMap["GetSpecialSources"] = WSRequestHandler::HandleGetSpecialSources;
|
|
||||||
messageMap["GetSourcesList"] = WSRequestHandler::HandleGetSourcesList;
|
|
||||||
messageMap["GetSourceSettings"] = WSRequestHandler::HandleGetSourceSettings;
|
|
||||||
messageMap["SetSourceSettings"] = WSRequestHandler::HandleSetSourceSettings;
|
|
||||||
|
|
||||||
messageMap["SetCurrentSceneCollection"] = WSRequestHandler::HandleSetCurrentSceneCollection;
|
|
||||||
messageMap["GetCurrentSceneCollection"] = WSRequestHandler::HandleGetCurrentSceneCollection;
|
|
||||||
messageMap["ListSceneCollections"] = WSRequestHandler::HandleListSceneCollections;
|
|
||||||
|
|
||||||
messageMap["SetCurrentProfile"] = WSRequestHandler::HandleSetCurrentProfile;
|
|
||||||
messageMap["GetCurrentProfile"] = WSRequestHandler::HandleGetCurrentProfile;
|
|
||||||
messageMap["ListProfiles"] = WSRequestHandler::HandleListProfiles;
|
|
||||||
|
|
||||||
messageMap["SetStreamSettings"] = WSRequestHandler::HandleSetStreamSettings;
|
|
||||||
messageMap["GetStreamSettings"] = WSRequestHandler::HandleGetStreamSettings;
|
|
||||||
messageMap["SaveStreamSettings"] = WSRequestHandler::HandleSaveStreamSettings;
|
|
||||||
|
|
||||||
messageMap["GetStudioModeStatus"] = WSRequestHandler::HandleGetStudioModeStatus;
|
|
||||||
messageMap["GetPreviewScene"] = WSRequestHandler::HandleGetPreviewScene;
|
|
||||||
messageMap["SetPreviewScene"] = WSRequestHandler::HandleSetPreviewScene;
|
|
||||||
messageMap["TransitionToProgram"] = WSRequestHandler::HandleTransitionToProgram;
|
|
||||||
messageMap["EnableStudioMode"] = WSRequestHandler::HandleEnableStudioMode;
|
|
||||||
messageMap["DisableStudioMode"] = WSRequestHandler::HandleDisableStudioMode;
|
|
||||||
messageMap["ToggleStudioMode"] = WSRequestHandler::HandleToggleStudioMode;
|
|
||||||
|
|
||||||
messageMap["SetTextGDIPlusProperties"] = WSRequestHandler::HandleSetTextGDIPlusProperties;
|
|
||||||
messageMap["GetTextGDIPlusProperties"] = WSRequestHandler::HandleGetTextGDIPlusProperties;
|
|
||||||
|
|
||||||
messageMap["GetBrowserSourceProperties"] = WSRequestHandler::HandleGetBrowserSourceProperties;
|
|
||||||
messageMap["SetBrowserSourceProperties"] = WSRequestHandler::HandleSetBrowserSourceProperties;
|
|
||||||
|
|
||||||
authNotRequired.insert("GetVersion");
|
|
||||||
authNotRequired.insert("GetAuthRequired");
|
|
||||||
authNotRequired.insert("Authenticate");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WSRequestHandler::processIncomingMessage(QString textMessage) {
|
void WSRequestHandler::processIncomingMessage(QString textMessage) {
|
||||||
|
@ -41,14 +41,14 @@ class WSRequestHandler : public QObject {
|
|||||||
const char* _requestType;
|
const char* _requestType;
|
||||||
obs_data_t* data;
|
obs_data_t* data;
|
||||||
|
|
||||||
QHash<QString, void(*)(WSRequestHandler*)> messageMap;
|
|
||||||
QSet<QString> authNotRequired;
|
|
||||||
|
|
||||||
void SendOKResponse(obs_data_t* additionalFields = NULL);
|
void SendOKResponse(obs_data_t* additionalFields = NULL);
|
||||||
void SendErrorResponse(const char* errorMessage);
|
void SendErrorResponse(const char* errorMessage);
|
||||||
void SendErrorResponse(obs_data_t* additionalFields = NULL);
|
void SendErrorResponse(obs_data_t* additionalFields = NULL);
|
||||||
void SendResponse(obs_data_t* response);
|
void SendResponse(obs_data_t* response);
|
||||||
|
|
||||||
|
static QHash<QString, void(*)(WSRequestHandler*)> messageMap;
|
||||||
|
static QSet<QString> authNotRequired;
|
||||||
|
|
||||||
static void HandleGetVersion(WSRequestHandler* req);
|
static void HandleGetVersion(WSRequestHandler* req);
|
||||||
static void HandleGetAuthRequired(WSRequestHandler* req);
|
static void HandleGetAuthRequired(WSRequestHandler* req);
|
||||||
static void HandleAuthenticate(WSRequestHandler* req);
|
static void HandleAuthenticate(WSRequestHandler* req);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user