/** * @param LiveBroadcast $broadcast */ public function preRemove($broadcast) { foreach ($broadcast->getOutputChannels() as $channel) { if ($channel instanceof ChannelYouTube) { $youTubeService = $this->getYouTubeService(); try { $youTubeService->removeLiveEvent($broadcast, $channel); } catch (\Google_Service_Exception $ex) { /** @var LoggerInterface $logger */ $logger = $this->getConfigurationPool()->getContainer()->get('logger'); $logger->warning($ex->getMessage()); } } } parent::preRemove($broadcast); }
/** * @param LiveBroadcast $liveBroadcast * @param OutputFacebook $outputFacebook * @return null|string * @throws LiveBroadcastOutputException */ public function createFacebookLiveVideo(LiveBroadcast $liveBroadcast, OutputFacebook $outputFacebook) { if (!$this->facebookSDK) { $this->initFacebook(); } try { $params = array('title' => $liveBroadcast->getName(), 'description' => $liveBroadcast->getDescription()); $this->facebookSDK->setDefaultAccessToken($outputFacebook->getAccessToken()); $response = $this->facebookSDK->post($outputFacebook->getEntityId() . '/live_videos', $params); } catch (FacebookResponseException $ex) { throw new LiveBroadcastOutputException('Facebook exception: ' . $ex->getMessage()); } catch (FacebookSDKException $ex) { throw new LiveBroadcastOutputException('Facebook SDK exception: ' . $ex->getMessage()); } $body = $response->getDecodedBody(); if (array_key_exists('stream_url', $body)) { return $body['stream_url']; } return null; }
/** * Start the actual broadcast * @throws LiveBroadcastOutputException * @throws \Martin1982\LiveBroadcastBundle\Exception\LiveBroadcastInputException */ protected function startBroadcast() { $media = $this->plannedBroadcast->getInput(); $input = $this->inputService->getInputInterface($media)->generateInputCmd(); /** @var OutputYouTube $outputService */ $outputService = $this->outputService->getOutputInterface($this->channel); $outputService->setStreamUrl($this->youTubeApiService->getStreamUrl($this->plannedBroadcast, $this->channel)); $output = $outputService->generateOutputCmd(); $this->logger->info('YouTube start broadcast', array('broadcast_id' => $this->plannedBroadcast->getBroadcastId())); $this->command->startProcess($input, $output, array('broadcast_id' => $this->plannedBroadcast->getBroadcastId(), 'channel_id' => $this->channel->getChannelId())); }
/** * @param LiveBroadcast $liveBroadcast * @param string $privacyStatus * @param string|null $id * @return \Google_Service_YouTube_LiveBroadcast */ protected function setupBroadcast(LiveBroadcast $liveBroadcast, $privacyStatus = 'public', $id = null) { $title = $liveBroadcast->getName(); $description = $liveBroadcast->getDescription(); $start = $liveBroadcast->getStartTimestamp(); $end = $liveBroadcast->getEndTimestamp(); if (new \DateTime() > $start) { $start = new \DateTime(); $start->add(new \DateInterval('PT1S')); } $broadcastSnippet = new \Google_Service_YouTube_LiveBroadcastSnippet(); $broadcastSnippet->setTitle($title); $broadcastSnippet->setDescription($description); $broadcastSnippet->setScheduledStartTime($start->format(\DateTime::ATOM)); $broadcastSnippet->setScheduledEndTime($end->format(\DateTime::ATOM)); $status = new \Google_Service_YouTube_LiveBroadcastStatus(); $status->setPrivacyStatus($privacyStatus); $broadcastInsert = new \Google_Service_YouTube_LiveBroadcast(); if ($id !== null) { $broadcastInsert->setId($id); } $broadcastInsert->setSnippet($broadcastSnippet); $broadcastInsert->setStatus($status); $broadcastInsert->setKind('youtube#liveBroadcast'); return $broadcastInsert; }
/** * @param $broadcast * @param $channel * @return bool */ public function isBroadcasting(LiveBroadcast $broadcast, BaseChannel $channel) { return $this->broadcastId === $broadcast->getBroadcastId() && $this->channelId === $channel->getChannelId(); }
/** * Test get methods. */ public function testGetMethods() { $now = new \DateTime(); $endTime = new \DateTime('+1 hour'); $broadcast = new LiveBroadcast(); $broadcast->setName('Test'); $broadcast->setDescription('Description of broadcast'); self::assertEquals($now, $broadcast->getStartTimestamp()); self::assertEquals($endTime, $broadcast->getEndTimestamp()); self::assertEquals(new ArrayCollection(), $broadcast->getOutputChannels()); self::assertEquals('Test', $broadcast->getName()); self::assertEquals('Description of broadcast', $broadcast->getDescription()); /* Check default value */ self::assertTrue($broadcast->isStopOnEndTimestamp()); $broadcast->setStopOnEndTimestamp(false); self::assertFalse($broadcast->isStopOnEndTimestamp()); }
/** * Initiate a new broadcast. * * @param LiveBroadcast $broadcast * @param BaseChannel $channel */ protected function startBroadcast(LiveBroadcast $broadcast, BaseChannel $channel) { try { $input = $this->inputService->getInputInterface($broadcast->getInput()); $output = $this->outputService->getOutputInterface($channel); $preBroadcastEvent = new PreBroadcastEvent($broadcast, $output); $this->dispatcher->dispatch(PreBroadcastEvent::NAME, $preBroadcastEvent); $this->logger->info('Start broadcast', array('broadcast_id' => $broadcast->getBroadcastId(), 'broadcast_name' => $broadcast->getName(), 'channel_id' => $channel->getChannelId(), 'channel_name' => $channel->getChannelName(), 'input_cmd' => $input->generateInputCmd(), 'output_cmd' => $output->generateOutputCmd())); $this->schedulerCommands->startProcess($input->generateInputCmd(), $output->generateOutputCmd(), array('broadcast_id' => $broadcast->getBroadcastId(), 'channel_id' => $channel->getChannelId())); $postBroadcastEvent = new PostBroadcastEvent($broadcast, $output); $this->dispatcher->dispatch(PostBroadcastEvent::NAME, $postBroadcastEvent); } catch (LiveBroadcastException $ex) { $this->logger->error('Could not start broadcast', array('broadcast_id' => $broadcast->getBroadcastId(), 'broadcast_name' => $broadcast->getName(), 'exception' => $ex->getMessage())); } }