We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I have set my transports to use WebSocket first and then fallback to polling e.g. transports: ["websocket", "polling"].
transports: ["websocket", "polling"]
To test if the fallback transport really works, I used TamperMonkey browser extension to disable Websocket by setting WebSocket = void 0.
WebSocket = void 0
Instead of switching to polling, I keep getting connect_error with the message timeout from websocket transport.
connect_error
timeout
Tried to investigate and it looks like transport switching only works if createTransport method throws here:
createTransport
https://github.com/socketio/engine.io-client/blob/fa479164251dd1f283dd163143b546582161339a/lib/socket.ts#L467-L474
But the method always returns a transport wrapper class, even when WebSocket is not defined.
WebSocket
To Reproduce
Engine.IO server version: 6.5.2
6.5.2
Server
const engine = require("engine.io"); const server = engine.listen(3000, { transports: ["polling", "websocket"] }); server.on("connection", (socket) => { console.log("connection"); socket.on("message", (data) => { console.log("data", data); }); socket.on("close", () => { console.log("close"); }); });
Engine.IO client version: 6.5.2
Client
const socket = require("engine.io-client")("ws://localhost:3000", { transports: ["websocket", "polling"] }); socket.on("open", () => { console.log("open"); socket.on("message", (data) => { console.log("data", data); }); socket.on("close", () => { console.log("close"); }); });
Expected behavior
Should be able to fallback to polling transport when WebSocket transport is disabled on the browser.
Platform:
Additional context Add any other context about the problem here.
The text was updated successfully, but these errors were encountered:
feat: add the ability to test all transports
579b243
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 tryAllTransports option let the client test all transports instead of just the first one:
tryAllTransports
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 [email protected] and [email protected].
[email protected]
Sorry, something went wrong.
No branches or pull requests
I have set my transports to use WebSocket first and then fallback to polling e.g.
transports: ["websocket", "polling"]
.To test if the fallback transport really works, I used TamperMonkey browser extension to disable Websocket by setting
WebSocket = void 0
.Instead of switching to polling, I keep getting
connect_error
with the messagetimeout
from websocket transport.Tried to investigate and it looks like transport switching only works if
createTransport
method throws here:https://github.com/socketio/engine.io-client/blob/fa479164251dd1f283dd163143b546582161339a/lib/socket.ts#L467-L474
But the method always returns a transport wrapper class, even when
WebSocket
is not defined.To Reproduce
Engine.IO server version:
6.5.2
Server
Engine.IO client version:
6.5.2
Client
Expected behavior
Should be able to fallback to polling transport when WebSocket transport is disabled on the browser.
Platform:
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: