From 0b6ff7f854a44b06061b9188ce27dea4fe2e6b5a Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Tue, 23 Sep 2025 22:00:15 -0700 Subject: [PATCH] disconnect --- app/src/sneaker.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/src/sneaker.ts b/app/src/sneaker.ts index 2ab3fd0..223850d 100644 --- a/app/src/sneaker.ts +++ b/app/src/sneaker.ts @@ -1,13 +1,14 @@ import nose from "./server" -// const SNEAKER_URL = "sneaker-ep2i.onrender.com" -// const SNEAKER_TLS = true -const SNEAKER_URL = "localhost:3100" -const SNEAKER_TLS = false +const SNEAKER_URL = "nose.space" +const SNEAKER_TLS = true +// const SNEAKER_URL = "localhost:3100" +// const SNEAKER_TLS = false type Connection = { subdomain: string ws: any + close: boolean // manual close } const conns: Record = {} @@ -35,6 +36,16 @@ export function sneakers(): string[] { return Object.keys(conns) } +export function disconnectSneaker(app: string): boolean { + if (!sneakers().includes(app) || !conns[app]) + return false + + conns[app].close = true + conns[app].ws.close() + + return true +} + // returns the sneaker subdomain if successful export async function connectSneaker(app: string, subdomain = ""): Promise { if (conns[app]) { @@ -49,8 +60,9 @@ export async function connectSneaker(app: string, subdomain = ""): Promise(res => resolve = res) ws.onclose = e => { + if (!conns[app]?.close) + setTimeout(() => connectSneaker(app, subdomain), 1000) // simple retry delete conns[app] - setTimeout(() => connectSneaker(app, subdomain), 1000) // simple retry } ws.onerror = e => console.error("sneaker error", e) @@ -59,7 +71,7 @@ export async function connectSneaker(app: string, subdomain = ""): Promise