mirror of
https://github.com/Shik3i/KoalaSync.git
synced 2026-08-29 12:07:09 +00:00
chore: bump version to 1.1.1 and fix self-metadata sync and UI visibility
This commit is contained in:
+38
-7
@@ -518,7 +518,12 @@ function handleServerEvent(event, data) {
|
|||||||
if (!Array.isArray(currentRoom.peers)) currentRoom.peers = [];
|
if (!Array.isArray(currentRoom.peers)) currentRoom.peers = [];
|
||||||
if (data.status === 'joined') {
|
if (data.status === 'joined') {
|
||||||
if (!currentRoom.peers.find(p => (p.peerId || p) === data.peerId)) {
|
if (!currentRoom.peers.find(p => (p.peerId || p) === data.peerId)) {
|
||||||
currentRoom.peers.push({ peerId: data.peerId, username: data.username, tabTitle: data.tabTitle });
|
currentRoom.peers.push({
|
||||||
|
peerId: data.peerId,
|
||||||
|
username: data.username,
|
||||||
|
tabTitle: data.tabTitle,
|
||||||
|
mediaTitle: data.mediaTitle || null
|
||||||
|
});
|
||||||
if (storageInitialized) chrome.storage.session.set({ currentRoom });
|
if (storageInitialized) chrome.storage.session.set({ currentRoom });
|
||||||
chrome.runtime.sendMessage({ type: 'PEER_UPDATE', peers: currentRoom.peers }).catch(() => {});
|
chrome.runtime.sendMessage({ type: 'PEER_UPDATE', peers: currentRoom.peers }).catch(() => {});
|
||||||
}
|
}
|
||||||
@@ -533,10 +538,16 @@ function handleServerEvent(event, data) {
|
|||||||
if (typeof peer === 'object') {
|
if (typeof peer === 'object') {
|
||||||
peer.tabTitle = data.tabTitle;
|
peer.tabTitle = data.tabTitle;
|
||||||
peer.username = data.username;
|
peer.username = data.username;
|
||||||
|
peer.mediaTitle = data.mediaTitle !== undefined ? data.mediaTitle : peer.mediaTitle;
|
||||||
} else {
|
} else {
|
||||||
// Migration: replace string with object
|
// Migration: replace string with object
|
||||||
const idx = currentRoom.peers.indexOf(peer);
|
const idx = currentRoom.peers.indexOf(peer);
|
||||||
currentRoom.peers[idx] = { peerId: data.peerId, username: data.username, tabTitle: data.tabTitle };
|
currentRoom.peers[idx] = {
|
||||||
|
peerId: data.peerId,
|
||||||
|
username: data.username,
|
||||||
|
tabTitle: data.tabTitle,
|
||||||
|
mediaTitle: data.mediaTitle || null
|
||||||
|
};
|
||||||
}
|
}
|
||||||
if (storageInitialized) chrome.storage.session.set({ currentRoom });
|
if (storageInitialized) chrome.storage.session.set({ currentRoom });
|
||||||
chrome.runtime.sendMessage({ type: 'PEER_UPDATE', peers: currentRoom.peers }).catch(() => {});
|
chrome.runtime.sendMessage({ type: 'PEER_UPDATE', peers: currentRoom.peers }).catch(() => {});
|
||||||
@@ -676,14 +687,15 @@ async function handleAsyncMessage(message, sender, sendResponse) {
|
|||||||
protocolVersion: PROTOCOL_VERSION
|
protocolVersion: PROTOCOL_VERSION
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
connect();
|
connect();
|
||||||
}
|
}
|
||||||
|
sendResponse({ status: 'ok' });
|
||||||
} else if (message.type === 'RETRY_CONNECT') {
|
} else if (message.type === 'RETRY_CONNECT') {
|
||||||
reconnectFailed = false;
|
reconnectFailed = false;
|
||||||
reconnectStartTime = null;
|
reconnectStartTime = null;
|
||||||
reconnectDelay = 1000;
|
reconnectDelay = 1000;
|
||||||
connect();
|
connect();
|
||||||
|
sendResponse({ status: 'ok' });
|
||||||
} else if (message.type === 'GET_STATUS') {
|
} else if (message.type === 'GET_STATUS') {
|
||||||
const isConnected = socket && socket.readyState === WebSocket.OPEN && isNamespaceJoined;
|
const isConnected = socket && socket.readyState === WebSocket.OPEN && isNamespaceJoined;
|
||||||
let status = isConnected ? 'connected' : (isConnecting || (socket && socket.readyState === WebSocket.CONNECTING) ? 'connecting' : 'disconnected');
|
let status = isConnected ? 'connected' : (isConnecting || (socket && socket.readyState === WebSocket.CONNECTING) ? 'connecting' : 'disconnected');
|
||||||
@@ -714,6 +726,7 @@ async function handleAsyncMessage(message, sender, sendResponse) {
|
|||||||
});
|
});
|
||||||
addLog('Left Room', 'info');
|
addLog('Left Room', 'info');
|
||||||
chrome.runtime.sendMessage({ type: 'PEER_UPDATE', peers: [] }).catch(() => {});
|
chrome.runtime.sendMessage({ type: 'PEER_UPDATE', peers: [] }).catch(() => {});
|
||||||
|
sendResponse({ status: 'ok' });
|
||||||
} else if (message.type === 'CLEAR_LOGS') {
|
} else if (message.type === 'CLEAR_LOGS') {
|
||||||
logs = [];
|
logs = [];
|
||||||
sendResponse({ status: 'ok' });
|
sendResponse({ status: 'ok' });
|
||||||
@@ -725,6 +738,7 @@ async function handleAsyncMessage(message, sender, sendResponse) {
|
|||||||
if (socket && socket.readyState === WebSocket.OPEN) {
|
if (socket && socket.readyState === WebSocket.OPEN) {
|
||||||
socket.send(`42${JSON.stringify([EVENTS.GET_ROOMS])}`);
|
socket.send(`42${JSON.stringify([EVENTS.GET_ROOMS])}`);
|
||||||
}
|
}
|
||||||
|
sendResponse({ status: 'ok' });
|
||||||
} else if (message.type === 'WEB_JOIN_REQUEST') {
|
} else if (message.type === 'WEB_JOIN_REQUEST') {
|
||||||
const { roomId, password, useCustomServer, serverUrl } = message;
|
const { roomId, password, useCustomServer, serverUrl } = message;
|
||||||
chrome.storage.sync.set({
|
chrome.storage.sync.set({
|
||||||
@@ -751,7 +765,6 @@ async function handleAsyncMessage(message, sender, sendResponse) {
|
|||||||
}
|
}
|
||||||
sendResponse({ status: 'ok' });
|
sendResponse({ status: 'ok' });
|
||||||
});
|
});
|
||||||
return true; // Keep channel open for async getSettings
|
|
||||||
} else if (message.type === 'REGENERATE_ID') {
|
} else if (message.type === 'REGENERATE_ID') {
|
||||||
const newId = self.crypto.randomUUID().substring(0, 8);
|
const newId = self.crypto.randomUUID().substring(0, 8);
|
||||||
chrome.storage.local.set({ peerId: newId }, () => {
|
chrome.storage.local.set({ peerId: newId }, () => {
|
||||||
@@ -760,7 +773,6 @@ async function handleAsyncMessage(message, sender, sendResponse) {
|
|||||||
if (socket) socket.close(); // Force reconnect with new ID
|
if (socket) socket.close(); // Force reconnect with new ID
|
||||||
sendResponse({ peerId: newId });
|
sendResponse({ peerId: newId });
|
||||||
});
|
});
|
||||||
return true;
|
|
||||||
} else if (message.type === 'GET_VIDEO_STATE') {
|
} else if (message.type === 'GET_VIDEO_STATE') {
|
||||||
const { tabId } = message;
|
const { tabId } = message;
|
||||||
if (!tabId) {
|
if (!tabId) {
|
||||||
@@ -774,7 +786,6 @@ async function handleAsyncMessage(message, sender, sendResponse) {
|
|||||||
sendResponse(res);
|
sendResponse(res);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true; // Keep channel open
|
|
||||||
} else if (message.type === 'CONTENT_EVENT') {
|
} else if (message.type === 'CONTENT_EVENT') {
|
||||||
if (sender.tab) {
|
if (sender.tab) {
|
||||||
currentTabId = sender.tab.id;
|
currentTabId = sender.tab.id;
|
||||||
@@ -815,6 +826,7 @@ async function handleAsyncMessage(message, sender, sendResponse) {
|
|||||||
}
|
}
|
||||||
addToHistory(message.action, 'You');
|
addToHistory(message.action, 'You');
|
||||||
emit(message.action, { ...message.payload, peerId });
|
emit(message.action, { ...message.payload, peerId });
|
||||||
|
sendResponse({ status: 'ok' });
|
||||||
} else if (message.type === 'FORCE_SYNC_ACK') {
|
} else if (message.type === 'FORCE_SYNC_ACK') {
|
||||||
if (isForceSyncInitiator) {
|
if (isForceSyncInitiator) {
|
||||||
forceSyncAcks.add(peerId);
|
forceSyncAcks.add(peerId);
|
||||||
@@ -827,6 +839,7 @@ async function handleAsyncMessage(message, sender, sendResponse) {
|
|||||||
} else {
|
} else {
|
||||||
emit(EVENTS.FORCE_SYNC_ACK, { peerId });
|
emit(EVENTS.FORCE_SYNC_ACK, { peerId });
|
||||||
}
|
}
|
||||||
|
sendResponse({ status: 'ok' });
|
||||||
} else if (message.type === 'CMD_ACK') {
|
} else if (message.type === 'CMD_ACK') {
|
||||||
// Content script successfully ran a command. Send ACK back to the initiator.
|
// Content script successfully ran a command. Send ACK back to the initiator.
|
||||||
if (currentCommandSenderId && currentCommandSenderId !== peerId) {
|
if (currentCommandSenderId && currentCommandSenderId !== peerId) {
|
||||||
@@ -836,6 +849,7 @@ async function handleAsyncMessage(message, sender, sendResponse) {
|
|||||||
actionTimestamp: message.actionTimestamp
|
actionTimestamp: message.actionTimestamp
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
sendResponse({ status: 'ok' });
|
||||||
} else if (message.type === 'HEARTBEAT') {
|
} else if (message.type === 'HEARTBEAT') {
|
||||||
if (sender.tab) {
|
if (sender.tab) {
|
||||||
currentTabId = sender.tab.id;
|
currentTabId = sender.tab.id;
|
||||||
@@ -843,10 +857,27 @@ async function handleAsyncMessage(message, sender, sendResponse) {
|
|||||||
}
|
}
|
||||||
// Peer status heartbeat from content script
|
// Peer status heartbeat from content script
|
||||||
getSettings().then(settings => {
|
getSettings().then(settings => {
|
||||||
emit(EVENTS.PEER_STATUS, { ...message.payload, peerId, username: settings.username, tabTitle: currentTabTitle });
|
const statusPayload = { ...message.payload, peerId, username: settings.username, tabTitle: currentTabTitle };
|
||||||
|
emit(EVENTS.PEER_STATUS, statusPayload);
|
||||||
|
|
||||||
|
// Locally update our own metadata so the popup sees it for "YOU"
|
||||||
|
if (currentRoom && currentRoom.peers) {
|
||||||
|
const me = currentRoom.peers.find(p => (p.peerId || p) === peerId);
|
||||||
|
if (me && typeof me === 'object') {
|
||||||
|
me.tabTitle = currentTabTitle;
|
||||||
|
me.username = settings.username;
|
||||||
|
me.mediaTitle = message.payload.mediaTitle;
|
||||||
|
chrome.runtime.sendMessage({ type: 'PEER_UPDATE', peers: currentRoom.peers }).catch(() => {});
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
sendResponse({ status: 'ok' });
|
||||||
} else if (message.type === 'LOG') {
|
} else if (message.type === 'LOG') {
|
||||||
addLog(`[Content] ${message.message}`, message.level || 'info');
|
addLog(`[Content] ${message.message}`, message.level || 'info');
|
||||||
|
sendResponse({ status: 'ok' });
|
||||||
|
} else {
|
||||||
|
// Final fallback to prevent channel hanging
|
||||||
|
sendResponse({ error: 'unhandled_message' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"name": "KoalaSync",
|
"name": "KoalaSync",
|
||||||
"version": "1.1.0",
|
"version": "1.1.1",
|
||||||
"description": "Synchronize video playback across different tabs and users.",
|
"description": "Synchronize video playback across different tabs and users.",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"storage",
|
"storage",
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ async function init() {
|
|||||||
function toggleUIState(inRoom) {
|
function toggleUIState(inRoom) {
|
||||||
if (elements.sectionJoin) elements.sectionJoin.style.display = inRoom ? 'none' : 'block';
|
if (elements.sectionJoin) elements.sectionJoin.style.display = inRoom ? 'none' : 'block';
|
||||||
if (elements.sectionActive) elements.sectionActive.style.display = inRoom ? 'block' : 'none';
|
if (elements.sectionActive) elements.sectionActive.style.display = inRoom ? 'block' : 'none';
|
||||||
|
if (elements.peerListSync) elements.peerListSync.style.display = inRoom ? 'block' : 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateUI(roomId, password, useCustomServer = false, serverUrl = '') {
|
function updateUI(roomId, password, useCustomServer = false, serverUrl = '') {
|
||||||
|
|||||||
Reference in New Issue
Block a user