This episode is for members only

Sign up to access "Soketi Basics" right now.

Get started
Already a member? Sign in to continue
Playing
04. Listening to events

Transcript

00:00
Okay then, very quickly, let's go and look at using Laravel Echo to listen on this public channel which will be available for anyone regardless of whether they're authenticated or not. We're going to listen to that specific new thing available event which we're broadcasting from that end point we created.
00:17
So let's go ahead and say Echo which is now on the window object as we saw from over here and we're going to go ahead and say Channel because this is a public channel. And remember we call that Things just to remind us we set the channel name just here. So what we're going to do is we're going to chain on the listen method and we're going to listen to that event. Now this will be the event class name so new thing available.
00:45
We can customize that and that's all in the Laravel documentation. And once that picks up in this event we're going to go ahead and get that event in here which we can just console log out for now. But of course if this was a new post that been published and you'd set the payload of the event in here to the new post then you could take that data and push it somewhere to the page whatever you needed to do with it. Okay so let's go over and just give this a refresh.
01:11
Of course we see nothing at the moment but what we should now see is when we refresh this we get the message instantly broadcasted picked up on the client side and we see that message payload that we pass through to the event. So that's how easy once we've got everything configured is to set up and listen to these events from the back end. So now that we've got public channels down the really important part of this is private channels that require the user to be authenticated. So let's head over and check that out in the next episode.
5 episodes 26 mins

Overview

Learn to broadcast events in realtime with Soketi, a simple, fast, and resilient open-source WebSockets server.

In this course, we'll set up a Soketi server, configure Laravel for Soketi, and create events for public and private channels. Then, we'll listen for these events on the client and dump the payload from the server.

If you need realtime events in your app, this course will get you up and running in no time.

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Episode discussion

No comments, yet. Be the first!