diff --git a/src/WebSocketServer.cpp b/src/WebSocketServer.cpp index 2001b4bd..cdadb253 100644 --- a/src/WebSocketServer.cpp +++ b/src/WebSocketServer.cpp @@ -79,6 +79,7 @@ void WebSocketServer::Start() } _serverPort = conf->ServerPort; + _serverPassword = conf->ServerPassword; _debugEnabled = conf->DebugEnabled; _authenticationRequired = conf->AuthRequired; _authenticationSalt = Utils::Crypto::GenerateSalt(); @@ -187,10 +188,14 @@ std::vector WebSocketServer::GetWebSocke return webSocketSessions; } -std::string WebSocketServer::GetConnectUrl() +QString WebSocketServer::GetConnectString() { - QString ret = QString("ws://%1:%2").arg(QString::fromStdString(Utils::Platform::GetLocalAddress())).arg(_serverPort); - return ret.toStdString(); + QString ret; + if (_authenticationRequired) + ret = QString("obswebsocket|%1:%2|%3").arg(QString::fromStdString(Utils::Platform::GetLocalAddress())).arg(_serverPort).arg(_serverPassword); + else + ret = QString("obswebsocket|%1:%2").arg(QString::fromStdString(Utils::Platform::GetLocalAddress())).arg(_serverPort); + return ret; } void WebSocketServer::BroadcastEvent(uint64_t requiredIntent, std::string eventType, json eventData) @@ -207,6 +212,7 @@ void WebSocketServer::BroadcastEvent(uint64_t requiredIntent, std::string eventT std::string messageJson; std::string messageMsgPack; + // Recurse connected sessions and send the event to suitable sessions. std::unique_lock lock(_sessionMutex); for (auto & it : _sessions) { if (!it.second.IsIdentified()) diff --git a/src/WebSocketServer.h b/src/WebSocketServer.h index 7b44732e..802e4967 100644 --- a/src/WebSocketServer.h +++ b/src/WebSocketServer.h @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -71,7 +72,7 @@ class WebSocketServer : QObject return &_threadPool; } - std::string GetConnectUrl(); + QString GetConnectString(); public Q_SLOTS: void BroadcastEvent(uint64_t requiredIntent, std::string eventType, json eventData = nullptr); @@ -94,6 +95,7 @@ class WebSocketServer : QObject std::mutex _sessionMutex; std::map> _sessions; uint16_t _serverPort; + QString _serverPassword; bool _debugEnabled; bool _authenticationRequired; std::string _authenticationSecret;