4

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?

Dan
  • 1,249
  • 2
  • 16
  • 31
  • I'm having the exact same issue and cannot find an answer. Did you ever solve this? – Gavin Oct 26 '22 at 21:50
  • Nope. I gave up on laravel-websockets and just started using Pusher's commercial offering. Sorry! – Dan Oct 28 '22 at 07:51
  • Thanks for the reply. It turned out there is a bug in the latest version of websockets. I installed an older version and got things working. Using supervisor to keep the process alive. – Gavin Oct 29 '22 at 09:13
  • You could post it as an answer, with the version that works? – Dan Oct 30 '22 at 10:11

1 Answers1

2

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.

Gavin
  • 2,123
  • 1
  • 15
  • 19
  • Thx, this will be handy if we go back to doing it like this. – Dan Nov 02 '22 at 10:32
  • Thank you! Looks like there's 2 issues on GitHub about this: [#364](https://github.com/pusher/pusher-http-php/issues/364) and [#1041](https://github.com/beyondcode/laravel-websockets/issues/1041). Basically, laravel-websockets can't keep up with the changes to pusher-php-server. – SameOldNick Dec 03 '22 at 08:56