import React, { useEffect, useState } from 'react'; import { Button } from '@dailyjs/shared/components/Button'; import Field from '@dailyjs/shared/components/Field'; import { TextInput } from '@dailyjs/shared/components/Input'; import Modal from '@dailyjs/shared/components/Modal'; import { Well } from '@dailyjs/shared/components/Well'; import { useCallState } from '@dailyjs/shared/contexts/CallProvider'; import { useUIState } from '@dailyjs/shared/contexts/UIStateProvider'; import { useLiveStreaming } from '../../contexts/LiveStreamingProvider'; export const LIVE_STREAMING_MODAL = 'live-streaming'; export const LiveStreamingModal = () => { const { callObject } = useCallState(); const { currentModals, closeModal } = useUIState(); const { isStreaming, streamError } = useLiveStreaming(); const [pending, setPending] = useState(false); const [rtmpUrl, setRtmpUrl] = useState(''); useEffect(() => { // Reset pending state whenever stream state changes setPending(false); }, [isStreaming]); function startLiveStream() { setPending(true); callObject.startLiveStreaming({ rtmpUrl }); } function stopLiveStreaming() { setPending(true); callObject.stopLiveStreaming(); } return ( closeModal(LIVE_STREAMING_MODAL)} > {streamError && ( Unable to start stream. Error message: {streamError} )} setRtmpUrl(e.target.value)} /> {!isStreaming ? ( ) : ( )} ); }; export default LiveStreamingModal;