Older/Server/WebRTC/SignalServer.cpp

37 lines
1.1 KiB
C++
Raw Normal View History

2024-01-24 23:19:53 +08:00
#include "SignalServer.h"
2025-01-10 21:49:22 +08:00
#include "../Application.h"
2025-01-12 00:46:14 +08:00
#include "../HttpSession.h"
#include "BoostLog.h"
#include "WebSocketSignalSession.h"
2025-01-10 21:49:22 +08:00
#include <boost/beast/websocket/rfc6455.hpp>
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)) {
2025-01-12 00:46:14 +08:00
auto ws = std::make_shared<WebSocketSignalSession>(session.releaseSocket(), *this, id);
ws->run(request);
2025-01-10 21:49:22 +08:00
}
});
// clang-format on
}
2024-01-24 23:19:53 +08:00
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) {
2025-01-12 00:46:14 +08:00
WebSocketSignalSession *ret = nullptr;
2024-01-24 23:19:53 +08:00
if (m_clients.contains(id)) {
ret = m_clients.at(id);
}
return ret;
}