lbry-desktop/ui/component/viewers/videoViewer/index.js

125 lines
5.2 KiB
JavaScript
Raw Normal View History

2019-08-02 08:28:14 +02:00
import { connect } from 'react-redux';
2022-03-15 17:18:08 +01:00
import { selectClaimForUri, selectThumbnailForUri } from 'redux/selectors/claims';
import { isStreamPlaceholderClaim, getChannelIdFromClaim } from 'util/claim';
import { selectActiveLivestreamForChannel } from 'redux/selectors/livestream';
import {
makeSelectNextUrlForCollectionAndUrl,
makeSelectPreviousUrlForCollectionAndUrl,
} from 'redux/selectors/collections';
import * as SETTINGS from 'constants/settings';
import * as COLLECTIONS_CONSTS from 'constants/collections';
import {
doChangeVolume,
doChangeMute,
doAnalyticsBuffer,
doAnaltyicsPurchaseEvent,
doAnalyticsView,
} from 'redux/actions/app';
2019-08-02 08:28:14 +02:00
import { selectVolume, selectMute } from 'redux/selectors/app';
2022-05-04 12:24:13 +02:00
import {
savePosition,
clearPosition,
doPlayUri,
doSetPlayingUri,
doSetContentHistoryItem,
} from 'redux/actions/content';
import { makeSelectIsPlayerFloating, selectContentPositionForUri, selectPlayingUri } from 'redux/selectors/content';
import { selectRecommendedContentForUri } from 'redux/selectors/search';
2019-08-02 08:28:14 +02:00
import VideoViewer from './view';
import { withRouter } from 'react-router';
import { doClaimEligiblePurchaseRewards } from 'redux/actions/rewards';
import { selectDaemonSettings, selectClientSetting, selectHomepageData } from 'redux/selectors/settings';
2022-04-20 20:40:21 +02:00
import { toggleVideoTheaterMode, toggleAutoplayNext, doSetClientSetting } from 'redux/actions/settings';
import { selectUserVerifiedEmail, selectUser } from 'redux/selectors/user';
import { parseURI } from 'util/lbryURI';
2022-04-25 15:28:36 +02:00
import { doToast } from 'redux/actions/notifications';
2019-08-02 08:28:14 +02:00
const select = (state, props) => {
const { search, pathname, hash } = props.location;
const urlParams = new URLSearchParams(search);
const autoplay = urlParams.get('autoplay');
const uri = props.uri;
const urlPath = `lbry://${(pathname + hash).slice(1)}`;
let startTime;
try {
({ startTime } = parseURI(urlPath));
} catch (e) {}
2022-03-15 17:18:08 +01:00
const claim = selectClaimForUri(state, uri);
// TODO: eventually this should be received from DB and not local state (https://github.com/lbryio/lbry-desktop/issues/6796)
const position =
startTime || (urlParams.get('t') !== null ? urlParams.get('t') : selectContentPositionForUri(state, uri));
const userId = selectUser(state) && selectUser(state).id;
const internalFeature = selectUser(state) && selectUser(state).internal_feature;
const playingUri = selectPlayingUri(state);
const collectionId = urlParams.get(COLLECTIONS_CONSTS.COLLECTION_ID) || playingUri.collectionId;
const isMarkdownOrComment = playingUri.source === 'markdown' || playingUri.source === 'comment';
let nextRecommendedUri;
let previousListUri;
if (collectionId) {
nextRecommendedUri = makeSelectNextUrlForCollectionAndUrl(collectionId, uri)(state);
previousListUri = makeSelectPreviousUrlForCollectionAndUrl(collectionId, uri)(state);
} else {
const recommendedContent = selectRecommendedContentForUri(state, uri);
nextRecommendedUri = recommendedContent && recommendedContent[0];
}
2020-03-19 21:25:37 +01:00
return {
position,
userId,
internalFeature,
collectionId,
nextRecommendedUri,
previousListUri,
isMarkdownOrComment,
2020-04-14 01:48:11 +02:00
autoplayIfEmbedded: Boolean(autoplay),
autoplayNext: selectClientSetting(state, SETTINGS.AUTOPLAY_NEXT),
volume: selectVolume(state),
muted: selectMute(state),
videoPlaybackRate: selectClientSetting(state, SETTINGS.VIDEO_PLAYBACK_RATE),
thumbnail: selectThumbnailForUri(state, uri),
2022-03-15 17:18:08 +01:00
claim,
2021-04-12 18:43:47 +02:00
homepageData: selectHomepageData(state),
authenticated: selectUserVerifiedEmail(state),
shareTelemetry: IS_WEB || selectDaemonSettings(state).share_usage_data,
isFloating: makeSelectIsPlayerFloating(props.location)(state),
videoTheaterMode: selectClientSetting(state, SETTINGS.VIDEO_THEATER_MODE),
2022-03-15 17:18:08 +01:00
activeLivestreamForChannel: selectActiveLivestreamForChannel(state, getChannelIdFromClaim(claim)),
isLivestreamClaim: isStreamPlaceholderClaim(claim),
defaultQuality: selectClientSetting(state, SETTINGS.DEFAULT_VIDEO_QUALITY),
};
};
2019-08-02 08:28:14 +02:00
2021-04-12 18:43:47 +02:00
const perform = (dispatch) => ({
changeVolume: (volume) => dispatch(doChangeVolume(volume)),
2019-08-13 07:35:13 +02:00
savePosition: (uri, position) => dispatch(savePosition(uri, position)),
2021-04-12 18:43:47 +02:00
clearPosition: (uri) => dispatch(clearPosition(uri)),
changeMute: (muted) => dispatch(doChangeMute(muted)),
2020-08-07 22:59:20 +02:00
doAnalyticsBuffer: (uri, bufferData) => dispatch(doAnalyticsBuffer(uri, bufferData)),
2021-01-08 16:21:27 +01:00
toggleVideoTheaterMode: () => dispatch(toggleVideoTheaterMode()),
toggleAutoplayNext: () => dispatch(toggleAutoplayNext()),
2021-04-12 18:43:47 +02:00
setVideoPlaybackRate: (rate) => dispatch(doSetClientSetting(SETTINGS.VIDEO_PLAYBACK_RATE, rate)),
doPlayUri: (uri, collectionId) =>
dispatch(
doPlayUri(
uri,
false,
false,
(fileInfo) => {
dispatch(doAnaltyicsPurchaseEvent(fileInfo));
},
true
),
dispatch(doSetPlayingUri({ uri, collectionId }))
),
doAnalyticsView: (uri, timeToStart) => dispatch(doAnalyticsView(uri, timeToStart)),
claimRewards: () => dispatch(doClaimEligiblePurchaseRewards()),
2022-04-25 15:28:36 +02:00
doToast: (props) => dispatch(doToast(props)),
2022-05-04 12:24:13 +02:00
doSetContentHistoryItem: (uri) => dispatch(doSetContentHistoryItem(uri)),
2019-08-02 08:28:14 +02:00
});
2020-03-19 21:25:37 +01:00
export default withRouter(connect(select, perform)(VideoViewer));