This commit is contained in:
2026-03-21 09:26:42 +00:00
parent b569cfd5ad
commit 6a4193a3ed
4 changed files with 28 additions and 4 deletions

View File

@@ -67,7 +67,7 @@
<script>
const $ = (id) => document.getElementById(id);
const ws = new WebSocket(`ws://${location.host}`);
const ws = new WebSocket(`${location.protocol === "https:" ? "wss:" : "ws:"}//${location.host}`);
ws.onmessage = (e) => {
const s = JSON.parse(e.data);

View File

@@ -20,6 +20,21 @@ let state = {
connected: false,
};
// --- Helpers ---
/** Recursively convert Map objects (from useMap decode) to plain objects */
function mapToObj(val) {
if (val instanceof Map) {
const obj = {};
for (const [k, v] of val) {
if (typeof k === "string" || typeof k === "number") obj[k] = mapToObj(v);
}
return obj;
}
if (Array.isArray(val)) return val.map(mapToObj);
return val;
}
// --- Wire protocol ---
function buildFrame(msg) {
@@ -60,7 +75,11 @@ function parseFrames(buffer) {
try {
messages.push(decode(payload));
} catch {
// skip malformed msgpack
try {
messages.push(mapToObj(decode(payload, { useMap: true })));
} catch {
// skip truly malformed msgpack
}
}
offset += 8 + len;
}