This commit is contained in:
yj 2024-08-14 16:32:51 +08:00
parent de5cda5b3c
commit 938df73910
1 changed files with 24 additions and 35 deletions

View File

@ -33,10 +33,6 @@ const JoinSetting = forwardRef((_props: any, ref: any) => {
})) }))
const navigate = useNavigate(); const navigate = useNavigate();
const [user, setUser] = useState<any>({}); const [user, setUser] = useState<any>({});
const [deviceList, setDeviceList] = useState<any>({
audioList: [],
videoList: [],
});
const [joinRoomSettingModal, setJoinRoomSettingModal] = useState(false) const [joinRoomSettingModal, setJoinRoomSettingModal] = useState(false)
const [joinRoomSettingForm, setJoinRoomSettingForm] = useState({ const [joinRoomSettingForm, setJoinRoomSettingForm] = useState({
list: [ list: [
@ -59,10 +55,6 @@ const JoinSetting = forwardRef((_props: any, ref: any) => {
time = setInterval(async () => { time = setInterval(async () => {
const list = [...joinRoomSettingForm.list] const list = [...joinRoomSettingForm.list]
await agora.getAudioMediaList().then(res => { await agora.getAudioMediaList().then(res => {
setDeviceList({
...deviceList,
audioList: res.ecordingList
})
if (!res.ecordingList.length) { if (!res.ecordingList.length) {
list[0].active = false list[0].active = false
setJoinRoomSettingForm({ setJoinRoomSettingForm({
@ -72,10 +64,6 @@ const JoinSetting = forwardRef((_props: any, ref: any) => {
} }
}) })
await agora.getVideoDeviceManager().then(res => { await agora.getVideoDeviceManager().then(res => {
setDeviceList({
...deviceList,
videoList: res.list
})
if (!res.list.length) { if (!res.list.length) {
list[1].active = false list[1].active = false
setJoinRoomSettingForm({ setJoinRoomSettingForm({
@ -148,35 +136,36 @@ const JoinSetting = forwardRef((_props: any, ref: any) => {
<div> <div>
{ {
joinRoomSettingForm.list.map((item, index) => { joinRoomSettingForm.list.map((item, index) => {
return <div key={index} onClick={() => { return <div key={index} onClick={async () => {
let msg = ''; let msg = '';
setDeviceList((res: any) => { if (index === 0) {
if (index === 0) { await agora.getAudioMediaList().then(res => {
if (!res.audioList.length) { if (!res.ecordingList.length) {
msg = '未检测到麦克风!' 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) { } else {
if (list[index].active) { await agora.getVideoDeviceManager().then(res => {
agora.startPreview('videoPreview', Number(user.account)) 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))
}
}
}}> }}>
<img src={item.active ? item.icon : item.iconActive} alt="" /> <img src={item.active ? item.icon : item.iconActive} alt="" />
</div> </div>