obs-websocket/src/WebSocketSession.cpp

134 lines
2.6 KiB
C++
Raw Normal View History

2021-04-27 21:52:04 +00:00
#include "WebSocketSession.h"
2021-04-27 23:41:10 +00:00
#include "plugin-macros.generated.h"
2021-04-27 21:52:04 +00:00
WebSocketSession::WebSocketSession() :
_remoteAddress(""),
2021-04-28 18:12:53 +00:00
_connectedAt(0),
2021-04-28 17:40:51 +00:00
_incomingMessages(0),
_outgoingMessages(0),
_encoding(0),
_challenge(""),
_rpcVersion(OBS_WEBSOCKET_RPC_VERSION),
_isIdentified(false),
_ignoreInvalidMessages(false),
_ignoreNonFatalRequestChecks(false),
_eventSubscriptions(0)
2021-04-27 21:52:04 +00:00
{
}
std::string WebSocketSession::RemoteAddress()
{
std::lock_guard<std::mutex> lock(_remoteAddressMutex);
std::string ret(_remoteAddress);
return ret;
}
void WebSocketSession::SetRemoteAddress(std::string address)
{
std::lock_guard<std::mutex> lock(_remoteAddressMutex);
_remoteAddress = address;
}
2021-04-28 18:12:53 +00:00
uint64_t WebSocketSession::ConnectedAt()
{
return _connectedAt.load();
}
void WebSocketSession::SetConnectedAt(uint64_t at);
{
_connectedAt.store(at);
}
2021-04-28 17:40:51 +00:00
uint64_t WebSocketSession::IncomingMessages()
2021-04-28 15:52:23 +00:00
{
2021-04-28 17:40:51 +00:00
return _incomingMessages.load();
2021-04-28 15:52:23 +00:00
}
2021-04-28 17:40:51 +00:00
void WebSocketSession::IncrementIncomingMessages()
2021-04-28 15:52:23 +00:00
{
2021-04-28 17:40:51 +00:00
_incomingMessages++;
2021-04-28 15:52:23 +00:00
}
2021-04-28 17:40:51 +00:00
uint64_t WebSocketSession::OutgoingMessages()
2021-04-27 21:52:04 +00:00
{
2021-04-28 17:40:51 +00:00
return _outgoingMessages.load();
2021-04-27 21:52:04 +00:00
}
2021-04-28 17:40:51 +00:00
void WebSocketSession::IncrementOutgoingMessages()
2021-04-27 21:52:04 +00:00
{
2021-04-28 17:40:51 +00:00
_outgoingMessages++;
2021-04-27 21:52:04 +00:00
}
2021-04-28 17:40:51 +00:00
uint8_t WebSocketSession::GetEncoding()
2021-04-27 21:52:04 +00:00
{
2021-04-28 17:40:51 +00:00
return _encoding.load();
2021-04-27 21:52:04 +00:00
}
2021-04-28 17:40:51 +00:00
void WebSocketSession::SetEncoding(uint8_t encoding)
{
_encoding.store(encoding);
}
std::string WebSocketSession::Challenge()
{
std::lock_guard<std::mutex> lock(_challengeMutex);
std::string ret(_challenge);
return ret;
}
void WebSocketSession::SetChallenge(std::string challengeString)
2021-04-27 21:52:04 +00:00
{
2021-04-28 17:40:51 +00:00
std::lock_guard<std::mutex> lock(_challengeMutex);
_challenge = challengeString;
2021-04-27 21:52:04 +00:00
}
uint8_t WebSocketSession::RpcVersion()
{
2021-04-28 17:40:51 +00:00
return _rpcVersion.load();
2021-04-27 21:52:04 +00:00
}
void WebSocketSession::SetRpcVersion(uint8_t version)
{
2021-04-28 17:40:51 +00:00
_rpcVersion.store(version);
2021-04-27 21:52:04 +00:00
}
bool WebSocketSession::IsIdentified()
{
2021-04-28 17:40:51 +00:00
return _isIdentified.load();
2021-04-27 21:52:04 +00:00
}
void WebSocketSession::SetIsIdentified(bool identified)
{
2021-04-28 17:40:51 +00:00
_isIdentified.store(identified);
2021-04-27 21:52:04 +00:00
}
bool WebSocketSession::IgnoreInvalidMessages()
{
2021-04-28 17:40:51 +00:00
return _ignoreInvalidMessages.load();
2021-04-27 21:52:04 +00:00
}
void WebSocketSession::SetIgnoreInvalidMessages(bool ignore)
{
2021-04-28 17:40:51 +00:00
_ignoreInvalidMessages.store(ignore);
2021-04-27 21:52:04 +00:00
}
bool WebSocketSession::IgnoreNonFatalRequestChecks()
{
2021-04-28 17:40:51 +00:00
return _ignoreNonFatalRequestChecks.load();
2021-04-27 21:52:04 +00:00
}
void WebSocketSession::SetIgnoreNonFatalRequestChecks(bool ignore)
{
2021-04-28 17:40:51 +00:00
_ignoreNonFatalRequestChecks.store(ignore);
2021-04-27 21:52:04 +00:00
}
uint64_t WebSocketSession::EventSubscriptions()
{
2021-04-28 17:40:51 +00:00
return _eventSubscriptions.load();
2021-04-27 21:52:04 +00:00
}
void WebSocketSession::SetEventSubscriptions(uint64_t subscriptions)
{
2021-04-28 17:40:51 +00:00
_eventSubscriptions.store(subscriptions);
2021-04-27 21:52:04 +00:00
}