From 047db29c3489e6aba60dd334fdcc5d4cee43b21c Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 11 Oct 2024 22:36:35 -0700 Subject: clean up invoice subscriptions --- lib/sockets.ts | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib') diff --git a/lib/sockets.ts b/lib/sockets.ts index 4ee8e00e..17c3cb4e 100644 --- a/lib/sockets.ts +++ b/lib/sockets.ts @@ -11,6 +11,7 @@ const users = {}; export const emit = (uid, type, data) => { if (type === "payment" && data.amount > 0) { + console.log("SUBS", subscriptions.length); for (let i = subscriptions.length - 1; i >= 0; i--) { let s = subscriptions[i]; @@ -117,6 +118,7 @@ Bun.serve({ store.sessions[data] = ws; break; case "subscribe": + console.log("SUBBING", data.id); subscriptions.push({ invoice: data, ws }); break; default: @@ -138,6 +140,10 @@ Bun.serve({ delete store.sockets[uid][id]; } + let i; + ~(i = subscriptions.findIndex((s) => s.ws.id === id)) && + subscriptions.splice(i, 1); + if (all[id]) delete all[id]; } catch (e) { err("problem closing socket", e.message); -- cgit v1.2.3