mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
base: Various random code nitpicks
This commit is contained in:
parent
886738547a
commit
53d7596160
@ -220,9 +220,8 @@ RequestResult RequestHandler::ProcessRequest(const Request &request)
|
|||||||
std::vector<std::string> RequestHandler::GetRequestList()
|
std::vector<std::string> RequestHandler::GetRequestList()
|
||||||
{
|
{
|
||||||
std::vector<std::string> ret;
|
std::vector<std::string> ret;
|
||||||
for (auto const &[key, val] : _handlerMap) {
|
for (auto const &[key, val] : _handlerMap)
|
||||||
ret.push_back(key);
|
ret.push_back(key);
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -158,9 +158,8 @@ void WebSocketServer::Stop()
|
|||||||
_threadPool.waitForDone();
|
_threadPool.waitForDone();
|
||||||
|
|
||||||
// This can delay the thread that it is running on. Bad but kinda required.
|
// This can delay the thread that it is running on. Bad but kinda required.
|
||||||
while (_sessions.size() > 0) {
|
while (_sessions.size() > 0)
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
}
|
|
||||||
|
|
||||||
_serverThread.join();
|
_serverThread.join();
|
||||||
|
|
||||||
@ -257,7 +256,7 @@ void WebSocketServer::onOpen(websocketpp::connection_hdl hdl)
|
|||||||
json helloMessageData;
|
json helloMessageData;
|
||||||
helloMessageData["obsWebSocketVersion"] = OBS_WEBSOCKET_VERSION;
|
helloMessageData["obsWebSocketVersion"] = OBS_WEBSOCKET_VERSION;
|
||||||
helloMessageData["rpcVersion"] = OBS_WEBSOCKET_RPC_VERSION;
|
helloMessageData["rpcVersion"] = OBS_WEBSOCKET_RPC_VERSION;
|
||||||
if (conf->AuthRequired) {
|
if (session->AuthenticationRequired()) {
|
||||||
session->SetSecret(_authenticationSecret);
|
session->SetSecret(_authenticationSecret);
|
||||||
std::string sessionChallenge = Utils::Crypto::GenerateSalt();
|
std::string sessionChallenge = Utils::Crypto::GenerateSalt();
|
||||||
session->SetChallenge(sessionChallenge);
|
session->SetChallenge(sessionChallenge);
|
||||||
|
@ -82,7 +82,7 @@ void WebSocketServer::ProcessMessage(SessionPtr session, WebSocketServer::Proces
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only `Identify` is allowed when not identified
|
// Only `Identify` is allowed when not identified
|
||||||
if (!session->IsIdentified() && opCode != 1) {
|
if (!session->IsIdentified() && opCode != WebSocketOpCode::Identify) {
|
||||||
ret.closeCode = WebSocketCloseCode::NotIdentified;
|
ret.closeCode = WebSocketCloseCode::NotIdentified;
|
||||||
ret.closeReason = "You attempted to send a non-Identify message while not identified.";
|
ret.closeReason = "You attempted to send a non-Identify message while not identified.";
|
||||||
return;
|
return;
|
||||||
@ -146,9 +146,8 @@ void WebSocketServer::ProcessMessage(SessionPtr session, WebSocketServer::Proces
|
|||||||
session->SetRpcVersion(requestedRpcVersion);
|
session->SetRpcVersion(requestedRpcVersion);
|
||||||
|
|
||||||
SetSessionParameters(session, ret, payloadData);
|
SetSessionParameters(session, ret, payloadData);
|
||||||
if (ret.closeCode != WebSocketCloseCode::DontClose) {
|
if (ret.closeCode != WebSocketCloseCode::DontClose)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// Increment refs for event subscriptions
|
// Increment refs for event subscriptions
|
||||||
auto eventHandler = GetEventHandler();
|
auto eventHandler = GetEventHandler();
|
||||||
@ -178,9 +177,8 @@ void WebSocketServer::ProcessMessage(SessionPtr session, WebSocketServer::Proces
|
|||||||
eventHandler->ProcessUnsubscription(session->EventSubscriptions());
|
eventHandler->ProcessUnsubscription(session->EventSubscriptions());
|
||||||
|
|
||||||
SetSessionParameters(session, ret, payloadData);
|
SetSessionParameters(session, ret, payloadData);
|
||||||
if (ret.closeCode != WebSocketCloseCode::DontClose) {
|
if (ret.closeCode != WebSocketCloseCode::DontClose)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// Increment refs for new subscriptions
|
// Increment refs for new subscriptions
|
||||||
eventHandler->ProcessSubscription(session->EventSubscriptions());
|
eventHandler->ProcessSubscription(session->EventSubscriptions());
|
||||||
@ -377,19 +375,16 @@ void WebSocketServer::BroadcastEvent(uint64_t requiredIntent, const std::string
|
|||||||
// Recurse connected sessions and send the event to suitable sessions.
|
// Recurse connected sessions and send the event to suitable sessions.
|
||||||
std::unique_lock<std::mutex> lock(_sessionMutex);
|
std::unique_lock<std::mutex> lock(_sessionMutex);
|
||||||
for (auto &it : _sessions) {
|
for (auto &it : _sessions) {
|
||||||
if (!it.second->IsIdentified()) {
|
if (!it.second->IsIdentified())
|
||||||
continue;
|
continue;
|
||||||
}
|
if (rpcVersion && it.second->RpcVersion() != rpcVersion)
|
||||||
if (rpcVersion && it.second->RpcVersion() != rpcVersion) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
if ((it.second->EventSubscriptions() & requiredIntent) != 0) {
|
if ((it.second->EventSubscriptions() & requiredIntent) != 0) {
|
||||||
websocketpp::lib::error_code errorCode;
|
websocketpp::lib::error_code errorCode;
|
||||||
switch (it.second->Encoding()) {
|
switch (it.second->Encoding()) {
|
||||||
case WebSocketEncoding::Json:
|
case WebSocketEncoding::Json:
|
||||||
if (messageJson.empty()) {
|
if (messageJson.empty())
|
||||||
messageJson = eventMessage.dump();
|
messageJson = eventMessage.dump();
|
||||||
}
|
|
||||||
_server.send((websocketpp::connection_hdl)it.first, messageJson,
|
_server.send((websocketpp::connection_hdl)it.first, messageJson,
|
||||||
websocketpp::frame::opcode::text, errorCode);
|
websocketpp::frame::opcode::text, errorCode);
|
||||||
it.second->IncrementOutgoingMessages();
|
it.second->IncrementOutgoingMessages();
|
||||||
|
Loading…
Reference in New Issue
Block a user