修复下载进度的错误问题

This commit is contained in:
CN-JS-HuiBai
2026-04-09 23:59:32 +08:00
parent be953b1621
commit a33cf44de0
2 changed files with 36 additions and 4 deletions

View File

@@ -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));
}
}
}
}
}
};