From 846284ff9fae3f221a22db624953b2d893072efe Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 7 Apr 2023 16:54:05 +0200 Subject: [PATCH] refactor(OptionsMenu): use latests core changes --- src/routes/Player/OptionsMenu/OptionsMenu.js | 65 +++++++++++--------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/src/routes/Player/OptionsMenu/OptionsMenu.js b/src/routes/Player/OptionsMenu/OptionsMenu.js index d15fe314c..6e3736691 100644 --- a/src/routes/Player/OptionsMenu/OptionsMenu.js +++ b/src/routes/Player/OptionsMenu/OptionsMenu.js @@ -11,23 +11,20 @@ const styles = require('./styles'); const OptionsMenu = ({ className, stream, playbackDevices }) => { const { core } = useServices(); const toast = useToast(); - const streamUrl = React.useMemo(() => { + const [streamingUrl, downloadUrl] = React.useMemo(() => { return stream !== null ? stream.deepLinks && stream.deepLinks.externalPlayer && - typeof stream.deepLinks.externalPlayer.download === 'string' ? - stream.deepLinks.externalPlayer.download - : - null + [stream.deepLinks.externalPlayer.streaming, stream.deepLinks.externalPlayer.download] : - null; + [null, null]; }, [stream]); const externalDevices = React.useMemo(() => { return playbackDevices.filter(({ type }) => type === 'external'); }, [playbackDevices]); const onCopyStreamButtonClick = React.useCallback(() => { - if (streamUrl !== null) { - navigator.clipboard.writeText(streamUrl) + if (streamingUrl || downloadUrl) { + navigator.clipboard.writeText(streamingUrl || downloadUrl) .then(() => { toast.show({ type: 'success', @@ -41,50 +38,60 @@ const OptionsMenu = ({ className, stream, playbackDevices }) => { toast.show({ type: 'error', title: 'Error', - message: `Failed to copy stream link: ${streamUrl}`, + message: `Failed to copy stream link: ${streamingUrl || downloadUrl}`, timeout: 3000 }); }); } - }, [streamUrl]); + }, [streamingUrl, downloadUrl]); const onDownloadVideoButtonClick = React.useCallback(() => { - if (streamUrl !== null) { - window.open(streamUrl); + if (streamingUrl || downloadUrl) { + window.open(streamingUrl || downloadUrl); } - }, [streamUrl]); + }, [streamingUrl, downloadUrl]); const onExternalDeviceRequested = React.useCallback((deviceId) => { - if (streamUrl !== null) { + if (streamingUrl) { core.transport.dispatch({ action: 'StreamingServer', args: { action: 'PlayOnDevice', args: { device: deviceId, - source: streamUrl, + source: streamingUrl, } } }); } - }, [streamUrl]); + }, [streamingUrl]); const onMouseDown = React.useCallback((event) => { event.nativeEvent.optionsMenuClosePrevented = true; }, []); return (
-