qruto / laravel-wave

Painless Laravel Broadcasting with SSE

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: Can't broadcast to presence channel

edalzell opened this issue · comments

What happened?

I'm trying to broadcast to a presence channel and I'm not seeing anything sent/received.

How to reproduce the bug

I have a model set up to broadcast on changes:

    public function broadcastOn(string $event): array
    {
        return match ($event) {
            'created' => [new PresenceChannel('chat.'.$this->receiver_id)],
            default => [],
        };
    }

I have auth set up in channels.php, which seems to work (no 403 errors in console):

Broadcast::channel('chat.{user}', function (User $user, User $receiver) {
    if ($user->id === $receiver->id) {
        return ['id' => $user->id, 'name' => $user->name];
    }

    return false;
});

I added this to my app.js:

Echo.join('chat.3')
    .here(() => {
        console.log('here');
    })
    .joining(() => {
        console.log('joining');
    })
    .leaving(() => {
        console.log('leaving');
    })
    .listen('MessageCreated', (e) => {
        console.log('listening')
    });

And I don't see the listening in my console.log, only here.

Package Version

0.7.1

PHP Version

8.2.8

Laravel Version

10.19

Which operating systems does with happen with?

macOS

Notes

I will see if I can figure out a failing test for this, but I did notice there were no presence tests.

User error, needed to have .MessageSent