diff --git a/Config.cpp b/Config.cpp
index 05ef459c..e9bd8921 100644
--- a/Config.cpp
+++ b/Config.cpp
@@ -27,6 +27,7 @@ with this program. If not, see
#define SECTION_NAME "WebsocketAPI"
#define PARAM_ENABLE "ServerEnabled"
#define PARAM_PORT "ServerPort"
+#define PARAM_DEBUG "DebugEnabled"
#define PARAM_AUTHREQUIRED "AuthRequired"
#define PARAM_SECRET "AuthSecret"
#define PARAM_SALT "AuthSalt"
@@ -38,6 +39,8 @@ Config::Config()
// Default settings
ServerEnabled = true;
ServerPort = 4444;
+
+ DebugEnabled = false;
AuthRequired = false;
Secret = "";
@@ -52,6 +55,9 @@ Config::Config()
SECTION_NAME, PARAM_ENABLE, ServerEnabled);
config_set_default_uint(obs_config,
SECTION_NAME, PARAM_PORT, ServerPort);
+
+ config_set_default_bool(obs_config,
+ SECTION_NAME, PARAM_DEBUG, DebugEnabled);
config_set_default_bool(obs_config,
SECTION_NAME, PARAM_AUTHREQUIRED, AuthRequired);
@@ -81,6 +87,8 @@ void Config::Load()
ServerEnabled = config_get_bool(obs_config, SECTION_NAME, PARAM_ENABLE);
ServerPort = config_get_uint(obs_config, SECTION_NAME, PARAM_PORT);
+
+ DebugEnabled = config_get_bool(obs_config, SECTION_NAME, PARAM_DEBUG);
AuthRequired = config_get_bool(obs_config, SECTION_NAME, PARAM_AUTHREQUIRED);
Secret = config_get_string(obs_config, SECTION_NAME, PARAM_SECRET);
@@ -93,6 +101,8 @@ void Config::Save()
config_set_bool(obs_config, SECTION_NAME, PARAM_ENABLE, ServerEnabled);
config_set_uint(obs_config, SECTION_NAME, PARAM_PORT, ServerPort);
+
+ config_set_bool(obs_config, SECTION_NAME, PARAM_DEBUG, DebugEnabled);
config_set_bool(obs_config, SECTION_NAME, PARAM_AUTHREQUIRED, AuthRequired);
config_set_string(obs_config, SECTION_NAME, PARAM_SECRET, Secret);
diff --git a/Config.h b/Config.h
index 8edc611f..f66c385b 100644
--- a/Config.h
+++ b/Config.h
@@ -38,6 +38,8 @@ class Config
bool ServerEnabled;
uint64_t ServerPort;
+
+ bool DebugEnabled;
bool AuthRequired;
const char *Secret;
diff --git a/WSEvents.cpp b/WSEvents.cpp
index 3beeb489..3dac8e3d 100644
--- a/WSEvents.cpp
+++ b/WSEvents.cpp
@@ -20,6 +20,7 @@ with this program. If not, see
#include
#include
#include
+#include "Config.h"
#include "Utils.h"
#include "WSEvents.h"
#include "obs-websocket.h"
@@ -213,9 +214,15 @@ void WSEvents::broadcastUpdate(const char* updateType, obs_data_t* additionalFie
if (additionalFields != NULL)
obs_data_apply(update, additionalFields);
- _srv->broadcast(obs_data_get_json(update));
-
+ const char *json = obs_data_get_json(update);
obs_data_release(update);
+
+ if (Config::Current()->DebugEnabled)
+ {
+ blog(LOG_DEBUG, "Update << '%s'", json);
+ }
+
+ _srv->broadcast(json);
}
void WSEvents::connectTransitionSignals(obs_source_t* transition)
diff --git a/WSRequestHandler.cpp b/WSRequestHandler.cpp
index 94c67f26..cfe5bee2 100644
--- a/WSRequestHandler.cpp
+++ b/WSRequestHandler.cpp
@@ -114,6 +114,11 @@ void WSRequestHandler::processIncomingMessage(QString textMessage)
SendErrorResponse("invalid JSON payload");
return;
}
+
+ if (Config::Current()->DebugEnabled)
+ {
+ blog(LOG_DEBUG, "Request >> '%s'", msg);
+ }
if (!hasField("request-type") ||
!hasField("message-id"))
@@ -156,9 +161,7 @@ void WSRequestHandler::SendOKResponse(obs_data_t* additionalFields)
if (additionalFields)
obs_data_apply(response, additionalFields);
- _client->sendTextMessage(obs_data_get_json(response));
-
- obs_data_release(response);
+ SendResponse(response);
}
void WSRequestHandler::SendErrorResponse(const char* errorMessage)
@@ -168,9 +171,20 @@ void WSRequestHandler::SendErrorResponse(const char* errorMessage)
obs_data_set_string(response, "error", errorMessage);
obs_data_set_string(response, "message-id", _messageId);
- _client->sendTextMessage(obs_data_get_json(response));
+ SendResponse(response);
+}
+void WSRequestHandler::SendResponse(obs_data_t* response)
+{
+ const char *json = obs_data_get_json(response);
obs_data_release(response);
+
+ if (Config::Current()->DebugEnabled)
+ {
+ blog(LOG_DEBUG, "Response << '%s'", json);
+ }
+
+ _client->sendTextMessage(json);
}
bool WSRequestHandler::hasField(const char* name)
diff --git a/WSRequestHandler.h b/WSRequestHandler.h
index 578f471f..eaf9e563 100644
--- a/WSRequestHandler.h
+++ b/WSRequestHandler.h
@@ -45,6 +45,7 @@ class WSRequestHandler : public QObject
void SendOKResponse(obs_data_t* additionalFields = NULL);
void SendErrorResponse(const char* errorMessage);
+ void SendResponse(obs_data_t* response);
static void HandleGetVersion(WSRequestHandler* req);
static void HandleGetAuthRequired(WSRequestHandler* req);
diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini
index 89cc7c8e..6d95025b 100644
--- a/data/locale/en-US.ini
+++ b/data/locale/en-US.ini
@@ -4,6 +4,7 @@ OBSWebsocket.Settings.ServerEnable="Enable Websocket server"
OBSWebsocket.Settings.ServerPort="Server Port"
OBSWebsocket.Settings.AuthRequired="Enable authentication"
OBSWebsocket.Settings.Password="Password"
+OBSWebsocket.Settings.DebugEnable="Enable debug logging"
OBSWebsocket.ConnectNotify.Connected="New WebSocket connection"
OBSWebsocket.ConnectNotify.Disconnected="WebSocket client disconnected"
OBSWebsocket.ConnectNotify.ClientIP="Client Address:"
\ No newline at end of file
diff --git a/forms/settings-dialog.cpp b/forms/settings-dialog.cpp
index 3729159a..e51eb2f2 100644
--- a/forms/settings-dialog.cpp
+++ b/forms/settings-dialog.cpp
@@ -47,6 +47,8 @@ void SettingsDialog::showEvent(QShowEvent* event)
ui->serverEnabled->setChecked(conf->ServerEnabled);
ui->serverPort->setValue(conf->ServerPort);
+
+ ui->debugEnabled->setChecked(conf->DebugEnabled);
ui->authRequired->setChecked(conf->AuthRequired);
ui->password->setText(CHANGE_ME);
@@ -74,6 +76,8 @@ void SettingsDialog::FormAccepted()
conf->ServerEnabled = ui->serverEnabled->isChecked();
conf->ServerPort = ui->serverPort->value();
+
+ conf->DebugEnabled = ui->debugEnabled->isChecked();
if (ui->authRequired->isChecked())
{
diff --git a/forms/settings-dialog.ui b/forms/settings-dialog.ui
index 108da584..17590b33 100644
--- a/forms/settings-dialog.ui
+++ b/forms/settings-dialog.ui
@@ -7,7 +7,7 @@
0
0
407
- 155
+ 175
@@ -79,6 +79,16 @@
+ -
+
+
+ OBSWebsocket.Settings.DebugEnable
+
+
+ false
+
+
+
-
@@ -103,11 +113,11 @@
248
- 254
+ 274
157
- 274
+ 294
@@ -119,11 +129,11 @@
316
- 260
+ 280
286
- 274
+ 294