From d7be269e425c227441d196e53e5d256b8bf49985 Mon Sep 17 00:00:00 2001 From: Pi Lanningham Date: Sat, 14 Dec 2024 12:25:36 -0500 Subject: [PATCH] apply changes in hydra-node.ts too The dedicated server uses a different implementation because of dumb reasons lol --- src/utils/hydra-node.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/utils/hydra-node.ts b/src/utils/hydra-node.ts index 257102c..017394c 100644 --- a/src/utils/hydra-node.ts +++ b/src/utils/hydra-node.ts @@ -58,6 +58,8 @@ export class Hydra { constructor( url: string | URL, filterAddress?: string, + onConnect?: () => void, + onDisconnect?: () => void, public queue_length: number = 10, ) { this.tx_count = 0; @@ -70,19 +72,22 @@ export class Hydra { this.url.protocol = this.url.protocol.replace("ws", "http"); const websocketUrl = new URL(url); websocketUrl.protocol = websocketUrl.protocol.replace("http", "ws"); + console.log(`onConnect: ${!!onConnect}, onDisconnect: ${!!onDisconnect}`); this.connection = new WebSocket( websocketUrl + (websocketUrl.toString().endsWith("/") ? "" : "/") + `?${filterAddress ? `address=${filterAddress}&` : ""}history=no`, ); this.connection.onopen = () => { - console.log("Connected to Hydra"); + console.log("Connected to Hydra, callback: ", !!onConnect); + onConnect?.(); }; this.connection.onerror = (error) => { console.error("Error on Hydra websocket: ", error); }; this.connection.onclose = () => { - console.error("Hydra websocket closed"); + console.error("Hydra websocket closed, callback: ", !!onDisconnect); + onDisconnect?.(); }; this.connection.onmessage = this.receiveMessage.bind(this); }