39
WebRTC/SignalServer.cpp
Normal file
39
WebRTC/SignalServer.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include "SignalServer.h"
|
||||
#include "../Application.h"
|
||||
#include "../HttpSession.h"
|
||||
#include "Core/Logger.h"
|
||||
#include "WebSocketSignalSession.h"
|
||||
#include <boost/beast/websocket/rfc6455.hpp>
|
||||
|
||||
namespace Older {
|
||||
SignalServer::SignalServer(Application &app) {
|
||||
using namespace boost::urls;
|
||||
// clang-format off
|
||||
app.insertUrl("/api/v1/webrtc/signal/{id}", [this](HttpSession &session, const Application::Request &request, const matches &matches) {
|
||||
auto id = matches.at("id");
|
||||
if (boost::beast::websocket::is_upgrade(request)) {
|
||||
auto ws = std::make_shared<WebSocketSignalSession>(session.releaseSocket(), *this, id);
|
||||
ws->run(request);
|
||||
}
|
||||
});
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
void SignalServer::join(const std::string &id, WebSocketSignalSession *client) {
|
||||
m_clients.insert({id, client});
|
||||
}
|
||||
|
||||
void SignalServer::leave(const std::string &id) {
|
||||
if (m_clients.contains(id)) {
|
||||
m_clients.erase(id);
|
||||
}
|
||||
}
|
||||
|
||||
WebSocketSignalSession *SignalServer::client(const std::string &id) {
|
||||
WebSocketSignalSession *ret = nullptr;
|
||||
if (m_clients.contains(id)) {
|
||||
ret = m_clients.at(id);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user