Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // tslint:disable: cyclomatic-complexity
- preparePlayback = async (
- props: Props,
- channelChanged: boolean,
- contentChanged: boolean,
- qualityChanged: boolean,
- videoTypeChanged: boolean,
- recordingStateChanged: boolean,
- startTimeChanged: boolean,
- ) => {
- const { player, contentId, type, store, recordingId, startTime, apiConnector } = props;
- let response: StreamUrlResponse|undefined;
- let playerData: LiveTVData|AssetDetail|null = null;
- let position = 0;
- const playbackStartTimestamp = store.player.playbackStartTimestamp;
- const isLiveTV = type === 'tv' || !type;
- const requestTimeStamp = Date.now();
- this.pendingRequestTimestamp = requestTimeStamp;
- this.setState({showThrobber: true});
- const channelId = props.channelId || store.player.tunedChannel;
- try {
- response = await this.fetchStreamUrl(props);
- if (isLiveTV) {
- playerData = await this.fetchLiveTVDataForChannel(type, channelId);
- } else if (type === 'timeshift' && response) {
- playerData = await this.fetchTimeshiftDataForChannel(type, channelId, startTime, response, contentId);
- } else {
- playerData = await this.fetchAssetDetail(type, contentId, channelId, recordingId);
- }
- if (type === 'timeshift' && contentChanged && response) {
- position = this.getPositionOfProgramStart(((playerData as LiveTVData).assetDetail as ProgramModel), response);
- }
- if (channelChanged || contentChanged || qualityChanged || videoTypeChanged || playbackStartTimestamp === 0) {
- if ((channelChanged || contentChanged) && type !== 'timeshift') {
- position = player.getCurrentTime();
- }
- if (response) {
- startPlayback(player, response.url, Number(startTime) || position, isLiveTV || type === 'timeshift');
- }
- if (contentId && typeof type === 'string') {
- PlayerScreen.continueWatchingTracker.start(apiConnector, player, type, contentId);
- console.log('continue watching started from Player.tsx');
- }
- } else if (startTimeChanged) {
- player.seek(Number(startTime) || position);
- }
- if (this.pendingRequestTimestamp === requestTimeStamp && response) {
- if (playerData) this.setPlayerDataToState(playerData);
- if ((channelChanged || videoTypeChanged) && channelId && (isLiveTV || type === 'timeshift')) {
- this.props.dispatch({type: SET_LIVETV_CHANNEL, channelId});
- }
- if ((contentChanged || videoTypeChanged) && contentId && type && !isLiveTV) {
- this.props.dispatch({type: SET_VOD_CONTENT, contentId, videoType: type});
- }
- this.setState(({streamUrlResponse: prevResponse}: State) => {
- if (prevResponse && prevResponse.url === response!.url) {
- return { error: undefined, availability: 'AVAILABLE' };
- }
- return {error: undefined, availability: 'AVAILABLE', streamUrlResponse: response};
- });
- }
- } catch (e) {
- if (!e.deviceLimit && this.pendingRequestTimestamp === requestTimeStamp) {
- if (playerData) this.setPlayerDataToState(playerData);
- }
- this.onError(e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement