In this episode, we dive into presence channels and see how they're used to show which users are currently online in a chat room. We start by looking at how presence channels require an authenticated user and how Laravel automatically handles the authentication requests under the hood.
You'll see how you can decide who gets access to your channels by returning true or false in your authorization callbacks, and even send back extra data about the user (like ID, name, or even avatar URLs) so that info is available client-side.
Once that's set up, we switch over to the frontend, where we use the .here()
method to grab the list of users currently present in the room. We console log out this data to see exactly what's coming back, and talk about how you can use this to keep your own list of online users. In the next episode, we'll actually display that list in the UI!