/** * @param Request $request * @param Session $session * @param YouTubeApiService $youTubeService */ protected function checkRequestCode(Request $request, Session $session, YouTubeApiService $youTubeService) { $requestCode = $request->get('code'); $requestState = $request->get('state'); $sessionState = $session->get('state'); $youTubeService->authenticate($requestCode, $requestState, $sessionState); $refreshToken = $youTubeService->getRefreshToken(); if ($refreshToken) { $session->set('youTubeChannelName', $youTubeService->getChannelName()); $session->set('youTubeRefreshToken', $refreshToken); } }
/** * @param PostBroadcastEvent $event */ public function onPostBroadcast(PostBroadcastEvent $event) { /** @var LiveBroadcast $liveBroadcast */ $liveBroadcast = $event->getLiveBroadcast(); $output = $event->getOutput(); if ($output instanceof OutputYouTube) { $redirectUri = $this->redirectService->getOAuthRedirectUrl(); $this->youTubeApiService->initApiClients($redirectUri); $channel = $output->getChannel(); $this->youTubeApiService->transitionState($liveBroadcast, $channel, YouTubeEvent::STATE_REMOTE_LIVE); } }
/** * @param PreBroadcastEvent $event */ public function onPreBroadcast(PreBroadcastEvent $event) { /** @var LiveBroadcast $liveBroadcast */ $liveBroadcast = $event->getLiveBroadcast(); $output = $event->getOutput(); if ($output instanceof OutputYouTube) { $redirectUri = $this->redirectService->getOAuthRedirectUrl(); $this->youTubeApiService->initApiClients($redirectUri); $streamUrl = $this->youTubeApiService->getStreamUrl($liveBroadcast, $output->getChannel()); if ($streamUrl) { $output->setStreamUrl($streamUrl); } } }
/** * @param BlockContextInterface $blockContext * @param Response|null $response * @return Response */ public function execute(BlockContextInterface $blockContext, Response $response = null) { $request = $this->requestStack->getCurrentRequest(); $session = $request->getSession(); if ($refreshToken = $session->get('youTubeRefreshToken')) { $this->youTubeApi->getAccessToken($refreshToken); } $isAuthenticated = $this->youTubeApi->isAuthenticated(); $state = mt_rand(); if (!$isAuthenticated) { $session->set('state', $state); $session->set('authreferer', $request->getRequestUri()); } return $this->renderResponse('LiveBroadcastBundle:Block:youtube_auth.html.twig', array('isAuthenticated' => $isAuthenticated, 'authUrl' => $isAuthenticated ? '#' : $this->youTubeApi->getAuthenticationUrl($state), 'youTubeChannelName' => $session->get('youTubeChannelName'), 'youTubeRefreshToken' => $session->get('youTubeRefreshToken'), 'block' => $blockContext->getBlock(), 'settings' => $blockContext->getSettings()), $response); }
/** * @return YouTubeApiService * @throws \Martin1982\LiveBroadcastBundle\Exception\LiveBroadcastOutputException */ protected function getYouTubeApiService() { if (!$this->googleRedirectUri) { $this->googleRedirectUri = $this->redirectService->getOAuthRedirectUrl(); $this->youTubeApiService->initApiClients($this->googleRedirectUri); } return $this->youTubeApiService; }
/** * 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())); }