diff --git a/src/routes/Player/Video/Video.js b/src/routes/Player/Video/Video.js index 30aa1f76d..98c1a29ce 100644 --- a/src/routes/Player/Video/Video.js +++ b/src/routes/Player/Video/Video.js @@ -16,16 +16,14 @@ const Video = React.forwardRef(({ className, ...props }, ref) => { const onImplementationChangedRef = useLiveRef(props.onImplementationChanged); const videoElementRef = React.useRef(null); const videoRef = React.useRef(null); - const dispatch = React.useCallback((args) => { - if (args && args.commandName === 'load' && args.commandArgs) { - const Video = selectVideoImplementation(args.commandArgs.shell, args.commandArgs.stream); - if (typeof Video !== 'function') { - videoRef.current = null; - } else if (videoRef.current === null || videoRef.current.constructor !== Video) { - dispatch({ commandName: 'destroy' }); + const dispatch = React.useCallback((action) => { + if (action && action.type === 'command' && action.commandName === 'load' && action.commandArgs) { + const Video = selectVideoImplementation(action.commandArgs); + if (videoRef.current === null || videoRef.current.constructor !== Video) { + dispatch({ type: 'command', commandName: 'destroy' }); videoRef.current = new Video({ - containerElement: videoElementRef.current, - shell: args.commandArgs.shell + ...action.commandArgs, + containerElement: videoElementRef.current }); videoRef.current.on('ended', () => { if (typeof onEndedRef.current === 'function') { @@ -60,17 +58,17 @@ const Video = React.forwardRef(({ className, ...props }, ref) => { if (videoRef.current !== null) { try { - videoRef.current.dispatch(args); - } catch (e) { + videoRef.current.dispatch(action); + } catch (error) { // eslint-disable-next-line no-console - console.error(videoRef.current.constructor.manifest.name, e); + console.error(videoRef.current.constructor.manifest.name, error); } } }, []); React.useImperativeHandle(ref, () => ({ dispatch }), []); React.useEffect(() => { return () => { - dispatch({ commandName: 'destroy' }); + dispatch({ type: 'command', commandName: 'destroy' }); }; }, []); return ( diff --git a/src/routes/Player/Video/selectVideoImplementation.js b/src/routes/Player/Video/selectVideoImplementation.js index 787b5378d..98c0e2aba 100644 --- a/src/routes/Player/Video/selectVideoImplementation.js +++ b/src/routes/Player/Video/selectVideoImplementation.js @@ -1,25 +1,21 @@ // Copyright (C) 2017-2020 Smart code 203358507 -const { HTMLVideo, YouTubeVideo, MPVVideo, withStreamingServer, withHTMLSubtitles } = require('stremio-video'); +const { ChromecastVideo, HTMLVideo, YouTubeVideo, withStreamingServer, withHTMLSubtitles } = require('stremio-video'); -const selectVideoImplementation = (shell, stream) => { +const selectVideoImplementation = (args) => { // TODO handle stream.behaviorHints // TODO handle IFrameVideo - // TODO handle ChromecastVideo + // TODO handle MPVVideo - if (shell) { - return withHTMLSubtitles(withStreamingServer(MPVVideo)); + if (args.chromecastTransport && args.chromecastTransport.getSessionState() === cast.framework.SessionState.SESSION_STARTED) { + return ChromecastVideo; } - if (stream) { - if (typeof stream.ytId === 'string') { - return withHTMLSubtitles(YouTubeVideo); - } else if (typeof stream.url === 'string' || typeof stream.infoHash === 'string') { - return withHTMLSubtitles(withStreamingServer(HTMLVideo)); - } + if (args.stream && typeof args.stream.ytId === 'string') { + return withHTMLSubtitles(YouTubeVideo); } - return null; + return withHTMLSubtitles(withStreamingServer(HTMLVideo)); }; module.exports = selectVideoImplementation;