V
V
Vitaly2020-01-24 12:30:30
Laravel
Vitaly, 2020-01-24 12:30:30

How to send a notification to the client immediately after connection?

Event:

class PlaylistTitleUpdate implements ShouldBroadcast
{
/*.......*/
    public function broadcastOn()
    {
        return new PresenceChannel('playlist.'.$this->playlist->slug);
    }
/*.......*/
}

js code:
window.Echo.join(`playlist.novoe`)
    .here((users) => {})
    .joining((user) => {})
    .leaving((user) => {})
    .listen('PlaylistTitleUpdate', (e) => {
        console.log(e);
    });

This code works great. Fires as it should when the corresponding event occurs on the server. But how can I get this data on the client right after the user has connected? While "puzzling" came two options: 1). B here send ajax request 2). We need some new event that will track the user's authorization and send data to this particular user via a private channel (although it's hard to imagine the implementation of such an approach in my head) Please help! I really want to believe that everything is much simpler - poke your nose into the documentation if you may have overlooked this moment! Thanks in advance
listen 'PlaylistTitleUpdate'

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question