-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathindex.tsx
More file actions
82 lines (68 loc) · 2.29 KB
/
Copy pathindex.tsx
File metadata and controls
82 lines (68 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { useEffect, useState } from 'react';
import { Button, Modal } from 'antd';
import { useSetAtom } from 'jotai';
import { VolumeOffIcon } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { videoDeviceIdAtom, videoStateAtom } from '@/jotai/device.ts';
import { camera } from '@/libs/media/camera.ts';
import { checkPermission, requestMicrophonePermission } from '@/libs/media/permission.ts';
import { MenuTooltip } from '../menu-tooltip';
export const Audio = () => {
const { t } = useTranslation();
const setVideoState = useSetAtom(videoStateAtom);
const setVideoDeviceId = useSetAtom(videoDeviceIdAtom);
const [isGranted, setIsGranted] = useState(false);
const [isModalOpen, setIsModalOpen] = useState(false);
useEffect(() => {
checkPermission('microphone').then((granted) => {
setIsGranted(granted);
});
}, []);
async function requestPermission() {
try {
const granted = await requestMicrophonePermission();
if (!granted) {
setIsModalOpen(true);
return;
}
setVideoDeviceId('');
setVideoState('disconnected');
setIsGranted(granted);
camera.close();
} catch (err: any) {
console.log('failed to request media permissions: ', err);
}
}
function closeModal() {
setIsModalOpen(false);
}
if (isGranted) {
return null;
}
return (
<>
<MenuTooltip title={t('menu.audio', 'Enable Audio')}>
<div
className="flex h-[28px] w-[28px] cursor-pointer items-center justify-center rounded text-neutral-300 hover:bg-neutral-700/70 hover:text-white"
onClick={requestPermission}
>
<VolumeOffIcon size={18} />
</div>
</MenuTooltip>
<Modal open={isModalOpen} title={t('audio.tip')} footer={null} onCancel={closeModal}>
<div className="whitespace-pre-line py-5">{t('audio.permission')}</div>
<a
href="https://wiki.sipeed.com/hardware/en/kvm/NanoKVM_USB/quick_start.html#Authorization"
target="_blank"
>
{t('audio.viewDoc')}
</a>
<div className="flex w-full justify-center pt-8">
<Button type="primary" className="min-w-20" onClick={closeModal}>
{t('audio.ok')}
</Button>
</div>
</Modal>
</>
);
};