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

After v1.1.13, phpsocket.io cannot be connected when a browser use WebSocket first #274

Closed
troublezzb opened this issue Feb 24, 2022 · 3 comments

Comments

@troublezzb
Copy link

phpsocket.io v1.1.13
socket.io-client v2.4.0 (Chrome 98.0.4758.102 64bit)

io(window.g.socketUrl, {transports: ['websocket', 'polling']})

The following error occurred in the browser:

WebSocket connection to 'ws://192.168.255.1:4052/socket.io/?EIO=3&transport=websocket' failed:

My Thoughts:
I think this judgment is not handled well.
src/Engine/Engine.php (commit 25243e320bf6b43f11b96974d1a54241dcd07bce)

        if ($transport === 'websocket' && empty($sid)) {
            return call_user_func($fn, self::ERROR_UNKNOWN_TRANSPORT, false, $req, $res);
        }

Interim Solution:
@jichangfeng You can try:

  1. use phpsocket.io v1.1.12
  2. removing the 'transport' attribute.
io(window.g.socketUrl)
  1. watching the ‘connect_error’ event(more).
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"];
});
@walkor walkor closed this as completed in a5758da Feb 24, 2022
@walkor
Copy link
Owner

walkor commented Feb 24, 2022

phpsocket.io v1.1.14 removed the judgment.
Please upgrade.
Sorry for the inconvenience.

@troublezzb
Copy link
Author

troublezzb commented Feb 24, 2022

It works. Thanks for your prompt reply.

@jichangfeng
Copy link
Contributor

Solved. Thanks。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants