-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Won't switch to polling transport when Websocket transport failed #5122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi! The order in the const socket = io("https://example.com", {
transports: ["websocket", "polling"] // use WebSocket first, if available
});
socket.on("connect_error", () => {
// revert to classic upgrade
socket.io.opts.transports = ["polling", "websocket"];
}); Reference: https://socket.io/docs/v4/client-options/#transports |
@darrachequesne okay, so if Websocket is blocked by proxy and unable to connect, shouldn't it switch to polling? |
Anything? What's the point of having multiple transports if automatic switching doesn't work? |
When setting the `tryAllTransports` option to `true`, if the first transport (usually, HTTP long-polling) fails, then the other transports will be tested too. This is useful in two cases: > when HTTP long-polling is disabled on the server, or if CORS fails Related: - https://github.com/socketio/engine.io-client/issues/575 - https://github.com/socketio/socket.io-client/issues/1448 > when WebSocket is tested first (`transports: ["websocket", "polling"]) Related: - https://github.com/socketio/engine.io-client/issues/714 - https://github.com/socketio/socket.io-client/issues/1599 The only potential downside is that the connection attempt could take more time in case of failure, as there have been reports of WebSocket connection errors taking several seconds before being detected (that's one reason for using HTTP long-polling first). That's why the option defaults to `false` for now.
For future readers: The import { io } from "socket.io-client";
const socket = io({
tryAllTransports: true
}); Reference: https://socket.io/docs/v4/client-options/#transports Implemented in socketio/engine.io-client@579b243, included in |
Describe the bug
I'm trying to connect with
websocket
transport first and if it fails I was hoping socketio would switch to long-polling. But for some reason, it keeps reconnecting withwebsocket
transport and never switches to polling.To Reproduce
Socket.IO server version:
4.7.2
Server
Socket.IO client version:
4.7.2
Client
Expected behavior
Was expecting the transport would switch to long-polling when websocket isn't available.
Platform:
Additional context
I disabled websocket by blocking websocket calls using the Firefox request blocking feature. Can be disabled using this TamperMonkey script as well.
The text was updated successfully, but these errors were encountered: