Spaces:
Sleeping
Sleeping
Update main.cpp
Browse files
main.cpp
CHANGED
|
@@ -303,17 +303,20 @@ private:
|
|
| 303 |
void handle_message(const std::string& raw,
|
| 304 |
std::shared_ptr<collab::Document> doc)
|
| 305 |
{
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
|
|
|
|
|
|
|
|
|
| 317 |
}
|
| 318 |
}
|
| 319 |
|
|
|
|
| 303 |
void handle_message(const std::string& raw,
|
| 304 |
std::shared_ptr<collab::Document> doc)
|
| 305 |
{
|
| 306 |
+
try {
|
| 307 |
+
json msg = json::parse(raw);
|
| 308 |
+
std::string type = msg.value("type", "");
|
| 309 |
+
if (type == "operation") handle_operation(msg, doc);
|
| 310 |
+
else if (type == "cursor") handle_cursor(msg);
|
| 311 |
+
else if (type == "title_change") handle_title_change(msg);
|
| 312 |
+
else if (type == "ping") {
|
| 313 |
+
json pong = msg;
|
| 314 |
+
pong["type"] = "pong";
|
| 315 |
+
enqueue_send(pong.dump());
|
| 316 |
+
}
|
| 317 |
+
} catch (...) {
|
| 318 |
+
// Ignore malformed messages or type errors to prevent crashing
|
| 319 |
+
return;
|
| 320 |
}
|
| 321 |
}
|
| 322 |
|