From 9f004557edaaf56ea7fac735bbf727759a7210d9 Mon Sep 17 00:00:00 2001 From: Timo <6156589+Shik3i@users.noreply.github.com> Date: Wed, 22 Apr 2026 12:10:26 +0200 Subject: [PATCH] fix: resolve peer isolation and invitation link sync issues --- extension/background.js | 27 +++++++++++++++++++++++++-- extension/popup.html | 6 ++++++ extension/popup.js | 2 +- server/index.js | 4 +++- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/extension/background.js b/extension/background.js index d313830..4e533c5 100644 --- a/extension/background.js +++ b/extension/background.js @@ -409,10 +409,12 @@ function handleServerEvent(event, data) { if (data.status === 'joined') { if (!currentRoom.peers.find(p => (p.peerId || p) === data.peerId)) { currentRoom.peers.push({ peerId: data.peerId, username: data.username, tabTitle: data.tabTitle }); + if (storageInitialized) chrome.storage.session.set({ currentRoom }); chrome.runtime.sendMessage({ type: 'PEER_UPDATE', peers: currentRoom.peers }).catch(() => {}); } } else if (data.status === 'left') { currentRoom.peers = currentRoom.peers.filter(p => (p.peerId || p) !== data.peerId); + if (storageInitialized) chrome.storage.session.set({ currentRoom }); chrome.runtime.sendMessage({ type: 'PEER_UPDATE', peers: currentRoom.peers }).catch(() => {}); } else { // Heartbeat/Update: Update tabTitle for matching @@ -426,6 +428,7 @@ function handleServerEvent(event, data) { const idx = currentRoom.peers.indexOf(peer); currentRoom.peers[idx] = { peerId: data.peerId, username: data.username, tabTitle: data.tabTitle }; } + if (storageInitialized) chrome.storage.session.set({ currentRoom }); chrome.runtime.sendMessage({ type: 'PEER_UPDATE', peers: currentRoom.peers }).catch(() => {}); } } @@ -556,9 +559,29 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { useCustomServer: !!useCustomServer, serverUrl: serverUrl || '' }, () => { - connect(); - // We wait for status update in handleServerEvent + if (socket && socket.readyState === WebSocket.OPEN && isNamespaceJoined) { + // FORCE TRANSITION: Emit Join Room directly if already connected + emit(EVENTS.JOIN_ROOM, { + roomId, + password, + peerId, + username: message.username || '', // Use username if provided by bridge + protocolVersion: PROTOCOL_VERSION + }); + addLog(`Joining room via link: ${roomId}`, 'info'); + } else { + connect(); + } }); + } else if (message.type === 'REGENERATE_ID') { + const newId = self.crypto.randomUUID().substring(0, 8); + chrome.storage.local.set({ peerId: newId }, () => { + peerId = newId; + addLog(`Identity regenerated: ${newId}`, 'success'); + if (socket) socket.close(); // Force reconnect with new ID + sendResponse({ peerId: newId }); + }); + return true; } else if (message.type === 'GET_VIDEO_STATE') { const { tabId } = message; if (!tabId) { diff --git a/extension/popup.html b/extension/popup.html index 1a95e1f..d110c89 100644 --- a/extension/popup.html +++ b/extension/popup.html @@ -315,6 +315,12 @@
• Username helps others identify you.
• Noise filtering uses a blacklist to hide common non-video sites (e.g. Search, Social Media) from the Target Tab selector.
+ +Use this if you see "Duplicate Identity" errors.
+