Search code examples
laravellaravel-8laravel-echobroadcastingpusher-js

Laravel echo send data when joining channel


How do I receive data when the client initially joins a channel?

Something like this:

Echo.channel('channel-name')
    .onjoin(function (data) {
        console.log(data) // Data received from server
    })

As soon when the client joins, the server should respond with data, preferably with PHP.


Solution

  • Presence channels return information about the users in the channel at the time the client subscribes. If you require other data from your server then you could send a post request to your server to get the information. You could invoke this in a pusher:subscription_succeeded binding so it occurs as soon as the subscription is established.