Skip to content

Commit

Permalink
Add some logging to diagnose disconnect issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Quantumplation committed Dec 14, 2024
1 parent 6cef7e1 commit e6eaed8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/utils/HydraMultiplayer/dedicated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export class HydraMultiplayerDedicated extends HydraMultiplayer {
url: string;
module: EmscriptenModule;
networkId?: number;
onConnect?: () => void;
onDisconnect?: () => void;
onConnect: () => void;
onDisconnect: () => void;
}) {
super({ key, url, module, networkId, onConnect, onDisconnect });
this.address = address;
Expand Down
6 changes: 3 additions & 3 deletions src/utils/hydra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,21 @@ 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);
Expand Down

0 comments on commit e6eaed8

Please sign in to comment.