import React, { useEffect, useState } from 'react';
import { useMedia } from 'react-use';
import {
HMSException,
HMSNotificationTypes,
HMSTrackException,
HMSTrackExceptionTrackType,
useHMSNotifications,
} from '@100mslive/react-sdk';
import { Button, config as cssConfig, Dialog, Flex, Text } from '../../..';
// @ts-ignore: No implicit Any
import androidPermissionAlert from '../../images/android-perm-1.png';
// @ts-ignore: No implicit Any
import iosPermissions from '../../images/ios-perm-0.png';
// @ts-ignore: No implicit Any
import { isAndroid, isIOS } from '../../common/constants';
export function PermissionErrorNotificationModal() {
const notification = useHMSNotifications(HMSNotificationTypes.ERROR);
return ;
}
export const PermissionErrorModal = ({ error }: { error?: HMSException }) => {
const [deviceType, setDeviceType] = useState('');
const [isSystemError, setIsSystemError] = useState(false);
const isMobile = useMedia(cssConfig.media.md);
useEffect(() => {
if (
!error ||
(error?.code !== 3001 && error?.code !== 3011) ||
(error?.code === 3001 && error?.message.includes('screen'))
) {
return;
}
const errorTrackExceptionType = (error as HMSTrackException)?.trackType;
const hasAudio = errorTrackExceptionType === HMSTrackExceptionTrackType.AUDIO;
const hasVideo = errorTrackExceptionType === HMSTrackExceptionTrackType.VIDEO;
const hasAudioVideo = errorTrackExceptionType === HMSTrackExceptionTrackType.AUDIO_VIDEO;
const hasScreen = errorTrackExceptionType === HMSTrackExceptionTrackType.SCREEN;
if (hasAudioVideo) {
setDeviceType('camera and microphone');
} else if (hasAudio) {
setDeviceType('microphone');
} else if (hasVideo) {
setDeviceType('camera');
} else if (hasScreen) {
setDeviceType('screen');
}
setIsSystemError(error.code === 3011);
}, [error]);
return deviceType ? (
{isMobile && isIOS ? (
) : null}
{/* Images for android */}
{isMobile && isAndroid ? (
) : null}
We can't access your {deviceType}
{/* IOS prompt text */}
{isMobile && isIOS
? 'Enable permissions by reloading this page and clicking "Allow" on the pop-up, or change settings from the address bar.'
: null}
{/* Prompt for android devices */}
{isMobile && isAndroid
? `To allow other users to see and hear you, click the blocked camera icon in your browser's address bar.`
: null}
{/* Prompt for desktops */}
{!isMobile ? `Access to ${deviceType} is required. ` : null}
{isSystemError && !isMobile
? `Enable permissions for ${deviceType}${deviceType === 'screen' ? 'share' : ''} from sytem settings`
: null}
{!isSystemError && !isMobile
? `Enable permissions for ${deviceType}${
deviceType === 'screen' ? 'share' : ''
} from address bar or browser settings.`
: null}
{/* CTA section */}
{isMobile && isIOS ? (
<>
>
) : null}
{isMobile && isAndroid ? (
<>
>
) : null}
{!isMobile ? (
) : null}
) : null;
};