-
Notifications
You must be signed in to change notification settings - Fork 391
WebSocket client got redundant number in message event data #459
Comments
Well, I never see this before 👀 Have you tried with newer versions of Laravel? |
Not yet, but I'll try when I'm free. |
Thanks for your help! |
I tried, still the same. These are I installed version PHP Version 7.3.12 swooletw/laravel-swoole v2.6.68 |
you should use a client with a socket.io implemention, socket.io-client, as the ws server is compatible with socket.io 2.x by default |
OK, I'll try it later. |
I tried and blocked by CORS policy. |
Are you using a socket.io client as said before? |
I tried all I can do. |
Hi, @ft525 there are several ways to resolve cors problems, you can either use a package called laravel-cors or add clips in nginx which is more effective, here is the full example:
|
Additional, here is a online socket.io client tool for debugging. |
As @solaz3 said, you should inject the headers directly in your nginx before getting them in your code |
OK, I tried. It does work. // server
Websocket::on('connect', function ($websocket, Request $request) {
// called while socket on connect
$websocket->emit('hello', 'Hello ~');
$websocket->emit('message', 'Welcome ~');
}); /*
client (socket.io v2.4)
// Docs
https://socket.io/docs/v2/client-api/#socket-on-eventName-callback
*/
socket.on("connect", function () {
console.log("Connected.");
});
socket.on("message", function (msg) {
console.log("On message.", msg);
});
socket.on("hello", function (arg) {
console.log("On hello.", arg);
}); |
add a |
It is still connected till I disconnect it. |
I found the problem. When I added the option (see below), It did work correctly // client
socket = new io("ws://xxx", {
transports: ["websocket"], // default is ["polling", "websocket"]
}); |
It should use socket.io client v2.x, otherwise fail. You can see the message prompt
|
Please provide your PHP and Swoole version. (
php -v
andphp --ri swoole
)PHP Version 7.3.16
swoole 4.5.7
Please provide your Laravel/Lumen version.
laravel v5.5.48
Which release version of this package are you using?
swooletw/laravel-swoole v2.6.68
What did you do? If possible, provide a recipe for reproducing the error.
What did you expect to see?
The correct format of response. ex. json、array
What did you see instead?
The text was updated successfully, but these errors were encountered: