/* eslint-disable jsx-a11y/label-has-associated-control -- inputs are nested inside their labels. */ /** * Builder card "When the stream is down" (in the Station section): loop a standby file, or just * show a message, while the live stream is unreachable (config.fallback; player side: * player/features/fallback.tsx). */ import { __ } from '@wordpress/i18n'; import { useState } from '@wordpress/element'; import { ToggleControl, RangeControl } from '@wordpress/components'; import Si from '../components/Si'; import { registerBuilderSection, type BuilderSectionProps, } from '../../player/extensions'; function FallbackSection( { config, update }: BuilderSectionProps ) { const f: any = ( config as any ).fallback || {}; const set = ( patch: Record< string, unknown > ) => update( { fallback: { ...f, ...patch } } ); const [ mode, setMode ] = useState< 'track' | 'message' >( f.enabled && ! f.url ? 'message' : 'track' ); const pick = () => { const frame = ( window as any ).wp.media( { title: __( 'Choose a standby track', 'streamsera' ), multiple: false, library: { type: 'audio' }, button: { text: __( 'Use this file', 'streamsera' ) }, } ); frame.on( 'select', () => { const att = frame.state().get( 'selection' ).first().toJSON(); set( { id: att.id, url: att.url } ); } ); frame.open(); }; const chooseMode = ( m: 'track' | 'message' ) => { setMode( m ); if ( m === 'message' && f.url ) { set( { id: 0, url: '' } ); } }; return (
{ __( 'When the stream is down', 'streamsera' ) } { __( 'What listeners get if no station answers.', 'streamsera' ) }
set( { enabled: v } ) } __nextHasNoMarginBottom label="" />
{ f.enabled ? (
{ ( [ [ 'track', __( 'Loop a standby track', 'streamsera' ), 'note', ], [ 'message', __( 'Message only', 'streamsera' ), 'msg', ], ] as [ 'track' | 'message', string, string ][] ).map( ( [ v, label, icon ] ) => ( ) ) }
{ mode === 'track' ? (
{ f.url ? f.url.split( '/' ).pop() : __( 'No file chosen yet', 'streamsera' ) } { f.url ? ( ) : null }
) : null }
{ __( 'Check the live stream again every', 'streamsera' ) } set( { retryAfter: v } ) } __nextHasNoMarginBottom label={ __( 'Seconds', 'streamsera' ) } hideLabelFromVision help={ __( 'seconds', 'streamsera' ) } />
) : null }
); } registerBuilderSection( { id: 'fallback', attachTo: 'station', group: 'source', label: __( 'When the stream is down', 'streamsera' ), icon: 'warn', order: 70, Component: FallbackSection, } );