20 rtc::WebSocketConfiguration cfg;
21 cfg.pingInterval = std::chrono::milliseconds(1000);
22 cfg.connectionTimeout = std::chrono::milliseconds(0);
23 ws = std::make_shared<rtc::WebSocket>(cfg);
28 nm->pushStatusToast(
"Signaling connected", ImGuiToaster::Level::Good);
30 ws->send(msg::makeAuth(nm->getNetworkPassword(),
32 nm->getMyUniqueId()).dump());
40 ws->onMessage([=](std::variant<rtc::binary, rtc::string> m)
42 if (!std::holds_alternative<rtc::string>(m))
return;
43 this->
onMessage(std::get<rtc::string>(m)); });
48 ws->isClosed() ?
ws->open(norm) : (
ws->close(),
ws->open(norm));
50 catch (
const std::exception& e)
52 std::cout <<
"ws->open: " << e.what() <<
"\n";
61 rtc::WebSocketConfiguration cfg;
62 cfg.pingInterval = std::chrono::milliseconds(1000);
63 cfg.connectionTimeout = std::chrono::milliseconds(0);
64 ws = std::make_shared<rtc::WebSocket>(cfg);
69 if (!nm)
throw std::runtime_error(
"[SignalingClient] NetworkManager Inactive");
72 nm->getMyUniqueId()).dump()); });
74 ws->onMessage([=](std::variant<rtc::binary, rtc::string> m)
76 if (!std::holds_alternative<rtc::string>(m))
return;
77 this->
onMessage(std::get<rtc::string>(m)); });
82 ws->isClosed() ?
ws->open(url) : (
ws->close(),
ws->open(url));
84 catch (
const std::exception& e)
86 std::cout <<
"ws->open: " << e.what() <<
"\n";
102 using json = nlohmann::json;
106 j = json::parse(
msg);
118 throw std::runtime_error(
"NM expired");
124 nm->disconectFromPeers();
137 nm->removePeer(target);
149 const std::string oldPeerId = nm->getMyPeerId();
150 nm->setMyPeerId(newPeerId);
152 if (
auto idm = nm->getIdentityManager())
154 if (!oldPeerId.empty() && oldPeerId != newPeerId)
155 idm->erasePeer(oldPeerId);
157 idm->bindPeer(newPeerId, idm->myUniqueId(), idm->myUsername());
161 const std::string gmUniqueId = j.value(std::string(
msg::key::GmId),
"");
162 if (!gmUniqueId.empty())
164 nm->setGMId(gmUniqueId);
172 std::string peerId = v.get<std::string>();
173 auto link = nm->ensurePeerLink(peerId);
174 link->createChannels();
188 if (from.empty() || sdp.empty() || uniqueId.empty())
191 "Signaling missing fields (from/sdp/uniqueId). Dropping.");
195 auto link = nm->ensurePeerLink(from);
196 nm->upsertPeerIdentityWithUnique(from, uniqueId, username);
198 link->createAnswer();
208 if (from.empty() || sdp.empty() || uniqueId.empty())
211 "Signaling missing fields (from/sdp/uniqueId). Dropping.");
215 auto link = nm->ensurePeerLink(from);
216 nm->upsertPeerIdentityWithUnique(from, uniqueId, username);
226 if (from.empty() || cand.empty())
229 auto link = nm->ensurePeerLink(from);
230 link->addIceCandidate(rtc::Candidate(cand, mid));