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';
|
2021-09-02 22:05:32 +02:00
|
|
|
import {
|
|
|
|
makeSelectNextUrlForCollectionAndUrl,
|
|
|
|
makeSelectPreviousUrlForCollectionAndUrl,
|
2021-10-17 10:36:14 +02:00
|
|
|
} from 'redux/selectors/collections';
|
|
|
|
import * as SETTINGS from 'constants/settings';
|
|
|
|
import * as COLLECTIONS_CONSTS from 'constants/collections';
|
2021-09-10 19:27:21 +02:00
|
|
|
import {
|
|
|
|
doChangeVolume,
|
|
|
|
doChangeMute,
|
|
|
|
doAnalyticsBuffer,
|
|
|
|
doAnaltyicsPurchaseEvent,
|
2022-01-06 20:28:27 +01:00
|
|
|
doAnalyticsView,
|
2021-09-10 19:27:21 +02:00
|
|
|
} 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';
|
2022-04-01 10:18:51 +02:00
|
|
|
import { makeSelectIsPlayerFloating, selectContentPositionForUri, selectPlayingUri } from 'redux/selectors/content';
|
2021-11-16 02:10:03 +01:00
|
|
|
import { selectRecommendedContentForUri } from 'redux/selectors/search';
|
2019-08-02 08:28:14 +02:00
|
|
|
import VideoViewer from './view';
|
2020-02-04 22:14:08 +01:00
|
|
|
import { withRouter } from 'react-router';
|
2020-06-15 22:33:03 +02:00
|
|
|
import { doClaimEligiblePurchaseRewards } from 'redux/actions/rewards';
|
2021-11-23 05:29:04 +01:00
|
|
|
import { selectDaemonSettings, selectClientSetting, selectHomepageData } from 'redux/selectors/settings';
|
2022-04-20 20:40:21 +02:00
|
|
|
import { toggleVideoTheaterMode, toggleAutoplayNext, doSetClientSetting } from 'redux/actions/settings';
|
2021-06-29 03:51:04 +02:00
|
|
|
import { selectUserVerifiedEmail, selectUser } from 'redux/selectors/user';
|
2022-07-12 21:58:18 +02:00
|
|
|
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
|
|
|
|
2020-02-04 22:14:08 +01:00
|
|
|
const select = (state, props) => {
|
2022-07-12 21:58:18 +02:00
|
|
|
const { search, pathname, hash } = props.location;
|
2020-02-04 22:14:08 +01:00
|
|
|
const urlParams = new URLSearchParams(search);
|
|
|
|
const autoplay = urlParams.get('autoplay');
|
2021-09-02 22:05:32 +02:00
|
|
|
const uri = props.uri;
|
2021-10-13 17:04:03 +02:00
|
|
|
|
2022-07-12 21:58:18 +02:00
|
|
|
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);
|
|
|
|
|
2021-08-10 22:42:50 +02:00
|
|
|
// TODO: eventually this should be received from DB and not local state (https://github.com/lbryio/lbry-desktop/issues/6796)
|
2022-07-12 21:58:18 +02:00
|
|
|
const position =
|
|
|
|
startTime || (urlParams.get('t') !== null ? urlParams.get('t') : selectContentPositionForUri(state, uri));
|
2021-06-29 03:51:04 +02:00
|
|
|
const userId = selectUser(state) && selectUser(state).id;
|
2021-10-13 17:04:03 +02:00
|
|
|
const internalFeature = selectUser(state) && selectUser(state).internal_feature;
|
2021-09-02 22:05:32 +02:00
|
|
|
const playingUri = selectPlayingUri(state);
|
2022-03-15 17:28:55 +01:00
|
|
|
const collectionId = urlParams.get(COLLECTIONS_CONSTS.COLLECTION_ID) || playingUri.collectionId;
|
|
|
|
const isMarkdownOrComment = playingUri.source === 'markdown' || playingUri.source === 'comment';
|
2021-09-02 22:05:32 +02:00
|
|
|
|
|
|
|
let nextRecommendedUri;
|
|
|
|
let previousListUri;
|
|
|
|
if (collectionId) {
|
|
|
|
nextRecommendedUri = makeSelectNextUrlForCollectionAndUrl(collectionId, uri)(state);
|
|
|
|
previousListUri = makeSelectPreviousUrlForCollectionAndUrl(collectionId, uri)(state);
|
|
|
|
} else {
|
2021-11-16 02:10:03 +01:00
|
|
|
const recommendedContent = selectRecommendedContentForUri(state, uri);
|
2021-09-16 22:00:44 +02:00
|
|
|
nextRecommendedUri = recommendedContent && recommendedContent[0];
|
2021-09-02 22:05:32 +02:00
|
|
|
}
|
2020-03-19 21:25:37 +01:00
|
|
|
|
2020-02-04 22:14:08 +01:00
|
|
|
return {
|
2021-09-13 17:24:35 +02:00
|
|
|
position,
|
|
|
|
userId,
|
2021-10-13 17:04:03 +02:00
|
|
|
internalFeature,
|
2021-09-13 17:24:35 +02:00
|
|
|
collectionId,
|
|
|
|
nextRecommendedUri,
|
|
|
|
previousListUri,
|
|
|
|
isMarkdownOrComment,
|
2020-04-14 01:48:11 +02:00
|
|
|
autoplayIfEmbedded: Boolean(autoplay),
|
2021-11-23 05:29:04 +01:00
|
|
|
autoplayNext: selectClientSetting(state, SETTINGS.AUTOPLAY_NEXT),
|
2020-02-04 22:14:08 +01:00
|
|
|
volume: selectVolume(state),
|
|
|
|
muted: selectMute(state),
|
2021-11-23 05:29:04 +01:00
|
|
|
videoPlaybackRate: selectClientSetting(state, SETTINGS.VIDEO_PLAYBACK_RATE),
|
2021-11-12 16:59:11 +01:00
|
|
|
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),
|
2021-07-31 05:55:02 +02:00
|
|
|
shareTelemetry: IS_WEB || selectDaemonSettings(state).share_usage_data,
|
2021-09-02 22:05:32 +02:00
|
|
|
isFloating: makeSelectIsPlayerFloating(props.location)(state),
|
2021-11-23 05:29:04 +01:00
|
|
|
videoTheaterMode: selectClientSetting(state, SETTINGS.VIDEO_THEATER_MODE),
|
2022-03-15 17:18:08 +01:00
|
|
|
activeLivestreamForChannel: selectActiveLivestreamForChannel(state, getChannelIdFromClaim(claim)),
|
|
|
|
isLivestreamClaim: isStreamPlaceholderClaim(claim),
|
2022-04-19 18:55:32 +02:00
|
|
|
defaultQuality: selectClientSetting(state, SETTINGS.DEFAULT_VIDEO_QUALITY),
|
2020-02-04 22:14:08 +01:00
|
|
|
};
|
|
|
|
};
|
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()),
|
2021-09-02 22:05:32 +02:00
|
|
|
toggleAutoplayNext: () => dispatch(toggleAutoplayNext()),
|
2021-04-12 18:43:47 +02:00
|
|
|
setVideoPlaybackRate: (rate) => dispatch(doSetClientSetting(SETTINGS.VIDEO_PLAYBACK_RATE, rate)),
|
2021-09-10 19:27:21 +02:00
|
|
|
doPlayUri: (uri, collectionId) =>
|
|
|
|
dispatch(
|
|
|
|
doPlayUri(
|
|
|
|
uri,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
(fileInfo) => {
|
|
|
|
dispatch(doAnaltyicsPurchaseEvent(fileInfo));
|
|
|
|
},
|
|
|
|
true
|
|
|
|
),
|
|
|
|
dispatch(doSetPlayingUri({ uri, collectionId }))
|
|
|
|
),
|
2022-01-06 20:28:27 +01:00
|
|
|
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));
|