From b333cb1dba63378e6f8b19e1342c4bc04267e33b Mon Sep 17 00:00:00 2001 From: Chase Moskal Date: Fri, 8 Nov 2024 14:23:38 -0800 Subject: [PATCH] wip: troubleshooting, add logging --- s/browser/api.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/s/browser/api.ts b/s/browser/api.ts index 32eda4e..5852356 100644 --- a/s/browser/api.ts +++ b/s/browser/api.ts @@ -35,6 +35,7 @@ export function makeBrowserApi({ const attempts = new Map2() function destroy(attemptId: string) { + console.log("destroy", attemptId) const attempt = attempts.get(attemptId) if (!attempt) return attempts.delete(attemptId) @@ -64,9 +65,12 @@ export function makeBrowserApi({ async function maybeAttempt(attemptId: string, fn: (attempt: Attempt) => Promise) { try { const attempt = attempts.get(attemptId) - return (attempt) - ? await fn(attempt) - : undefined + if (attempt) { + return await fn(attempt) + } + else { + console.log("maybe attempt: did not find", attemptId) + } } catch (error) { destroy(attemptId) @@ -169,6 +173,7 @@ export function makeBrowserApi({ peer, cable, disconnect: () => { + console.log("connection.disconnect() called") conduit.send("bye") died() }, @@ -177,15 +182,16 @@ export function makeBrowserApi({ const disconnected = attempt.connected(connection) function died() { + console.log("DIED") destroy(attemptId) disconnected() } - attempt.prospect.onFailed(died) - ev(peer, {connectionstatechange: () => { - if (peer.connectionState === "closed" || peer.connectionState === "failed") + if (peer.connectionState === "closed" || peer.connectionState === "failed") { + console.log("PEER REMOTELY CLOSED (connectionstatechange)") died() + } }}) conduit.onmessage = event => {