Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // tslint:disable: cyclomatic-complexity
  2.   preparePlayback = async (
  3.     props: Props,
  4.     channelChanged: boolean,
  5.     contentChanged: boolean,
  6.     qualityChanged: boolean,
  7.     videoTypeChanged: boolean,
  8.     recordingStateChanged: boolean,
  9.     startTimeChanged: boolean,
  10.   ) => {
  11.     const { player, contentId, type, store, recordingId, startTime, apiConnector } = props;
  12.     let response: StreamUrlResponse|undefined;
  13.     let playerData: LiveTVData|AssetDetail|null = null;
  14.     let position = 0;
  15.     const playbackStartTimestamp = store.player.playbackStartTimestamp;
  16.     const isLiveTV = type === 'tv' || !type;
  17.     const requestTimeStamp = Date.now();
  18.     this.pendingRequestTimestamp = requestTimeStamp;
  19.  
  20.     this.setState({showThrobber: true});
  21.     const channelId = props.channelId || store.player.tunedChannel;
  22.     try {
  23.       response = await this.fetchStreamUrl(props);
  24.  
  25.       if (isLiveTV) {
  26.         playerData = await this.fetchLiveTVDataForChannel(type, channelId);
  27.       } else if (type === 'timeshift' && response) {
  28.         playerData = await this.fetchTimeshiftDataForChannel(type, channelId, startTime, response, contentId);
  29.       } else {
  30.         playerData = await this.fetchAssetDetail(type, contentId, channelId, recordingId);
  31.       }
  32.  
  33.       if (type === 'timeshift' && contentChanged && response) {
  34.         position = this.getPositionOfProgramStart(((playerData as LiveTVData).assetDetail as ProgramModel), response);
  35.       }
  36.  
  37.       if (channelChanged || contentChanged || qualityChanged  || videoTypeChanged || playbackStartTimestamp === 0) {
  38.         if ((channelChanged || contentChanged) && type !== 'timeshift') {
  39.           position = player.getCurrentTime();
  40.         }
  41.         if (response) {
  42.           startPlayback(player, response.url, Number(startTime) || position, isLiveTV || type === 'timeshift');
  43.         }
  44.         if (contentId && typeof type === 'string') {
  45.           PlayerScreen.continueWatchingTracker.start(apiConnector, player, type, contentId);
  46.           console.log('continue watching started from Player.tsx');
  47.         }
  48.       } else if (startTimeChanged) {
  49.         player.seek(Number(startTime) || position);
  50.       }
  51.  
  52.       if (this.pendingRequestTimestamp === requestTimeStamp && response) {
  53.         if (playerData) this.setPlayerDataToState(playerData);
  54.  
  55.         if ((channelChanged || videoTypeChanged) && channelId && (isLiveTV || type === 'timeshift')) {
  56.           this.props.dispatch({type: SET_LIVETV_CHANNEL, channelId});
  57.         }
  58.         if ((contentChanged || videoTypeChanged) && contentId && type && !isLiveTV) {
  59.           this.props.dispatch({type: SET_VOD_CONTENT, contentId, videoType: type});
  60.         }
  61.  
  62.         this.setState(({streamUrlResponse: prevResponse}: State) => {
  63.           if (prevResponse && prevResponse.url === response!.url) {
  64.             return { error: undefined, availability: 'AVAILABLE' };
  65.           }
  66.           return {error: undefined, availability: 'AVAILABLE', streamUrlResponse: response};
  67.         });
  68.       }
  69.     } catch (e) {
  70.       if (!e.deviceLimit && this.pendingRequestTimestamp === requestTimeStamp) {
  71.         if (playerData) this.setPlayerDataToState(playerData);
  72.       }
  73.       this.onError(e);
  74.     }
  75.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement