// Copyright 2020-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT-0 import React, { ChangeEvent, useContext, useState } from 'react'; import { useHistory } from 'react-router-dom'; import { Checkbox, DeviceLabels, Flex, FormField, Heading, Input, Modal, ModalBody, ModalHeader, PrimaryButton, Select, useMeetingManager, } from 'amazon-chime-sdk-component-library-react'; import { DefaultBrowserBehavior, MeetingSessionConfiguration } from 'amazon-chime-sdk-js'; import { getErrorContext } from '../../providers/ErrorProvider'; import routes from '../../constants/routes'; import Card from '../../components/Card'; import Spinner from '../../components/icons/Spinner'; import DevicePermissionPrompt from '../DevicePermissionPrompt'; import RegionSelection from './RegionSelection'; import { createGetAttendeeCallback, fetchMeeting } from '../../utils/api'; import { useAppState } from '../../providers/AppStateProvider'; import { MeetingMode, VideoFiltersCpuUtilization } from '../../types'; import { MeetingManagerJoinOptions } from 'amazon-chime-sdk-component-library-react/lib/providers/MeetingProvider/types'; import meetingConfig from '../../meetingConfig'; const VIDEO_TRANSFORM_FILTER_OPTIONS = [ { value: VideoFiltersCpuUtilization.Disabled, label: 'Disable Video Filter' }, { value: VideoFiltersCpuUtilization.CPU10Percent, label: 'Video Filter CPU 10%' }, { value: VideoFiltersCpuUtilization.CPU20Percent, label: 'Video Filter CPU 20%' }, { value: VideoFiltersCpuUtilization.CPU40Percent, label: 'Video Filter CPU 40%' }, ]; const MeetingForm: React.FC = () => { const meetingManager = useMeetingManager(); const { region, meetingId, localUserName, meetingMode, enableSimulcast, priorityBasedPolicy, keepLastFrameWhenPaused, isWebAudioEnabled, videoTransformCpuUtilization: videoTransformCpuUtilization, setJoinInfo, isEchoReductionEnabled, toggleEchoReduction, toggleWebAudio, toggleSimulcast, togglePriorityBasedPolicy, toggleKeepLastFrameWhenPaused, setMeetingMode, setMeetingId, setLocalUserName, setRegion, setCpuUtilization, skipDeviceSelection, toggleMeetingJoinDeviceSelection, } = useAppState(); const [meetingErr, setMeetingErr] = useState(false); const [nameErr, setNameErr] = useState(false); const [isLoading, setIsLoading] = useState(false); const { errorMessage, updateErrorMessage } = useContext(getErrorContext()); const history = useHistory(); const browserBehavior = new DefaultBrowserBehavior(); const handleJoinMeeting = async (e: React.FormEvent) => { e.preventDefault(); const id = meetingId.trim().toLocaleLowerCase(); const attendeeName = localUserName.trim(); if (!id || !attendeeName) { if (!attendeeName) { setNameErr(true); } if (!id) { setMeetingErr(true); } return; } setIsLoading(true); meetingManager.getAttendee = createGetAttendeeCallback(id); try { const { JoinInfo } = await fetchMeeting(id, attendeeName, region, isEchoReductionEnabled); setJoinInfo(JoinInfo); const meetingSessionConfiguration = new MeetingSessionConfiguration(JoinInfo?.Meeting, JoinInfo?.Attendee); if ( meetingConfig.postLogger && meetingSessionConfiguration.meetingId && meetingSessionConfiguration.credentials && meetingSessionConfiguration.credentials.attendeeId ) { const existingMetadata = meetingConfig.postLogger.metadata; meetingConfig.postLogger.metadata = { ...existingMetadata, meetingId: meetingSessionConfiguration.meetingId, attendeeId: meetingSessionConfiguration.credentials.attendeeId, }; } setRegion(JoinInfo.Meeting.MediaRegion); meetingSessionConfiguration.enableSimulcastForUnifiedPlanChromiumBasedBrowsers = enableSimulcast; if (priorityBasedPolicy) { meetingSessionConfiguration.videoDownlinkBandwidthPolicy = priorityBasedPolicy; } meetingSessionConfiguration.keepLastFrameWhenPaused = keepLastFrameWhenPaused; const options: MeetingManagerJoinOptions = { deviceLabels: meetingMode === MeetingMode.Spectator ? DeviceLabels.None : DeviceLabels.AudioAndVideo, enableWebAudio: isWebAudioEnabled, skipDeviceSelection, }; await meetingManager.join(meetingSessionConfiguration, options); if (meetingMode === MeetingMode.Spectator) { await meetingManager.start(); history.push(`${routes.MEETING}/${meetingId}`); } else { setMeetingMode(MeetingMode.Attendee); history.push(routes.DEVICE); } } catch (error) { updateErrorMessage((error as Error).message); } }; const closeError = (): void => { updateErrorMessage(''); setMeetingId(''); setLocalUserName(''); setIsLoading(false); }; return (
); }; export default MeetingForm;