What is meant by Error 1006?

When a WebSocket connection is closed without a "close frame", the pusher-js library emits an error with code 1006. Usually this is caused by WebSocket-incompatible proxies, which can't close the connection in the correct way.

See: https://developer.mozilla.org/en-US/docs/WebSockets/WebSockets_reference

How does pusher-js deal with such scenarios?

Pusher's JavaScript client uses two strategies to maintain a working connection.

Lower the heartbeat interval

A "Heartbeat" is a small message that is exchanged by clients and servers to check whether connections are still open and working.

Some proxies might terminate connections because there isn't any data sent in either direction. To counteract such behaviour, after getting an 1006 close code, the heartbeat interval is lowered to half the lifespan of the last connection (minimum 10s, maximum 120s).

This way, connections are kept active all the time and proxies might stop disconnecting them.

Disable WebSockets

When pusher-js detects that two WebSocket connections failed after less than a few minutes, it decides to disable WebSocket-based transports (including Flash) and fall back to HTTP. This way clients won't waste any more time trying to use a broken transport. Additionally, pusher-js remembers last successful transport, so after refreshing the page, it will jump straight to the HTTP fallback.

Was this article helpful?
2 out of 2 found this helpful
Haven't found what you were looking for?
Submit a ticket