diff --git a/src/App/App.js b/src/App/App.js index d7a8ef54a..1c39635a2 100644 --- a/src/App/App.js +++ b/src/App/App.js @@ -90,6 +90,12 @@ const App = () => { action: 'PullAddonsFromAPI' } }); + services.core.transport.dispatch({ + action: 'Ctx', + args: { + action: 'PullUserFromAPI' + } + }); } }, [initialized]); return ( diff --git a/src/routes/Intro/Intro.js b/src/routes/Intro/Intro.js index a97a113f8..4e2fb74cd 100644 --- a/src/routes/Intro/Intro.js +++ b/src/routes/Intro/Intro.js @@ -186,7 +186,6 @@ const Intro = ({ queryParams }) => { tos: state.termsAccepted, privacy: state.privacyPolicyAccepted, marketing: state.marketingAccepted, - time: new Date(), from: 'web' } } diff --git a/src/routes/Player/Player.js b/src/routes/Player/Player.js index 1778c4089..e08157426 100644 --- a/src/routes/Player/Player.js +++ b/src/routes/Player/Player.js @@ -18,14 +18,14 @@ const useSettings = require('./useSettings'); const styles = require('./styles'); const Player = ({ urlParams, queryParams }) => { - const { core, chromecast } = useServices(); + const { chromecast } = useServices(); const [forceTranscoding, maxAudioChannels] = React.useMemo(() => { return [ queryParams.has('forceTranscoding'), queryParams.has('maxAudioChannels') ? parseInt(queryParams.get('maxAudioChannels'), 10) : null ]; }, [queryParams]); - const [player, updateLibraryItemState, pushToLibrary] = usePlayer(urlParams); + const [player, timeChanged, pausedChanged, ended, pushToLibrary] = usePlayer(urlParams); const [settings, updateSettings] = useSettings(); const streamingServer = useStreamingServer(); const routeFocused = useRouteFocused(); @@ -42,6 +42,7 @@ const Player = ({ urlParams, queryParams }) => { const [videoState, setVideoState] = React.useReducer( (videoState, nextVideoState) => ({ ...videoState, ...nextVideoState }), { + manifest: null, stream: null, paused: null, time: null, @@ -75,6 +76,7 @@ const Player = ({ urlParams, queryParams }) => { } }, []); const onImplementationChanged = React.useCallback((manifest) => { + setVideoState({ manifest }); manifest.props.forEach((propName) => { dispatch({ type: 'observeProp', propName }); }); @@ -93,16 +95,8 @@ const Player = ({ urlParams, queryParams }) => { setVideoState({ [propName]: propValue }); }, []); const onEnded = React.useCallback(() => { + ended(); pushToLibrary(); - if (player.libraryItem !== null) { - core.transport.dispatch({ - action: 'Ctx', - args: { - action: 'RewindLibraryItem', - args: player.libraryItem._id - } - }); - } if (player.nextVideo !== null) { window.location.replace( typeof player.nextVideo.deepLinks.player === 'string' ? @@ -302,10 +296,17 @@ const Player = ({ urlParams, queryParams }) => { dispatch({ type: 'setProp', propName: 'extraSubtitlesOutlineColor', propValue: settings.subtitlesOutlineColor }); }, [settings.subtitlesOutlineColor]); React.useEffect(() => { - if (videoState.time !== null && !isNaN(videoState.time) && videoState.duration !== null && !isNaN(videoState.duration)) { - updateLibraryItemState(videoState.time, videoState.duration); + if (videoState.time !== null && !isNaN(videoState.time) && + videoState.duration !== null && !isNaN(videoState.duration) && + videoState.manifest !== null && typeof videoState.manifest.name === 'string') { + timeChanged(videoState.time, videoState.duration, videoState.manifest.name); } - }, [videoState.time, videoState.duration]); + }, [videoState.time, videoState.duration, videoState.manifest]); + React.useEffect(() => { + if (videoState.paused !== null) { + pausedChanged(videoState.paused); + } + }, [videoState.paused]); React.useEffect(() => { if ((!Array.isArray(videoState.subtitlesTracks) || videoState.subtitlesTracks.length === 0) && (!Array.isArray(videoState.extraSubtitlesTracks) || videoState.extraSubtitlesTracks.length === 0) && diff --git a/src/routes/Player/usePlayer.js b/src/routes/Player/usePlayer.js index f9c18e9d5..9acd16396 100644 --- a/src/routes/Player/usePlayer.js +++ b/src/routes/Player/usePlayer.js @@ -86,12 +86,12 @@ const usePlayer = (urlParams) => { }; } }, [urlParams]); - const updateLibraryItemState = React.useCallback((time, duration) => { + const timeChanged = React.useCallback((time, duration, device) => { core.transport.dispatch({ action: 'Player', args: { - action: 'UpdateLibraryItemState', - args: { time, duration } + action: 'TimeChanged', + args: { time, duration, device } } }, 'player'); }, []); @@ -103,8 +103,25 @@ const usePlayer = (urlParams) => { } }, 'player'); }, []); + const ended = React.useCallback(() => { + core.transport.dispatch({ + action: 'Player', + args: { + action: 'Ended' + } + }, 'player'); + }, []); + const pausedChanged = React.useCallback((paused) => { + core.transport.dispatch({ + action: 'Player', + args: { + action: 'PausedChanged', + args: { paused } + } + }, 'player'); + }, []); const player = useModelState({ model: 'player', action, map }); - return [player, updateLibraryItemState, pushToLibrary]; + return [player, timeChanged, pausedChanged, ended, pushToLibrary]; }; module.exports = usePlayer;