From 938df73910265b80c083a1f0d5fa7dc7869096ab Mon Sep 17 00:00:00 2001 From: yj <1336058017@qq.com> Date: Wed, 14 Aug 2024 16:32:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/JoinSetting/index.tsx | 59 +++++++++++----------------- 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/src/components/JoinSetting/index.tsx b/src/components/JoinSetting/index.tsx index 1ceb7fb..5dfe134 100644 --- a/src/components/JoinSetting/index.tsx +++ b/src/components/JoinSetting/index.tsx @@ -33,10 +33,6 @@ const JoinSetting = forwardRef((_props: any, ref: any) => { })) const navigate = useNavigate(); const [user, setUser] = useState({}); - const [deviceList, setDeviceList] = useState({ - audioList: [], - videoList: [], - }); const [joinRoomSettingModal, setJoinRoomSettingModal] = useState(false) const [joinRoomSettingForm, setJoinRoomSettingForm] = useState({ list: [ @@ -59,10 +55,6 @@ const JoinSetting = forwardRef((_props: any, ref: any) => { time = setInterval(async () => { const list = [...joinRoomSettingForm.list] await agora.getAudioMediaList().then(res => { - setDeviceList({ - ...deviceList, - audioList: res.ecordingList - }) if (!res.ecordingList.length) { list[0].active = false setJoinRoomSettingForm({ @@ -72,10 +64,6 @@ const JoinSetting = forwardRef((_props: any, ref: any) => { } }) await agora.getVideoDeviceManager().then(res => { - setDeviceList({ - ...deviceList, - videoList: res.list - }) if (!res.list.length) { list[1].active = false setJoinRoomSettingForm({ @@ -148,35 +136,36 @@ const JoinSetting = forwardRef((_props: any, ref: any) => {
{ joinRoomSettingForm.list.map((item, index) => { - return
{ + return
{ let msg = ''; - setDeviceList((res: any) => { - if (index === 0) { - if (!res.audioList.length) { + if (index === 0) { + await agora.getAudioMediaList().then(res => { + if (!res.ecordingList.length) { msg = '未检测到麦克风!' } - } else { - if (!res.videoList.length) { - msg = '未检测到麦克风!' - } - } - if (msg) { - message.error('未检测到麦克风!') - return - } - const list = [...joinRoomSettingForm.list] - list[index].active = !list[index].active - setJoinRoomSettingForm({ - ...joinRoomSettingForm, - list }) - if (index === 1) { - if (list[index].active) { - agora.startPreview('videoPreview', Number(user.account)) + } else { + await agora.getVideoDeviceManager().then(res => { + if (!res.list.length) { + msg = '未检测到摄像头!' } - } - return res + }) + } + if (msg) { + message.error('未检测到麦克风!') + return + } + const list = [...joinRoomSettingForm.list] + list[index].active = !list[index].active + setJoinRoomSettingForm({ + ...joinRoomSettingForm, + list }) + if (index === 1) { + if (list[index].active) { + agora.startPreview('videoPreview', Number(user.account)) + } + } }}>