laravel-echolaravel-websocketslaravel-broadcast

Laravel broadcast with Pusher and laravel-websockets not sending message


This is a setup with Laravel 7, following the install guide for using the pusher driver with laravel-websockets rather than Pusher.

The 'php artisan websockets:serve' is running, and has connected to the Echo client in the browser and is happily sending ping / pong messages.

But, when I try to send a server message by triggering an event with

broadcast(new TestBroadcastingEvent($event));

I see no activity from websockets:serve logs and no messages on the wire (in DevTools).

I can see the event get constructed, the job gets queued and executed, and I can see the broadcastOn() method being called.

public function broadcastOn()
{
    \Log::debug("broadcastOn()");
    return new PrivateChannel('order.'.$this->event->ch);
}

If I switch the BROADCAST_DRIVER to 'log', I do see the message logged there:

[2021-05-07 14:08:59] testing.INFO: Broadcasting [App\Events\TestBroadcastingEvent] on channels [order.111] with payload:
{
    "event": {
        "ch": "111",
        "info": "hello"
    },
    "socket": null
}  

But setting the BROADCAST_DRIVER to "pusher" results in no further activity, as mentioned.

Same behavior with queue driver set to "sync", so it's not the queue setup.

The only clue I have is that the channel authentication function is not getting called, but it's not quite clear from the docs whether this is relevant for sending (says authentication for listening).

Broadcast::channel('order.{orderId}', function ($user, $orderId) {
    \Log::debug('callback in channels.php');
    return true;
});

There are no errors in any logs, no exceptions or anything visibly wrong.

What else can I look at to see where the message is getting lost?


Solution

  • This is not a direct answer to the original question as that was a year and a half ago but I was having the same issue as described using pusher-php-server 7.2 and websockets 1.13.1.

    Ping / Pong messages were sent and received but I couldn't broadcast my own messages from a Laravel 9 app.

    Downgrading to pusher-php-server 7.0.2 solved the problem.