From b8c3731a88f874f5b577bf8ad4357008b1dca5d6 Mon Sep 17 00:00:00 2001 From: Louis Date: Fri, 5 Jul 2024 08:53:29 +0200 Subject: [PATCH] fix: leave_stream --- apps/api/src/app.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/api/src/app.ts b/apps/api/src/app.ts index f17997f..56badc2 100644 --- a/apps/api/src/app.ts +++ b/apps/api/src/app.ts @@ -629,7 +629,9 @@ io.on("connection", (socket) => { io.in(streamId).socketsLeave(streamId); - if (stream.viewerCount === 0) { + const socketCount = await io.in(streamId).fetchSockets(); + + if (stream.viewerCount === 0 && socketCount.length === 0) { streams.delete(streamId); } @@ -690,7 +692,9 @@ io.on("connection", (socket) => { delete socket.data.streamId; - if (stream.viewerCount === 0) { + const socketCount = await io.in(streamId).fetchSockets(); + + if (stream.viewerCount === 0 && socketCount.length === 0) { streams.delete(streamId); }