In this episode, we set up private broadcasting for our video encoding process, which is crucial for keeping each user's upload events private and secure. Instead of making encoding status updates public, we're ensuring that only the user who uploaded a video can receive real-time updates about its progress.
We start by creating an EncodeVideo
job, which is dispatched right after a video finishes uploading. The actual encoding part happens later—right now, our focus is on letting the client know that the encoding has started. We create a new event (EncodeVideoStart
) and broadcast it only on a private channel associated with the current user.
On the frontend, we subscribe to this private channel using Laravel Echo and Inertia.js, making sure only the authenticated user receives these updates. When the event comes through, we update the state of the relevant upload (by video ID) to set its encoding status to true
. We also tweak the UI to show an "encoding" progress bar, so users know their video is being processed—even if the backend is taking its time.
Along the way, we add a few safety checks in the frontend (like making sure we're only updating uploads that exist on the page) and run through a couple of quick code fixes to keep things smooth. By the end of the episode, whenever you upload a video, you immediately see the switch from uploading to encoding, all happening securely through private broadcasting.
In the next episode, we'll handle the actual video encoding on the backend and start pushing real progress updates to the client. Stay tuned!