From a33cf44de032ef0beffb4be226bca38d6c04b2d1 Mon Sep 17 00:00:00 2001 From: CN-JS-HuiBai Date: Thu, 9 Apr 2026 23:59:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8B=E8=BD=BD=E8=BF=9B?= =?UTF-8?q?=E5=BA=A6=E7=9A=84=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/main.js | 15 +++++++++++++++ server.js | 25 +++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/public/js/main.js b/public/js/main.js index 6cc5792..216ff3e 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -899,6 +899,15 @@ document.addEventListener('DOMContentLoaded', () => { } resetPhases(); + // Reset subtitle selector before subscribing to ensure we use the base key for source download + if (subtitleSelector) { + subtitleSelector.innerHTML = ''; + subtitleSelector.value = "-1"; + } + if (subtitlePanel) { + subtitlePanel.classList.add('hidden'); + } + selectedKey = key; currentVideoKey = key; subscribeToKey(key); @@ -906,6 +915,12 @@ document.addEventListener('DOMContentLoaded', () => { nowPlaying.classList.remove('hidden'); currentVideoTitle.textContent = key.split('/').pop(); + // If download is needed, show the overlay so the user sees the progress + if (!hasDownloadCache) { + transcodingOverlay.classList.remove('hidden'); + showDownloadPhase(); + } + // Fetch subtitle metadata fetchVideoMetadata(selectedBucket, key); }; diff --git a/server.js b/server.js index 8c86b20..2b1a60e 100644 --- a/server.js +++ b/server.js @@ -192,12 +192,29 @@ const removeWsClient = (ws) => { }; const broadcastWs = (key, payload) => { + // Broadcast to the specific room const clients = wsSubscriptions.get(key); - if (!clients) return; const message = JSON.stringify(payload); - for (const client of clients) { - if (client.readyState === WebSocket.OPEN) { - client.send(message); + if (clients) { + for (const client of clients) { + if (client.readyState === WebSocket.OPEN) { + client.send(message); + } + } + } + + // If this is a base key (not a sub-key), also broadcast to all its sub-keys + if (!key.includes('-sub')) { + for (const [subKey, subClients] of wsSubscriptions.entries()) { + if (subKey.startsWith(`${key}-sub`)) { + for (const client of subClients) { + if (client.readyState === WebSocket.OPEN) { + // We need to keep the payload key matching the room key for filtering on the client side + const subPayload = { ...payload, key: subKey }; + client.send(JSON.stringify(subPayload)); + } + } + } } } };