diff --git a/static/whiteboard.js b/static/whiteboard.js index daacd13..a48cf63 100644 --- a/static/whiteboard.js +++ b/static/whiteboard.js @@ -23,10 +23,13 @@ // ---------- 状态 ---------- let ws = null; - let clientId = localStorage.getItem("wb_cid") || ""; + // 每个 tab 独立的 client_id(用 sessionStorage 而非 localStorage,避免同浏览器 + // 多 tab 共享 id 导致收到的 update 被误判为「自己的」而跳过不同步)。 + // 服务端已用 exclude=conn 排除发送者,前端不再用 client_id 跳过 update。 + let clientId = sessionStorage.getItem("wb_cid") || ""; if (!clientId) { clientId = "c_" + Math.random().toString(36).slice(2, 10); - localStorage.setItem("wb_cid", clientId); + sessionStorage.setItem("wb_cid", clientId); } let heartbeatTimer = null; let reconnectTimer = null; @@ -171,7 +174,7 @@ case "pong": break; case "update": - if (msg.client_id === clientId) break; // 自己的,已本地更新 + // 服务端 broadcast 已用 exclude=conn 排除发送者,收到即他人编辑,直接应用。 applyRemoteUpdate(msg.content || ""); flashStatus("对方有更新"); break;