6#include "nlohmann/json.hpp"
67 type_str =
"Snapshot_GameTable";
70 type_str =
"Snapshot_Board";
73 type_str =
"CommitMarker";
76 type_str =
"CommitBoard";
79 type_str =
"ImageChunk";
82 type_str =
"MarkerCreate";
85 type_str =
"MarkerUpdate";
88 type_str =
"MarkerDelete";
91 type_str =
"FogCreate";
94 type_str =
"FogUpdate";
97 type_str =
"FogDelete";
100 type_str =
"GridUpdate";
103 type_str =
"NoteCreate";
106 type_str =
"NoteUpdate";
109 type_str =
"NoteDelete";
112 type_str =
"ChatThreadCreate";
115 type_str =
"ChatThreadUpdate";
118 type_str =
"ChatThreadDelete";
121 type_str =
"ChatMessage";
124 type_str =
"MarkerMove";
127 type_str =
"MarkerMoveState";
130 type_str =
"UserNameUpdate";
133 type_str =
"UnkownType";
176 std::optional<Position>
pos;
178 std::optional<Visibility>
vis;
180 std::optional<std::string>
name;
181 std::optional<std::vector<uint8_t>>
bytes;
186 std::optional<uint64_t>
ts;
187 std::optional<std::string>
text;
190 std::optional<Moving>
mov;
196 std::optional<uint32_t>
seq;
229 inline constexpr std::string_view Type =
"type";
230 inline constexpr std::string_view
From =
"from";
231 inline constexpr std::string_view
To =
"to";
232 inline constexpr std::string_view
Broadcast =
"broadcast";
234 inline constexpr std::string_view
Text =
"text";
235 inline constexpr std::string_view
Clients =
"clients";
236 inline constexpr std::string_view
Event =
"event";
237 inline constexpr std::string_view
Username =
"username";
238 inline constexpr std::string_view
ClientId =
"clientId";
239 inline constexpr std::string_view
Target =
"target";
240 inline constexpr std::string_view
GmId =
"gmId";
242 inline constexpr std::string_view
Sdp =
"sdp";
243 inline constexpr std::string_view
Candidate =
"candidate";
244 inline constexpr std::string_view
SdpMid =
"sdpMid";
248 inline constexpr std::string_view
UniqueId =
"uniqueId";
249 inline constexpr std::string_view
AuthOk =
"ok";
250 inline constexpr std::string_view
AuthMsg =
"msg";
252 inline constexpr std::string_view
Password =
"password";
255 inline constexpr std::string_view
Label =
"label";
256 inline constexpr std::string_view
Payload =
"payload";
257 inline constexpr std::string_view
EntityId =
"entityId";
258 inline constexpr std::string_view
X =
"x";
259 inline constexpr std::string_view
Y =
"y";
260 inline constexpr std::string_view
Z =
"z";
261 inline constexpr std::string_view
Visible =
"visible";
262 inline constexpr std::string_view
ImageId =
"imageId";
265 inline constexpr std::string_view
Chunk =
"chunk";
271 inline constexpr std::string_view
Join =
"join";
272 inline constexpr std::string_view
Offer =
"offer";
273 inline constexpr std::string_view
Answer =
"answer";
274 inline constexpr std::string_view
Presence =
"presence";
275 inline constexpr std::string_view
Candidate =
"candidate";
276 inline constexpr std::string_view
Ping =
"ping";
277 inline constexpr std::string_view
Pong =
"pong";
278 inline constexpr std::string_view
Auth =
"auth";
280 inline constexpr std::string_view
Text =
"text";
287 inline constexpr std::string
False =
"false";
288 inline constexpr std::string
True =
"true";
297 inline constexpr std::string
Game =
"game";
298 inline constexpr std::string
Chat =
"chat";
299 inline constexpr std::string
Notes =
"notes";
311 return "ChatGroupCreate";
313 return "ChatGroupUpdate";
315 return "ChatGroupDelete";
317 return "ChatMessage";
324 if (s ==
"ChatGroupCreate")
329 if (s ==
"ChatGroupUpdate")
334 if (s ==
"ChatGroupDelete")
339 if (s ==
"ChatMessage")
350 inline constexpr std::string_view Type =
"type";
351 inline constexpr std::string_view
TableId =
"tableId";
352 inline constexpr std::string_view
GroupId =
"groupId";
353 inline constexpr std::string_view
Name =
"name";
354 inline constexpr std::string_view
Parts =
"participants";
355 inline constexpr std::string_view
Ts =
"ts";
356 inline constexpr std::string_view
Username =
"username";
357 inline constexpr std::string_view
Text =
"text";
367 const std::string& name,
368 const std::set<std::string>& participants)
376 for (
auto& p : participants)
382 const std::string& name,
383 const std::set<std::string>& participants)
391 for (
auto& p : participants)
405 uint64_t ts,
const std::string& username,
406 const std::string& text)
418 const std::string& sdp,
const std::string& username,
419 const std::string& uniqueId,
434 const std::string& sdp,
const std::string& username,
435 const std::string& uniqueId,
468 return nlohmann::json{
496 const std::string& username,
497 const std::string& uniqueId)
507 const std::string& clientId,
const std::string& username,
508 const std::vector<std::string>& clients = {},
509 const std::string& gmPeerId =
"",
510 const std::string& uniqueId =
"")
512 auto j = nlohmann::json{
518 if (!clients.empty())
520 if (!gmPeerId.empty())
522 if (!uniqueId.empty())
561 inline Json makeText(
const std::string& from,
const std::string& to,
const std::string& text,
bool broadcast =
false)
574 auto it = j.find(std::string(
key::Type));
575 return it != j.end() && it->is_string() && it->get_ref<
const std::string&>() == t;
579 inline std::string
getString(
const Json& j, std::string k, std::string def = {})
581 auto it = j.find(std::string(k));
582 return (it != j.end() && it->is_string()) ? it->get<std::string>() : std::move(def);
586 auto it = j.find(std::string(k));
587 return (it != j.end() && it->is_number_integer()) ? it->get<
int>() : def;
589 inline bool getBool(
const Json& j, std::string k,
bool def =
false)
591 auto it = j.find(std::string(k));
592 return (it != j.end() && it->is_boolean()) ? it->get<
bool>() : def;
constexpr std::string_view Ts
constexpr std::string_view Username
constexpr std::string_view Name
constexpr std::string_view Text
constexpr std::string_view Type
constexpr std::string_view Parts
constexpr std::string_view TableId
constexpr std::string_view GroupId
constexpr std::string Chat
constexpr std::string Game
constexpr std::string MarkerMove
constexpr std::string_view AuthToken
constexpr std::string_view Payload
constexpr std::string_view ImageId
constexpr std::string_view BytesTotal
constexpr std::string_view Type
constexpr std::string_view Y
constexpr std::string_view Event
constexpr std::string_view Target
constexpr std::string_view GmId
constexpr std::string_view To
constexpr std::string_view X
constexpr std::string_view EntityId
constexpr std::string_view UniqueId
constexpr std::string_view AuthOk
constexpr std::string_view From
constexpr std::string_view Sdp
constexpr std::string_view Chunk
constexpr std::string_view BytesOffset
constexpr std::string_view SdpMid
constexpr std::string_view Timestamp
constexpr std::string_view AuthMsg
constexpr std::string_view Z
constexpr std::string_view Visible
constexpr std::string_view Password
constexpr std::string_view Candidate
constexpr std::string_view Clients
constexpr std::string_view Username
constexpr std::string_view Text
constexpr std::string_view ClientId
constexpr std::string_view Broadcast
constexpr std::string_view Label
constexpr std::string_view ServerDisconnect
constexpr std::string_view PeerDisconnect
constexpr std::string_view Text
constexpr std::string_view Join
constexpr std::string_view Answer
constexpr std::string_view AuthResponse
constexpr std::string_view Ping
constexpr std::string_view Offer
constexpr std::string_view Pong
constexpr std::string_view Auth
constexpr std::string_view Presence
constexpr std::string_view Candidate
constexpr std::string False
constexpr std::string True
bool DCTypeFromJson(std::string_view s, DCType &out)
Json makeChatMessage(uint64_t tableId, uint64_t groupId, uint64_t ts, const std::string &username, const std::string &text)
Json makePing(const std::string &from)
Json makeOffer(const std::string &from, const std::string &to, const std::string &sdp, const std::string &username, const std::string &uniqueId, const std::string &broadcast=msg::value::False)
Json makeChatGroupUpdate(uint64_t tableId, uint64_t groupId, const std::string &name, const std::set< std::string > &participants)
Json makeBroadcastShutdown()
bool getBool(const Json &j, std::string k, bool def=false)
std::string getString(const Json &j, std::string k, std::string def={})
Json makePresence(const std::string &event, const std::string &clientId)
Json makeText(const std::string &from, const std::string &to, const std::string &text, bool broadcast=false)
nlohmann::json makePeerDisconnect(const std::string &targetPeerId, bool broadcast=true)
nlohmann::json makeAuthResponse(const std::string ok, const std::string &msg, const std::string &clientId, const std::string &username, const std::vector< std::string > &clients={}, const std::string &gmPeerId="", const std::string &uniqueId="")
Json makeCandidate(const std::string &from, const std::string &to, const std::string &cand, const std::string &broadcast=msg::value::False)
Json makeChatGroupCreate(uint64_t tableId, uint64_t groupId, const std::string &name, const std::set< std::string > &participants)
int getInt(const Json &j, std::string k, int def=0)
Json makeAnswer(const std::string &from, const std::string &to, const std::string &sdp, const std::string &username, const std::string &uniqueId, const std::string &broadcast=msg::value::False)
std::string DCtypeString(DCType type)
const char * DCTypeToJson(DCType t)
Json makeAuth(const std::string &token, const std::string &username, const std::string &uniqueId)
bool isType(const Json &j, std::string t)
Json makeChatGroupDelete(uint64_t tableId, uint64_t groupId)
std::vector< uint8_t > bytes
std::optional< uint8_t > rebound
std::optional< MarkerMeta > markerMeta
std::optional< uint64_t > fogId
std::optional< Visibility > vis
std::optional< std::vector< uint8_t > > bytes
std::optional< uint64_t > markerId
std::optional< Role > senderRole
std::optional< MarkerComponent > markerComp
std::optional< Moving > mov
std::optional< Position > pos
std::optional< std::string > text
std::optional< Grid > grid
std::optional< std::string > userUniqueId
std::optional< uint32_t > dragEpoch
std::optional< uint32_t > seq
std::optional< BoardMeta > boardMeta
std::optional< uint64_t > ts
std::optional< uint64_t > boardId
std::optional< Size > size
std::optional< uint64_t > threadId
std::optional< std::string > name
std::optional< std::set< std::string > > participants
std::optional< uint64_t > tableId