disable countdown for floating window

This commit is contained in:
Sean Yesmunt 2020-01-27 14:32:20 -05:00
parent d312a8e8b6
commit f4da12128a
5 changed files with 58 additions and 15 deletions

View file

@ -3,6 +3,7 @@ import { connect } from 'react-redux';
import { makeSelectClaimForUri } from 'lbry-redux'; import { makeSelectClaimForUri } from 'lbry-redux';
import { makeSelectNextUnplayedRecommended } from 'redux/selectors/content'; import { makeSelectNextUnplayedRecommended } from 'redux/selectors/content';
import { makeSelectClientSetting } from 'redux/selectors/settings'; import { makeSelectClientSetting } from 'redux/selectors/settings';
import { doSetPlayingUri } from 'redux/actions/content';
import RecommendedVideos from './view'; import RecommendedVideos from './view';
const select = (state, props) => { const select = (state, props) => {
@ -14,7 +15,9 @@ const select = (state, props) => {
}; };
}; };
const perform = (dispatch, ownProps) => ({}); const perform = dispatch => ({
setPlayingUri: uri => dispatch(doSetPlayingUri(uri)),
});
export default connect( export default connect(
select, select,

View file

@ -9,12 +9,14 @@ type Props = {
history: { push: string => void }, history: { push: string => void },
nextRecommendedClaim: ?StreamClaim, nextRecommendedClaim: ?StreamClaim,
nextRecommendedUri: string, nextRecommendedUri: string,
setPlayingUri: (string | null) => void,
}; };
function AutoplayCountdown(props: Props) { function AutoplayCountdown(props: Props) {
const { const {
nextRecommendedUri, nextRecommendedUri,
nextRecommendedClaim, nextRecommendedClaim,
setPlayingUri,
history: { push }, history: { push },
} = props; } = props;
const nextTitle = nextRecommendedClaim && nextRecommendedClaim.value && nextRecommendedClaim.value.title; const nextTitle = nextRecommendedClaim && nextRecommendedClaim.value && nextRecommendedClaim.value.title;
@ -32,6 +34,8 @@ function AutoplayCountdown(props: Props) {
interval = setInterval(() => { interval = setInterval(() => {
const newTime = timer - 1; const newTime = timer - 1;
if (newTime === 0) { if (newTime === 0) {
// Set the playingUri to null so the app doesn't try to make a floating window with the video that just finished
setPlayingUri(null);
push(navigateUrl); push(navigateUrl);
} else { } else {
setTimer(timer - 1); setTimer(timer - 1);
@ -41,7 +45,7 @@ function AutoplayCountdown(props: Props) {
return () => { return () => {
clearInterval(interval); clearInterval(interval);
}; };
}, [timer, navigateUrl, push, timerCanceled]); }, [timer, navigateUrl, push, timerCanceled, setPlayingUri, nextRecommendedUri]);
if (timerCanceled) { if (timerCanceled) {
return null; return null;
@ -49,12 +53,14 @@ function AutoplayCountdown(props: Props) {
return ( return (
<div className="video-overlay__wrapper"> <div className="video-overlay__wrapper">
<div className="video-overlay__subtitle">Up Next</div> <div className="video-overlay__subtitle">{__('Up Next')}</div>
<div className="video-overlay__title">{nextTitle}</div> <div className="video-overlay__title">{nextTitle}</div>
<UriIndicator link uri={nextRecommendedUri} /> <UriIndicator link uri={nextRecommendedUri} />
<div className="video-overlay__actions"> <div className="video-overlay__actions">
<div className="video-overlay__subtitle">Playing in {timer} seconds</div> <div className="video-overlay__subtitle">
{__('Playing in %seconds_left% seconds', { seconds_left: timer })}
</div>
<div className="section__actions--centered"> <div className="section__actions--centered">
<Button label={__('Cancel')} button="secondary" onClick={() => setTimerCanceled(true)} /> <Button label={__('Cancel')} button="secondary" onClick={() => setTimerCanceled(true)} />
</div> </div>

View file

@ -11,6 +11,7 @@ import {
import * as SETTINGS from 'constants/settings'; import * as SETTINGS from 'constants/settings';
import { makeSelectClientSetting } from 'redux/selectors/settings'; import { makeSelectClientSetting } from 'redux/selectors/settings';
import { makeSelectIsText } from 'redux/selectors/content'; import { makeSelectIsText } from 'redux/selectors/content';
import { doSetPlayingUri } from 'redux/actions/content';
import FileRender from './view'; import FileRender from './view';
const select = (state, props) => ({ const select = (state, props) => ({
@ -22,7 +23,15 @@ const select = (state, props) => ({
downloadPath: makeSelectDownloadPathForUri(props.uri)(state), downloadPath: makeSelectDownloadPathForUri(props.uri)(state),
fileName: makeSelectFileNameForUri(props.uri)(state), fileName: makeSelectFileNameForUri(props.uri)(state),
streamingUrl: makeSelectStreamingUrlForUri(props.uri)(state), streamingUrl: makeSelectStreamingUrlForUri(props.uri)(state),
autoplay: makeSelectClientSetting(SETTINGS.AUTOPLAY)(state),
isText: makeSelectIsText(props.uri)(state), isText: makeSelectIsText(props.uri)(state),
}); });
export default connect(select)(FileRender); const perform = dispatch => ({
setPlayingUri: uri => dispatch(doSetPlayingUri(uri)),
});
export default connect(
select,
perform
)(FileRender);

View file

@ -36,6 +36,9 @@ type Props = {
currentTheme: string, currentTheme: string,
downloadPath: string, downloadPath: string,
fileName: string, fileName: string,
autoplay: boolean,
setPlayingUri: (string | null) => void,
currentlyFloating: boolean,
}; };
type State = { type State = {
@ -51,7 +54,8 @@ class FileRender extends React.PureComponent<Props, State> {
}; };
(this: any).escapeListener = this.escapeListener.bind(this); (this: any).escapeListener = this.escapeListener.bind(this);
(this: any).onEndedCb = this.onEndedCb.bind(this); (this: any).onEndedAutoplay = this.onEndedAutoplay.bind(this);
(this: any).getOnEndedCb = this.getOnEndedCb.bind(this);
} }
componentDidMount() { componentDidMount() {
@ -76,8 +80,25 @@ class FileRender extends React.PureComponent<Props, State> {
remote.getCurrentWindow().setFullScreen(false); remote.getCurrentWindow().setFullScreen(false);
} }
onEndedCb() { getOnEndedCb() {
this.setState({ showAutoplayCountdown: true }); const { setPlayingUri, currentlyFloating } = this.props;
if (!currentlyFloating) {
return this.onEndedAutoplay;
}
// if (embeded) {
// return this.onEndedEmbed
// }
return () => setPlayingUri(null);
}
onEndedAutoplay() {
const { autoplay } = this.props;
if (autoplay) {
this.setState({ showAutoplayCountdown: true });
}
} }
renderViewer() { renderViewer() {
@ -99,8 +120,8 @@ class FileRender extends React.PureComponent<Props, State> {
application: <AppViewer uri={uri} />, application: <AppViewer uri={uri} />,
// @endif // @endif
video: <VideoViewer uri={uri} source={source} contentType={contentType} onEndedCB={this.onEndedCb} />, video: <VideoViewer uri={uri} source={source} contentType={contentType} onEndedCB={this.getOnEndedCb()} />,
audio: <VideoViewer uri={uri} source={source} contentType={contentType} onEndedCB={this.onEndedCb} />, audio: <VideoViewer uri={uri} source={source} contentType={contentType} onEndedCB={this.getOnEndedCb()} />,
image: <ImageViewer uri={uri} source={source} />, image: <ImageViewer uri={uri} source={source} />,
// Add routes to viewer... // Add routes to viewer...
}; };
@ -108,10 +129,10 @@ class FileRender extends React.PureComponent<Props, State> {
// Supported contentTypes // Supported contentTypes
const contentTypes = { const contentTypes = {
'application/x-ext-mkv': ( 'application/x-ext-mkv': (
<VideoViewer uri={uri} source={source} contentType={contentType} onEndedCB={this.onEndedCb} /> <VideoViewer uri={uri} source={source} contentType={contentType} onEndedCB={this.getOnEndedCb()} />
), ),
'video/x-matroska': ( 'video/x-matroska': (
<VideoViewer uri={uri} source={source} contentType={contentType} onEndedCB={this.onEndedCb} /> <VideoViewer uri={uri} source={source} contentType={contentType} onEndedCB={this.getOnEndedCb()} />
), ),
'application/pdf': <PdfViewer source={downloadPath || source} />, 'application/pdf': <PdfViewer source={downloadPath || source} />,
'text/html': <HtmlViewer source={downloadPath || source} />, 'text/html': <HtmlViewer source={downloadPath || source} />,
@ -189,12 +210,12 @@ class FileRender extends React.PureComponent<Props, State> {
} }
render() { render() {
const { isText, uri } = this.props; const { isText, uri, currentlyFloating } = this.props;
const { showAutoplayCountdown } = this.state; const { showAutoplayCountdown } = this.state;
return ( return (
<div className={classnames('file-render', { 'file-render--document': isText })}> <div className={classnames('file-render', { 'file-render--document': isText })}>
{showAutoplayCountdown && <AutoplayCountdown uri={uri} />} {!currentlyFloating && showAutoplayCountdown && <AutoplayCountdown uri={uri} />}
<Suspense fallback={<div />}>{this.renderViewer()}</Suspense> <Suspense fallback={<div />}>{this.renderViewer()}</Suspense>
</div> </div>
); );

View file

@ -175,7 +175,11 @@ export default function FileViewer(props: Props) {
</div> </div>
)} )}
{isReadyToPlay ? <FileRender uri={uri} /> : <LoadingScreen status={loadingMessage} />} {isReadyToPlay ? (
<FileRender currentlyFloating={!inline} uri={uri} />
) : (
<LoadingScreen status={loadingMessage} />
)}
{!inline && ( {!inline && (
<div className="draggable content__info"> <div className="draggable content__info">
<div className="claim-preview-title" title={title || uri}> <div className="claim-preview-title" title={title || uri}>