Pārlūkot izejas kodu

fix: Events unsubscribing when used more than once

Owen Diffey 1 gadu atpakaļ
vecāks
revīzija
b18a49fb7f
1 mainītis faili ar 6 papildinājumiem un 3 dzēšanām
  1. 6 3
      frontend/src/stores/websocket.ts

+ 6 - 3
frontend/src/stores/websocket.ts

@@ -51,15 +51,18 @@ export const useWebsocketStore = defineStore("websocket", () => {
 	};
 
 	const unsubscribe = async (channel: string, uuid: string) => {
-		if (!socketChannels.includes(channel))
-			await runJob("api.unsubscribe", { channel });
-
 		if (
 			!subscriptions.value[channel] ||
 			!subscriptions.value[channel][uuid]
 		)
 			return;
 
+		if (
+			!socketChannels.includes(channel) &&
+			Object.keys(subscriptions.value[channel]).length <= 1
+		)
+			await runJob("api.unsubscribe", { channel });
+
 		delete subscriptions.value[channel][uuid];
 
 		if (Object.keys(subscriptions.value[channel]).length === 0)