WebSocketServer: Add GetWebSocketSessions() logic

This commit is contained in:
tt2468 2021-04-28 11:28:07 -07:00
parent 3d43bd525b
commit 5348c80aa8
2 changed files with 16 additions and 3 deletions

View File

@ -1,6 +1,7 @@
#include <chrono>
#include <thread>
#include <QtConcurrent>
#include <QDateTime>
#include "WebSocketServer.h"
#include "obs-websocket.h"
@ -126,9 +127,21 @@ void WebSocketServer::InvalidateSession(websocketpp::connection_hdl hdl)
_server.close(hdl, WebSocketCloseCode::SessionInvalidated, "Your session has been invalidated.");
}
std::vector<WebSocketServer::WebSocketState> WebSocketServer::GetWebSocketSessions()
std::vector<WebSocketServer::WebSocketSessionState> WebSocketServer::GetWebSocketSessions()
{
std::vector<WebSocketServer::WebSocketState> webSocketSessions;
std::vector<WebSocketServer::WebSocketSessionState> webSocketSessions;
std::unique_lock<std::mutex> lock(_sessionMutex);
for (auto & [hdl, session] : _sessions) {
uint64_t connectedAt = session.ConnectedAt();
uint64_t incomingMessages = session.IncomingMessages();
uint64_t outgoingMessages = session.OutgoingMessages();
std::string remoteAddress = session.RemoteAddress();
webSocketSessions.emplace_back(WebSocketSessionState{hdl, remoteAddress, connectedAt, incomingMessages, outgoingMessages});
}
lock.unlock();
return webSocketSessions;
}

View File

@ -35,7 +35,7 @@ uint64_t WebSocketSession::ConnectedAt()
return _connectedAt.load();
}
void WebSocketSession::SetConnectedAt(uint64_t at);
void WebSocketSession::SetConnectedAt(uint64_t at)
{
_connectedAt.store(at);
}