Retry when WebSocket connection not established (no onopen event)
Currently, the WebSocket transport retries only when the connection is closed or fails after being established.
However, sometimes the initial WebSocket connection never succeeds — for example, when the browser cannot reach the server (network issue, DNS failure, or dropped SYN). In such cases, the onopen event is never emitted, and the retry logic is never triggered, leaving the app stuck waiting forever.
Here’s the relevant section in the code:
` this._ws.onopen = () => { if (this._closed) return;
wasConnected = true;
// Emit 'open' event.
this.safeEmit('open');
}; `
If the connection attempt never reaches this point (no onopen), there’s currently no mechanism to retry.
💡 Expected behavior
If the WebSocket connection is not established within a reasonable timeout (for example, 5 seconds), the library should automatically retry — just like it already does for onclose or onerror events.
This would make the connection logic more robust in real-world network conditions.
🔍 Example use case
When using this library in the browser, sometimes the WebSocket handshake never completes (e.g., network hiccup or local firewall). Because no open or close event fires, the client stays stuck and never reconnects.
It would be helpful if the library could automatically:
Detect that onopen didn’t fire within N seconds.
Trigger a reconnect attempt (using the same retry logic as in onclose).
This is not entirely true. If the connection is never established due to DNS problem (such as if you try to connect to wss://1.2.3.4:443, then eventually the TCP socket will fail (usually after 3 minutes in Linux/Mac with default kernel TCP settings) and then protoo-client will retry again.
So this feature request is just about adding a max timeout for the connection to happen, otherwise retry again.
I will leave this ticket open but I don't plan to work on this soon. I'll do in next months during a complete refactor.