/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     if (!DebugHelpers::shouldSiteBeLive()) {
         $this->info('Not running because site should not be live at the moment.');
         return;
     }
     $this->info('Sending ping command to any dvr bridge service servers that are being used.');
     // go though all dvrLiveStreamUris, get their dvr bridge service url, and send ping to it
     $dvrLiveStreamUriModels = DvrLiveStreamUri::with("liveStreamUri", "mediaItemLiveStream")->get();
     foreach ($dvrLiveStreamUriModels as $a) {
         $liveStreamUriModel = $a->liveStreamUri;
         $mediaItemLiveStream = $a->mediaItemLiveStream;
         $url = $liveStreamUriModel->uri;
         $this->info("Sending ping command to dvr bridge service at url \"" . $url . "\".");
         $responseInfo = MediaItemLiveStream::makeDvrBridgeServiceRequest($url, "PING", intval($a->id));
         if ($responseInfo["statusCode"] !== 200) {
             // error occurred. Remove dvrLiveStreamUri as something's wrong with it.
             $a->delete();
             $this->info("Error occurred/response returned from ping command to dvr bridge service at url \"" . $url . "\". Removing dvr link.");
         } else {
             $this->info("Sent ping command to dvr bridge service at url \"" . $url . "\".");
         }
     }
     $this->info("Finished.");
 }
Exemplo n.º 2
0
 private function startDvrs()
 {
     $liveStreamModel = $this->liveStream;
     if (is_null($liveStreamModel)) {
         // could be null if just external stream on external site
         return;
     }
     // there shouldn't already be one in progress but clear anyway to be sure
     $this->dvrLiveStreamUris()->delete();
     foreach ($liveStreamModel->liveStreamUris as $uriModel) {
         $enabled = (bool) $uriModel->enabled;
         $uriForDvrBridgeService = (bool) $uriModel->dvr_bridge_service_uri;
         if ($enabled && $uriForDvrBridgeService) {
             $dvrLiveStreamUriModel = new DvrLiveStreamUri();
             $dvrLiveStreamUriModel->liveStreamUri()->associate($uriModel);
             $dvrLiveStreamUriModel->mediaItemLiveStream()->associate($this);
             $this->dvrLiveStreamUris()->save($dvrLiveStreamUriModel);
             $responseInfo = self::makeDvrBridgeServiceRequest($uriModel->uri, "START", $dvrLiveStreamUriModel->id);
             if ($responseInfo["statusCode"] === 200 && !is_null($responseInfo['data']) && !is_null($responseInfo['data']['url'])) {
                 // success. dvr has started
                 // add url to dvr_live_stream_uris entry
                 $dvrLiveStreamUriModel->uri = $responseInfo['data']['url'];
                 $dvrLiveStreamUriModel->save();
             } else {
                 $dvrLiveStreamUriModel->delete();
             }
         }
     }
     // there may be new domains now from the urls retrieved from the dvr bridge services
     Cache::forget("liveStreamDomains");
 }