diff --git a/examples/react-native/WhipWhepDemo/app/whip.tsx b/examples/react-native/WhipWhepDemo/app/whip.tsx index 008887e6..82f727d2 100644 --- a/examples/react-native/WhipWhepDemo/app/whip.tsx +++ b/examples/react-native/WhipWhepDemo/app/whip.tsx @@ -26,6 +26,9 @@ export default function WhipScreen() { const [isLoading, setIsLoading] = useState(false); const [shouldShowStreamBtn, setShouldShowStreamBtn] = useState(true); const [streamMode, setStreamMode] = useState('selection'); + const [isAudioPaused, setIsAudioPaused] = useState(false); + const [isVideoPaused, setIsVideoPaused] = useState(false); + const [errorMessage, setErrorMessage] = useState(null); const whipClient = useRef(null); @@ -118,6 +121,12 @@ export default function WhipScreen() { const handleDisconnectBtnClick = async () => { try { await whipClient.current?.disconnect(); + // The client keeps its pause state across disconnects, so resume + // explicitly to start the next stream from a clean state. + await whipClient.current?.setAudioPaused(false); + await whipClient.current?.setVideoPaused(false); + setIsAudioPaused(false); + setIsVideoPaused(false); setShouldShowStreamBtn(true); } catch (error) { console.error('Failed to disconnect from WHIP Client', error); @@ -149,6 +158,32 @@ export default function WhipScreen() { } }, []); + const handleToggleAudio = useCallback(async () => { + const paused = !isAudioPaused; + try { + await whipClient.current?.setAudioPaused(paused); + setIsAudioPaused(paused); + setErrorMessage(null); + } catch (error) { + setErrorMessage( + `Failed to ${paused ? 'pause' : 'resume'} audio: ${error}`, + ); + } + }, [isAudioPaused]); + + const handleToggleVideo = useCallback(async () => { + const paused = !isVideoPaused; + try { + await whipClient.current?.setVideoPaused(paused); + setIsVideoPaused(paused); + setErrorMessage(null); + } catch (error) { + setErrorMessage( + `Failed to ${paused ? 'pause' : 'resume'} video: ${error}`, + ); + } + }, [isVideoPaused]); + const handleSetH264VideoCodec = useCallback(async () => { if (whipClient.current) { try { @@ -233,6 +268,10 @@ export default function WhipScreen() { + {errorMessage && ( + {errorMessage} + )} + {streamMode === 'camera' && ( <>