diff options
| author | Adam Soltys <[email protected]> | 2026-02-10 15:28:58 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-02-24 12:05:28 -0800 |
| commit | 4d8b4053abed3a44c2f4d52b1feafff21557774a (patch) | |
| tree | 768d68fa513f33b64ab795bc4052adffc9224e54 | |
| parent | b1e3435613ef092d43353d511b632a8de64efc5d (diff) | |
| download | coinos-server-4d8b4053abed3a44c2f4d52b1feafff21557774a.tar.gz coinos-server-4d8b4053abed3a44c2f4d52b1feafff21557774a.zip | |
migration script fixes
| -rw-r--r-- | lib/sockets.ts | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/lib/sockets.ts b/lib/sockets.ts index 028551ed..2e1c98e9 100644 --- a/lib/sockets.ts +++ b/lib/sockets.ts @@ -1,7 +1,7 @@ import store from "$lib/store"; import jwt from "jsonwebtoken"; import { v4 } from "uuid"; -import { err, warn } from "$lib/logging"; +import { err, l, warn } from "$lib/logging"; import { fail, getUser } from "$lib/utils"; const code = 1000; @@ -10,21 +10,39 @@ const subscriptions = []; const users = {}; export const emit = (uid, type, data) => { + let sent = 0; + if (type === "payment" && data.amount > 0) { for (let i = subscriptions.length - 1; i >= 0; i--) { const s = subscriptions[i]; if (s.invoice && s.invoice.id === data.iid) { - s.ws.send(JSON.stringify({ type, data })); + try { + s.ws.send(JSON.stringify({ type, data })); + sent++; + } catch (e) { + warn("emit subscription send failed", e.message); + } } } } - if (!store.sockets[uid]) return; + if (!store.sockets[uid]) { + if (type === "payment") l(`emit: no sockets for ${uid}, subscriptions sent: ${sent}`); + return; + } + for (const id in store.sockets[uid]) { const ws = store.sockets[uid][id]; - ws.send(JSON.stringify({ type, data })); + try { + ws.send(JSON.stringify({ type, data })); + sent++; + } catch (e) { + warn("emit socket send failed", e.message); + } } + + if (type === "payment") l(`emit: payment sent to ${sent} clients for ${uid}`); }; export const broadcast = (type, data) => { |
