import React, { useEffect, useState } from 'react'; import Button from '@custom/shared/components/Button'; import { CardBody } from '@custom/shared/components/Card'; import Field from '@custom/shared/components/Field'; import { TextInput, SelectInput } from '@custom/shared/components/Input'; import Modal from '@custom/shared/components/Modal'; import Well from '@custom/shared/components/Well'; import { useLiveStreaming } from '@custom/shared/contexts/LiveStreamingProvider'; import { useParticipants } from '@custom/shared/contexts/ParticipantsProvider'; import { useUIState } from '@custom/shared/contexts/UIStateProvider'; export const LIVE_STREAMING_MODAL = 'live-streaming'; const LAYOUTS = [ { label: 'Grid (default)', value: 'default' }, { label: 'Single participant', value: 'single-participant' }, { label: 'Active participant', value: 'active-participant' }, ]; export const LiveStreamingModal = () => { const { participants } = useParticipants(); const { currentModals, closeModal } = useUIState(); const { isStreaming, streamError, startLiveStreaming, stopLiveStreaming, } = useLiveStreaming(); const [pending, setPending] = useState(false); const [rtmpUrl, setRtmpUrl] = useState(''); const [layoutType, setLayoutType] = useState('default'); const [maxCams, setMaxCams] = useState(9); const [participantId, setParticipantId] = useState(0); useEffect(() => { // Reset pending state whenever stream state changes setPending(false); }, [isStreaming]); function startLiveStream() { const config = { rtmpUrl, layout: { preset: layoutType, }, }; if (layoutType === 'single-participant') config.layout.session_id = participantId; else if (layoutType === 'default') config.layout.max_cam_streams = maxCams; startLiveStreaming(config); } function stopLiveStream() { setPending(true); stopLiveStreaming(); } const handleRMTPURLChange = (e) => setRtmpUrl(e.target.value); const handleSelectLayoutInputChange = (e) => setLayoutType(e.target.value); const handleSelectParticipantInputChange = (e) => setParticipantId(e.target.value); const handleSelectMaxCamsInputChange = (e) => setMaxCams(e.target.valueAsNumber); return ( closeModal(LIVE_STREAMING_MODAL)} actions={[ , !isStreaming ? ( ) : ( ), ]} > {streamError && ( Unable to start stream. Error message: {streamError} )} {LAYOUTS.map((l) => ( ))} {layoutType === 'default' && ( )} {layoutType === 'single-participant' && ( {participants.map((p) => ( ))} )} Want to learn more about RTMP url? ); }; export default LiveStreamingModal;