101{
102 using json = nlohmann::json;
104 try
105 {
106 j = json::parse(
msg);
107 }
108 catch (...)
109 {
110 return;
111 }
113 if (type.empty())
114 return;
115
117 if (!nm)
118 throw std::runtime_error("NM expired");
119
121 {
123 {
124 nm->disconectFromPeers();
125 }
126 return;
127 }
128
129
131 {
133 if (target.empty())
134 return;
136 {
137 nm->removePeer(target);
138 }
139 return;
140 }
141
143 {
145 {
146
148
149 const std::string oldPeerId = nm->getMyPeerId();
150 nm->setMyPeerId(newPeerId);
151
152 if (auto idm = nm->getIdentityManager())
153 {
154 if (!oldPeerId.empty() && oldPeerId != newPeerId)
155 idm->erasePeer(oldPeerId);
156
157 idm->bindPeer(newPeerId, idm->myUniqueId(), idm->myUsername());
158 }
159
160
161 const std::string gmUniqueId = j.value(std::string(
msg::key::GmId),
"");
162 if (!gmUniqueId.empty())
163 {
164 nm->setGMId(gmUniqueId);
165 }
166
167
169 {
171 {
172 std::string peerId = v.get<std::string>();
173 auto link = nm->ensurePeerLink(peerId);
174 link->createChannels();
175 link->createOffer();
176 }
177 }
178 }
179 return;
180 }
181
183 {
188 if (from.empty() || sdp.empty() || uniqueId.empty())
189 {
191 "Signaling missing fields (from/sdp/uniqueId). Dropping.");
192 return;
193 }
194
195 auto link = nm->ensurePeerLink(from);
196 nm->upsertPeerIdentityWithUnique(from, uniqueId, username);
198 link->createAnswer();
199 return;
200 }
201
203 {
208 if (from.empty() || sdp.empty() || uniqueId.empty())
209 {
211 "Signaling missing fields (from/sdp/uniqueId). Dropping.");
212 return;
213 }
214
215 auto link = nm->ensurePeerLink(from);
216 nm->upsertPeerIdentityWithUnique(from, uniqueId, username);
218 return;
219 }
220
222 {
226 if (from.empty() || cand.empty())
227 return;
228
229 auto link = nm->ensurePeerLink(from);
230 link->addIceCandidate(rtc::Candidate(cand, mid));
231 return;
232 }
233}
static Logger & instance()
constexpr std::string_view Type
constexpr std::string_view Target
constexpr std::string_view GmId
constexpr std::string_view UniqueId
constexpr std::string_view AuthOk
constexpr std::string_view From
constexpr std::string_view Sdp
constexpr std::string_view SdpMid
constexpr std::string_view Candidate
constexpr std::string_view Clients
constexpr std::string_view Username
constexpr std::string_view ClientId
constexpr std::string_view ServerDisconnect
constexpr std::string_view PeerDisconnect
constexpr std::string_view Answer
constexpr std::string_view AuthResponse
constexpr std::string_view Offer
constexpr std::string_view Candidate
constexpr std::string False
constexpr std::string True