تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Scheduling Status Updates0:00

Any time a podcast has completed, in this case, is the end time past, is the end time already in the past according to our server, then we want to remove the live status. We want to set isActive to false, and that way we're not displaying it, and we can also then in our show component here, maybe we can say something like if isActive is false, we can say this has already been played, the listening party is no more. So when we go into our app.php, actually our console.php, and this is where we can set up new artisan commands, but we're just going to run a schedule command right here. And what we can do is schedule, and we can bring in that Facade. So schedule command, and we can call this maybe, we'll use a function to kind of pass this out.

So schedule command, and we can call this maybe, we'll use a function to kind of pass this out. So we can say that this is the listening party, and we can bring in that model. And this is where we want to run that query to grab all of those and then update them. So listening party where, and then we want to check if the end time is in the past. So end time is less than or equal to now, then we want to update the is active parameter, the is active column in the database. We can set the is active to false, and that should be good to go. Now we can say we want to run this maybe every minute, because we want to check every minute if there has been a change in the end time.

Running Scheduled Task1:33

Now we can say we want to run this maybe every minute, because we want to check every minute if there has been a change in the end time. In this case, if a podcast has been completed, we should change the isActive status. So if we were to take a look at our terminal, why don't we go ahead and run this php artisan schedule:work command. Looks like we have an error. Let's see. Argument class must be of type string. It is not a schedule command. That is why it is a schedule call.

It is not a schedule command. That is why it is a schedule call. Let's bring back up our terminal, and we'll run that again. And we're going to see that a schedule command is being run. When I switch back to the browser, we should see that old status. Looks like that completed. I'll switch back to the browser and refresh. We don't have any audio listening parties. Now, if we really want to, we could set a wire pull on this, but no one's really going to be, no User is probably going to be just waiting for an audio party to be done.

Considering Live Polling2:33

Now, if we really want to, we could set a wire:poll on this, but no one's really going to be, no User is probably going to be just waiting for an audio party to be done. Most people would probably click into it, and that's where we can set up another check to say, hey, if this has not been active anymore. Okay. Back to seeing if that listening is correct. So if I click createListeningParty, it looks like that is happening in the background. And one of the things that we can do is in the show.blade.php for this listening party, we could actually set a wire:poll of five seconds so that while it's creating it, we can then reload it and show, in this case, after the end time is set,

we could actually set a wire pull of five seconds so that while it's creating it, we can then reload it and show, in this case, after the end time is set, we probably want to show like a waiting room if it's not live. In this case, it is live. Okay. Go to the dashboard and we can click in and it should start playing. It doesn't look like it's playing. Let's see where we might have made a mistake. So it looks like we have all of this here, check and play audio format time. Yes.

Fixing Alpine Initialization3:35

So it looks like we have all of this here, check and play audio format time. Yes. When we are initializing an Alpine component, in this case, this isn't going to run automatically. We need to tell it what function should run. We want the initializeAudioPlayer to run. So now in this div, we can set an x-init. And this is saying when this component loads, we want to run this audioPlayer function. So now if we were to go back, let's go to the dashboard, click in. Okay. It's still not loading.

Okay. It's still not loading. Let's check in the console and looks like we have some kind of format error. Let's see. Format time seconds. Aha. There we go. We are good to go. So if we take a look, let's close this console. We have this upcoming listening party.

So if we take a look, let's close this console. We have this upcoming listening party. We click in and you probably can't hear the actual audio. I might be picking it up in my microphone, but the current time is being played. So if we were to go back, we click in. We are playing at the time it should be playing based off of the start time. So whoever visits this particular page is going to get this episode. In this case, the episode that is associated with the listening party playing at the same time across every browser. And we're initializing that with our Alpine JS state.

Improving UI and Autoplay5:01

time across every browser. And we're initializing that with our Alpine JS state. So click in and set three minutes and 31 seconds. So now why don't we clean this up a little bit to make it look a little bit prettier when we are in a listening party, but also set up some loading states for when the listening party hasn't quite started, maybe when it's about to finish and show off this page a little bit more. Also, one bug that we might need to take a look at is if this link is copied directly, someone visits it, the audio doesn't play automatically. Now this is specific to web browser standards where you can't auto play audio unless you

someone visits it, the audio doesn't play automatically. Now this is specific to web browser standards where you can't auto play audio unless you opt into it. So maybe we'll go ahead and have a kind of like a flash screen for those folks. If this is live, we want them to click play and then we can initialize that audio. So let's keep going.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟