swooletw / laravel-swoole

High performance HTTP server based on Swoole. Speed up your Laravel or Lumen applications.
MIT License
4.03k stars 388 forks source link

Socket.io client not work with Websockets implementation out of box #545

Open Forsakenrox opened 1 year ago

Forsakenrox commented 1 year ago

Need update wiki with worked examples, but the problem with websockets is more complex. and even this not help because core protocol of socket.io implemented wrong way. Ping\Pong also not working. The feeling that the implementation of web sockets in this package was abandoned on the half way.

Updated: So, expirience way i found that this websocket implementation work only with socket.io-client version 2.

That what you need to do on the fronted side:

npm i socket.io-client@v2-latest

After that use this code for starting point:

import io from "socket.io-client";
const socket = io("ws://127.0.0.1:1215", {
        // transports: ["websocket"], //if you want force ws: connection instead of initial http:
    });
socket.on("connect", function (event) {
    console.log(event);
});
function handleClick() {
    socket.emit("hello", { text: "i say hey" });
}

I hope this help for anyone. But anyway - wiki must be updated or laravel-swoole package must be updated to actual state.