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> ret;
|
||||
for (auto const &[key, val] : _handlerMap) {
|
||||
for (auto const &[key, val] : _handlerMap)
|
||||
ret.push_back(key);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -158,9 +158,8 @@ void WebSocketServer::Stop()
|
||||
_threadPool.waitForDone();
|
||||
|
||||
// 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));
|
||||
}
|
||||
|
||||
_serverThread.join();
|
||||
|
||||
@ -257,7 +256,7 @@ void WebSocketServer::onOpen(websocketpp::connection_hdl hdl)
|
||||
json helloMessageData;
|
||||
helloMessageData["obsWebSocketVersion"] = OBS_WEBSOCKET_VERSION;
|
||||
helloMessageData["rpcVersion"] = OBS_WEBSOCKET_RPC_VERSION;
|
||||
if (conf->AuthRequired) {
|
||||
if (session->AuthenticationRequired()) {
|
||||
session->SetSecret(_authenticationSecret);
|
||||
std::string sessionChallenge = Utils::Crypto::GenerateSalt();
|
||||
session->SetChallenge(sessionChallenge);
|
||||
|
@ -82,7 +82,7 @@ void WebSocketServer::ProcessMessage(SessionPtr session, WebSocketServer::Proces
|
||||
}
|
||||
|
||||
// Only `Identify` is allowed when not identified
|
||||
if (!session->IsIdentified() && opCode != 1) {
|
||||
if (!session->IsIdentified() && opCode != WebSocketOpCode::Identify) {
|
||||
ret.closeCode = WebSocketCloseCode::NotIdentified;
|
||||
ret.closeReason = "You attempted to send a non-Identify message while not identified.";
|
||||
return;
|
||||
@ -146,9 +146,8 @@ void WebSocketServer::ProcessMessage(SessionPtr session, WebSocketServer::Proces
|
||||
session->SetRpcVersion(requestedRpcVersion);
|
||||
|
||||
SetSessionParameters(session, ret, payloadData);
|
||||
if (ret.closeCode != WebSocketCloseCode::DontClose) {
|
||||
if (ret.closeCode != WebSocketCloseCode::DontClose)
|
||||
return;
|
||||
}
|
||||
|
||||
// Increment refs for event subscriptions
|
||||
auto eventHandler = GetEventHandler();
|
||||
@ -178,9 +177,8 @@ void WebSocketServer::ProcessMessage(SessionPtr session, WebSocketServer::Proces
|
||||
eventHandler->ProcessUnsubscription(session->EventSubscriptions());
|
||||
|
||||
SetSessionParameters(session, ret, payloadData);
|
||||
if (ret.closeCode != WebSocketCloseCode::DontClose) {
|
||||
if (ret.closeCode != WebSocketCloseCode::DontClose)
|
||||
return;
|
||||
}
|
||||
|
||||
// Increment refs for new subscriptions
|
||||
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.
|
||||
std::unique_lock<std::mutex> lock(_sessionMutex);
|
||||
for (auto &it : _sessions) {
|
||||
if (!it.second->IsIdentified()) {
|
||||
if (!it.second->IsIdentified())
|
||||
continue;
|
||||
}
|
||||
if (rpcVersion && it.second->RpcVersion() != rpcVersion) {
|
||||
if (rpcVersion && it.second->RpcVersion() != rpcVersion)
|
||||
continue;
|
||||
}
|
||||
if ((it.second->EventSubscriptions() & requiredIntent) != 0) {
|
||||
websocketpp::lib::error_code errorCode;
|
||||
switch (it.second->Encoding()) {
|
||||
case WebSocketEncoding::Json:
|
||||
if (messageJson.empty()) {
|
||||
if (messageJson.empty())
|
||||
messageJson = eventMessage.dump();
|
||||
}
|
||||
_server.send((websocketpp::connection_hdl)it.first, messageJson,
|
||||
websocketpp::frame::opcode::text, errorCode);
|
||||
it.second->IncrementOutgoingMessages();
|
||||
|
Loading…
Reference in New Issue
Block a user