Skip to content
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

[Browser] Doesn't switch to polling when WebSocket is undefined. #714

Open
hassansin opened this issue Nov 16, 2023 · 0 comments
Open

[Browser] Doesn't switch to polling when WebSocket is undefined. #714

hassansin opened this issue Nov 16, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@hassansin
Copy link

hassansin commented Nov 16, 2023

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 message timeout from websocket transport.

Tried to investigate and it looks like transport switching only works if createTransport method throws here:

try {
transport = this.createTransport(transport);
} catch (e) {
debug("error while creating transport: %s", e);
this.transports.shift();
this.open();
return;
}

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

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:

  • Device: Chrome 119.0.6045
  • OS: Windows

Additional context
Add any other context about the problem here.

@hassansin hassansin added the bug Something isn't working label Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant