-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
442467a
commit b35a41e
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
packages/roomkit-react/src/Prebuilt/components/Notifications/DeviceInUseError.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,79 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { HMSNotificationTypes, useHMSNotifications } from '@100mslive/react-sdk'; | ||
import { Button, Dialog, Text } from '../../..'; | ||
// @ts-ignore: No implicit Any | ||
import { DialogContent, DialogRow } from '../../primitives/DialogContent'; | ||
// @ts-ignore: No implicit Any | ||
import { ToastManager } from '../Toast/ToastManager'; | ||
|
||
const Instruction = ({ description }: { description: string }) => ( | ||
<li> | ||
<DialogRow css={{ ml: '$4' }}> | ||
<Text variant="body2">{description}</Text> | ||
</DialogRow> | ||
</li> | ||
); | ||
|
||
export function DeviceInUseError() { | ||
const notification = useHMSNotifications(HMSNotificationTypes.ERROR); | ||
const [showDeviceInUseModal, setShowDeviceInUseModal] = useState(false); | ||
const [deviceType, setDeviceType] = useState(''); | ||
|
||
useEffect(() => { | ||
const error = notification?.data; | ||
if (!error || error.code !== 3003) { | ||
return; | ||
} | ||
|
||
const errorMessage = error?.message; | ||
ToastManager.addToast({ | ||
title: `Error: ${errorMessage} - ${error?.description}`, | ||
action: ( | ||
<Button outlined variant="standard" css={{ w: 'max-content' }} onClick={() => setShowDeviceInUseModal(true)}> | ||
Help | ||
</Button> | ||
), | ||
}); | ||
|
||
const hasAudio = errorMessage.includes('audio'); | ||
const hasVideo = errorMessage.includes('video'); | ||
const hasScreen = errorMessage.includes('screen'); | ||
if (hasAudio && hasVideo) { | ||
setDeviceType('camera and microphone'); | ||
} else if (hasAudio) { | ||
setDeviceType('microphone'); | ||
} else if (hasVideo) { | ||
setDeviceType('camera'); | ||
} else if (hasScreen) { | ||
setDeviceType('screen'); | ||
} | ||
}, [notification]); | ||
|
||
return ( | ||
<Dialog.Root | ||
open={showDeviceInUseModal} | ||
onOpenChange={() => { | ||
setShowDeviceInUseModal(false); | ||
}} | ||
> | ||
<DialogContent title="Device Access Error"> | ||
<DialogRow> | ||
<Text variant="body2"> | ||
We weren't able to access your {deviceType} since it's either in use by another application or is not | ||
configured properly. Please follow the following instructions to resolve this issue. | ||
</Text> | ||
</DialogRow> | ||
<ol> | ||
<Instruction | ||
description={`Please check if the ${deviceType} device(s) are in use by another browser or application and close it.`} | ||
/> | ||
<Instruction | ||
description={`Go to Browser Settings > Privacy and security > Site settings > ${deviceType} and check if your preferred device is selected as default.`} | ||
/> | ||
<Instruction description="Try restarting the browser." /> | ||
<Instruction description="Try disconnecting and reconnecting the external device if your intention is to use one." /> | ||
</ol> | ||
</DialogContent> | ||
</Dialog.Root> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters