In this episode, we dive into adding a "user is typing" indicator to our chat application—something that really makes your app feel more interactive and alive!
First, we look at how to use Laravel Echo's whisper
method to broadcast typing events on a channel. Unlike regular broadcasted events, whisper
is a client-to-client event, so you don't need to hit the backend every time someone starts or stops typing. It updates all other connected clients except the one sending the event. We play around with this by sending a typing event (with some user data), confirming it appears for all connected users, and updating our store to keep track of who is typing.
Next, we update our frontend to visually show when a user is typing. We add a fun little SVG animation (like those three-dot loading indicators) that appears next to a user's name while they're typing. Of course, you can get fancy with this part and style it however you like.
Finally, we iron out one last UX bug: making sure the typing indicator disappears as soon as a user sends a message (for example, by pressing Enter), so there’s no awkward delay.
By the end, our chat feels much more real-time, showing who’s actively typing at any given moment. This makes for a way smoother and more engaging chat experience! 🗨️💬