mirror of
https://github.com/Shik3i/KoalaSync.git
synced 2026-07-26 12:08:15 +00:00
fix: resolve peer isolation and invitation link sync issues
This commit is contained in:
+25
-2
@@ -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) {
|
||||
|
||||
@@ -315,6 +315,12 @@
|
||||
<p>• Username helps others identify you.</p>
|
||||
<p>• Noise filtering uses a blacklist to hide common non-video sites (e.g. Search, Social Media) from the Target Tab selector.</p>
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 15px; padding: 8px; border-top: 1px solid var(--card);">
|
||||
<label>Troubleshooting</label>
|
||||
<button id="regenId" class="secondary" style="width: 100%; font-size: 11px;">Regenerate Peer ID</button>
|
||||
<p style="font-size: 9px; color: var(--text-muted); margin-top: 5px; text-align: center;">Use this if you see "Duplicate Identity" errors.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Dev Tab -->
|
||||
|
||||
+1
-1
@@ -31,6 +31,7 @@ const elements = {
|
||||
roomInfo: document.getElementById('roomInfo'),
|
||||
inviteLink: document.getElementById('inviteLink'),
|
||||
filterNoise: document.getElementById('filterNoise'),
|
||||
regenId: document.getElementById('regenId'),
|
||||
historyList: document.getElementById('historyList'),
|
||||
copyLogs: document.getElementById('copyLogs'),
|
||||
createRoomBtn: document.getElementById('createRoomBtn'),
|
||||
@@ -42,7 +43,6 @@ const elements = {
|
||||
sectionActive: document.getElementById('section-active'),
|
||||
activeRoomId: document.getElementById('activeRoomId'),
|
||||
activeServer: document.getElementById('activeServer'),
|
||||
peerList: document.getElementById('peerList'),
|
||||
peerListSync: document.getElementById('peerListSync'),
|
||||
videoDebug: document.getElementById('videoDebug'),
|
||||
playBtn: document.getElementById('playBtn'),
|
||||
|
||||
+3
-1
@@ -222,8 +222,10 @@ io.on('connection', (socket) => {
|
||||
if (data.peerId === peerId && sid !== socket.id) {
|
||||
const oldSocket = io.sockets.sockets.get(sid);
|
||||
if (oldSocket) {
|
||||
oldSocket.emit(EVENTS.ERROR, { message: 'Deduplication: Another session with this ID joined. Disconnecting...' });
|
||||
oldSocket.leave(roomId);
|
||||
socketToRoom.delete(sid);
|
||||
oldSocket.disconnect(true);
|
||||
log('DEDUPE', `Kicked old session for peer ${peerId}`);
|
||||
}
|
||||
room.peers.delete(sid);
|
||||
room.peerIds.delete(sid);
|
||||
|
||||
Reference in New Issue
Block a user