diff --git a/src/routes/Player/CastDevicesMenu/CastDevicesMenu.tsx b/src/routes/Player/CastDevicesMenu/CastDevicesMenu.tsx index 567361201..92cf7dd58 100644 --- a/src/routes/Player/CastDevicesMenu/CastDevicesMenu.tsx +++ b/src/routes/Player/CastDevicesMenu/CastDevicesMenu.tsx @@ -14,10 +14,11 @@ type CastDevice = { type Props = { className: string, devices: CastDevice[], + loading: boolean, onDeviceSelected: (deviceId: string) => void, }; -const CastDevicesMenu = memo(forwardRef(({ className, devices, onDeviceSelected }, ref) => { +const CastDevicesMenu = memo(forwardRef(({ className, devices, loading, onDeviceSelected }, ref) => { const { t } = useTranslation(); const onMouseDown = (event: MouseEvent) => { @@ -28,15 +29,25 @@ const CastDevicesMenu = memo(forwardRef(({ className, dev return (
{ - devices.map(({ id, name }) => ( -
); diff --git a/src/routes/Player/CastDevicesMenu/styles.less b/src/routes/Player/CastDevicesMenu/styles.less index 5832af248..4b4d861c6 100644 --- a/src/routes/Player/CastDevicesMenu/styles.less +++ b/src/routes/Player/CastDevicesMenu/styles.less @@ -3,4 +3,11 @@ .cast-devices-menu-container { width: 16rem; padding: 1rem; + + .message { + padding: 1rem; + color: var(--primary-foreground-color); + opacity: 0.7; + text-align: center; + } } diff --git a/src/routes/Player/ControlBar/ControlBar.js b/src/routes/Player/ControlBar/ControlBar.js index 1aefdba71..6eac8ca18 100644 --- a/src/routes/Player/ControlBar/ControlBar.js +++ b/src/routes/Player/ControlBar/ControlBar.js @@ -39,7 +39,8 @@ const ControlBar = React.forwardRef(({ onToggleSpeedMenu, onToggleSideDrawer, onToggleOptionsMenu, - shellCastAvailable, + shellCastSupported, + onRefreshCastDevices, onToggleCastDevicesMenu, videoScale, videoScaleLabel, @@ -100,19 +101,22 @@ const ControlBar = React.forwardRef(({ } } }, [muted, onMuteRequested, onUnmuteRequested]); - const castButtonDisabled = platform.shell.active ? !shellCastAvailable : !chromecastServiceActive; + const castButtonDisabled = platform.shell.active ? !shellCastSupported : !chromecastServiceActive; const onChromecastButtonClick = React.useCallback(() => { + if (platform.shell.active) { + if (typeof onRefreshCastDevices === 'function') { + onRefreshCastDevices(); + } + if (shellCastSupported && typeof onToggleCastDevicesMenu === 'function') { + onToggleCastDevicesMenu(); + } + return; + } if (castButtonDisabled) { return; } - if (platform.shell.active) { - if (typeof onToggleCastDevicesMenu === 'function') { - onToggleCastDevicesMenu(); - } - } else { - chromecast.transport.requestSession(); - } - }, [castButtonDisabled, platform.shell.active, onToggleCastDevicesMenu]); + chromecast.transport.requestSession(); + }, [castButtonDisabled, platform.shell.active, shellCastSupported, onRefreshCastDevices, onToggleCastDevicesMenu]); React.useEffect(() => { const onStateChanged = () => { setChromecastServiceActive(chromecast.active); @@ -236,7 +240,8 @@ ControlBar.propTypes = { onToggleSpeedMenu: PropTypes.func, onToggleSideDrawer: PropTypes.func, onToggleOptionsMenu: PropTypes.func, - shellCastAvailable: PropTypes.bool, + shellCastSupported: PropTypes.bool, + onRefreshCastDevices: PropTypes.func, onToggleCastDevicesMenu: PropTypes.func, onToggleStatisticsMenu: PropTypes.func, onMouseOver: PropTypes.func, diff --git a/src/routes/Player/Player.js b/src/routes/Player/Player.js index 6f79e2e26..b07fc695c 100644 --- a/src/routes/Player/Player.js +++ b/src/routes/Player/Player.js @@ -104,10 +104,21 @@ const Player = ({ urlParams, queryParams }) => { const castDevices = React.useMemo(() => { return playbackDevices.filter(({ type }) => type === 'chromecast' || type === 'tv'); }, [playbackDevices]); + const castDevicesLoading = platform.shell.active && streamingServer.playbackDevices !== null && streamingServer.playbackDevices.type === 'Loading'; const castStreamingUrl = React.useMemo(() => { return player.selected?.stream?.deepLinks?.externalPlayer?.streaming || null; }, [player.selected]); - const shellCastAvailable = platform.shell.active && castStreamingUrl !== null && castDevices.length > 0; + const shellCastSupported = platform.shell.active && castStreamingUrl !== null; + const refreshCastDevices = React.useCallback(() => { + if (platform.shell.active) { + core.transport.dispatch({ + action: 'StreamingServer', + args: { + action: 'RefreshPlaybackDevices', + } + }); + } + }, [platform.shell.active]); const onCastDeviceSelected = React.useCallback((deviceId) => { if (castStreamingUrl) { core.transport.dispatch({ @@ -123,6 +134,11 @@ const Player = ({ urlParams, queryParams }) => { closeCastDevicesMenu(); } }, [castStreamingUrl]); + React.useEffect(() => { + if (castDevicesMenuOpen) { + refreshCastDevices(); + } + }, [castDevicesMenuOpen, refreshCastDevices]); const { streamSubtitles, @@ -907,7 +923,8 @@ const Player = ({ urlParams, queryParams }) => { onVolumeChangeRequested={onVolumeChangeRequested} onSeekRequested={onSeekRequested} onToggleOptionsMenu={toggleOptionsMenu} - shellCastAvailable={shellCastAvailable} + shellCastSupported={shellCastSupported} + onRefreshCastDevices={refreshCastDevices} onToggleCastDevicesMenu={toggleCastDevicesMenu} onToggleSubtitlesMenu={toggleSubtitlesMenu} onToggleAudioMenu={toggleAudioMenu} @@ -948,6 +965,7 @@ const Player = ({ urlParams, queryParams }) => {