beyondcode / laravel-websockets

Websockets for Laravel. Done right.
https://beyondco.de/docs/laravel-websockets
MIT License
5.07k stars 612 forks source link

Websockets not working with pusher-php-server 7.2 #1041

Closed szabrzyski closed 1 year ago

szabrzyski commented 1 year ago

Hello, after pusher-php-server has been updated to version 7.2 websockets stopped working. I'm using Laravel Echo and the initial connection to private channel is successful, but then I'm not getting any events broadcasted on that channel. With pusher-php-server 7.0.2 everything works fine. Is the new version incompatible with Laravel Websockets and should I wait for an update?

dunakov commented 1 year ago

I also lowered version for stable work laravel-websockets)

mankms commented 1 year ago

Workaround

composer require pusher/pusher-php-server:7.0.2
Nielson commented 1 year ago

Holy shit. Thanks @szabrzyski ! I've been struggling with this for 1½ weeks now and couldn't figure out why my client side didn't catch the event.

LipeApp commented 1 year ago

Когда планируется обновления? На 7.2 много чего который хотели бы пробовать.

luceos commented 1 year ago

I have traced the issue to this: https://github.com/pusher/pusher-http-php/pull/329/files#r993378977

TLDR, the new payload for when dispatching to one channel is channel not channels.

madpilot78 commented 1 year ago

Also experiencing this issue.

A bug report has been filed also at pusher/pusher-http-php#351

@luceos Strange, actually beyondcode/laravel-websockets does accept both channel and channels:

https://github.com/beyondcode/laravel-websockets/blob/1f25913ce05c66bbff1f925106bf9490ec0eb3bf/src/API/TriggerEvent.php#L21

Have you actually tested a patch that solves the issue?

luceos commented 1 year ago

I don't know then @madpilot78; truth be told I have a fork because I needed a custom implementation for a @Flarum extension. And in this fork it now works. Diffing the last version with the new one, and testing things locally, only the channel change has been the most apparent one.

The code you mentioned, which correctly adds the ability to read channel if it is set, was only merged into master 8 days ago, whereas the last release is from March for 1.x. I assume that's the culprit, these changes haven't been released yet and so any published version of this package will still only allow channels in the payload.

madpilot78 commented 1 year ago

I don't know then @madpilot78; truth be told I have a fork because I needed a custom implementation for a @flarum extension. And in this fork it now works. Diffing the last version with the new one, and testing things locally, only the channel change has been the most apparent one.

No you're probably right, I'm going to test again.

The code you mentioned, which correctly adds the ability to read channel if it is set, was only merged into master 8 days ago, whereas the last release is from March for 1.x. I assume that's the culprit, these changes haven't been released yet and so any published version of this package will still only allow channels in the payload.

Oh, sorry, my bad I did not check when it was added. Then I'll test using code with that addition, maybe forcing using the repo head.

madpilot78 commented 1 year ago

I've tested and filed pull request #1046 against branch 1.x that should fix the issue.

Thanks to @luceos for pointing me in the right direction.

vnestoruk commented 1 year ago

Two days that will never come back 😓 Thanks guys, at least you saved my nerves 🫡

tomvo commented 1 year ago

thanks @madpilot78 for fixing this, we're currently struggling with this issue on production. Any timeline on when this will be merged and tagged?

octhavio commented 1 year ago

composer require pusher/pusher-php-server:7.0.2

Thank you so much! I've been stuck on this issue for days. You are my hero. I consider you from now on one of my closest friends. We're practically family now.

Wernke96 commented 1 year ago

@mpociot since we got this package merge in is there any chance we could make a release for this?

gavinsbtm commented 1 year ago

2 days of my life wasted... Thank god I found this page before the weekend.

Thanks to Bvanhaastrecht

vutungf commented 1 year ago

2 days of my life wasted... Thank god I found this page before the weekend.

me too 👍

bci24 commented 1 year ago

in laravel 9.37 with laravel-websockets 1.13.1 the solutions was downgrading to pusher-php-server 7.0.2 or use the latest pusher-php-server 7.2.1 and manually patch the TriggerEventController from here https://github.com/beyondcode/laravel-websockets/pull/1046/commits/fe78daf914aa5a60d47402b2d0b6390e83c9102a

tomvo commented 1 year ago

@bci24 a better fix would be to use "beyondcode/laravel-websockets": "1.x-dev", in your composer instead of manually patching stuff.

jafar690 commented 1 year ago

Spent 4 hours debugging the same issue, 4 hours i won't get back. thanks @mankms

medilies commented 1 year ago

Spent the whole day editing configs and changing the composer file to figure out that V7.2 is broken is the source of the problem https://github.com/medilies/trying-laravel-websockets/compare/6f60c31...a5223dd

Now the question is. Should we expect an update soon?

lordjoo commented 1 year ago

I've downgrade the pusher-php-server and still the client doesn't catch the events abd in the dashboard they didn't appear too

lordjoo commented 1 year ago

I've ended up switching to soketi

kamilkahar90 commented 1 year ago

Looking forward to this issue being resolved. Downgrade pusher-php-server to 7.0.2 working for me.

Slauta commented 1 year ago

I spent a day, but downgrade to 7.0.2 helped me

Steffra commented 1 year ago

Unfortunately i've only found this issue after i've already resolved it by myself. Downgrading to 7.0.2 is the only thing that has worked for me. Can't wait untill it's fixed!

DanJamesMills commented 1 year ago

I had the same issue guys been debugging until this afternoon to find this thread, has anyone created a pull request to fix this or should I create one?

kluevandrew commented 1 year ago

A best way to fix:

./vendor/beyondcode/laravel-websockets/src/HttpApi/Controllers/TriggerEventController.php

<?php

namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers;

use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
use Illuminate\Http\Request;

class TriggerEventController extends Controller
{
    public function __invoke(Request $request)
    {
        $this->ensureValidSignature($request);

        $channels = $request->json()->get('channels', []);
        $channel = $request->json()->get('channel');
        if ($channel) {
            $channels[] = $channel;
        }
        foreach ($channels as $channelName) {
            $channel = $this->channelManager->find($request->appId, $channelName);

            optional($channel)->broadcastToEveryoneExcept([
                'channel' => $channelName,
                'event' => $request->json()->get('name'),
                'data' => $request->json()->get('data'),
            ], $request->json()->get('socket_id'));

            DashboardLogger::apiMessage(
                $request->appId,
                $channelName,
                $request->json()->get('name'),
                $request->json()->get('data')
            );

            StatisticsLogger::apiMessage($request->appId);
        }

        return (object) [];
    }
}
madpilot78 commented 1 year ago

A best way to fix:

./vendor/beyondcode/laravel-websockets/src/HttpApi/Controllers/TriggerEventController.php [...]

@kluevandrew You suggested patch looks very similar to mine from #1046, which has already been merged to the 1.x branch.

Unluckily until a new release is cut from 1.x the change is not going to be distributed automatically.

Let's hope a new 1.x release is cut soon.

AliKhedmati commented 1 year ago

I still had the issue with v7.2.1 Downgrading to v7.0.2 was working fine for me.

madpilot78 commented 1 year ago

@AliKhedmati

The issue is in beyondcode/laravel-websockets. pusher/pusher-http-php has changed how it accesses its own API and is not going back, they have no reason too, they do not support servers except their own.

beyondcode/laravel-websockets needs to adapt to the new way the client accesses the API.

tomvo commented 1 year ago

I don't understand why the fix is merged but not a new release being tagged. Is this repo even maintained? @mpociot

danh65 commented 1 year ago

A best way to fix:

./vendor/beyondcode/laravel-websockets/src/HttpApi/Controllers/TriggerEventController.php

<?php

namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers;

use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
use Illuminate\Http\Request;

class TriggerEventController extends Controller
{
    public function __invoke(Request $request)
    {
        $this->ensureValidSignature($request);

        $channels = $request->json()->get('channels', []);
        $channel = $request->json()->get('channel');
        if ($channel) {
            $channels[] = $channel;
        }
        foreach ($channels as $channelName) {
            $channel = $this->channelManager->find($request->appId, $channelName);

            optional($channel)->broadcastToEveryoneExcept([
                'channel' => $channelName,
                'event' => $request->json()->get('name'),
                'data' => $request->json()->get('data'),
            ], $request->json()->get('socket_id'));

            DashboardLogger::apiMessage(
                $request->appId,
                $channelName,
                $request->json()->get('name'),
                $request->json()->get('data')
            );

            StatisticsLogger::apiMessage($request->appId);
        }

        return (object) [];
    }
}

This worked for me. Glad to find a solution after spending more than a day troubleshooting!

Msangi21 commented 1 year ago

Workaround

composer require pusher/pusher-php-server:7.0.2

You saved my 3 days

099912 commented 1 year ago

"php": "^8.0", "beyondcode/laravel-websockets": "^2.0@beta", "cboden/ratchet": "^0.4.4", "cviebrock/eloquent-sluggable": "^9.0", "fruitcake/laravel-cors": "^2.0.5", "guzzlehttp/guzzle": "^7.7", "illuminate/session": "*", "laravel/framework": "^9.0", "laravel/sanctum": "^3.2", "laravel/tinker": "^2.7", "pusher/pusher-php-server": "7.0.2", I have this version of laravel i think beta 2.o websockets doesnot work for php 8 I also downgrade the pusher from 7.2 to 7.0 but the dashboard of websocj=ket doesnot catch the event

099912 commented 1 year ago

which version of websocket should I use for current versions (but websocket dashboard dosnot catch event) "php": "^8.0", "beyondcode/laravel-websockets": "^2.0@beta", "laravel/framework": "^9.0", "pusher/pusher-php-server": "7.0.2",

jdthehelper commented 7 months ago

I have create full documentation for laravel websocket with realted issue every time. Please check it https://myphpinformation.blogspot.com/2024/01/laravel-websocket-setup-and-example-how-to-use-it.html this my help you.