This commit is contained in:
yj 2024-08-14 16:37:14 +08:00
parent 938df73910
commit 7c5a2ffae9
3 changed files with 28 additions and 29 deletions

View File

@ -26,7 +26,6 @@ const JoinSetting = forwardRef((_props: any, ref: any) => {
})
if (location.hash.indexOf('/meeting') === -1) {
agora.init()
agora.setDeviceManager()
}
getDeviceList()
}

View File

@ -14,7 +14,6 @@ const StupWizard = forwardRef((props: any, ref: any) => {
changeModal: () => {
if (location.hash.indexOf('/meeting') === -1) {
agora.init()
agora.setDeviceManager()
}
setList((res: any) => {
res.forEach((item: any) => {

View File

@ -24,69 +24,70 @@ const agora = {
await rtcEngine.initialize({
appId: option.appId,
});
if (bool) {
const setting = JSON.parse(storage.getItem('setting') as string)
if (setting.videoDeviceId) agora.setVideoDeviceManager(setting.videoDeviceId) //指定摄像头头采集设备
if (setting.playBackDeviceId) agora.setPlaybackDevice(setting.playBackDeviceId) //指定播放设备
if (setting.playBackVolume) agora.setPlaybackDeviceVolume(setting.playBackVolume) // 设置播放设备音量
if (setting.ecordingDeviceId) agora.setRecordingDevice(setting.ecordingDeviceId) // 设置音频采集设备
if (setting.ecordingVolume) agora.setRecordingDeviceVolume(setting.ecordingVolume) // 设置音频设备音量
}
await agora.setDeviceManager(bool)
},
// 获取当前设备是否存在不存在就获取默认设备
setDeviceManager: async () => {
const setting = JSON.parse(storage.getItem('setting') as string)
setDeviceManager: async (bool: boolean = false) => {
const setting = await JSON.parse(storage.getItem('setting') as string)
// 摄像头
if (setting.videoDeviceId) {
agora.getVideoDeviceManager().then(async (res) => {
await agora.getVideoDeviceManager().then(async (res) => {
let item = res.list.find((item: any) => item.deviceId === setting.videoDeviceId);
if (item) {
agora.setVideoDeviceManager(setting.videoDeviceId)
await agora.setVideoDeviceManager(setting.videoDeviceId)
} else {
agora.setVideoDeviceManager(rtcEngine.getVideoDeviceManager().getDevice())
setting.videoDeviceId = rtcEngine.getVideoDeviceManager().getDevice()
await agora.setVideoDeviceManager(await rtcEngine.getVideoDeviceManager().getDevice())
setting.videoDeviceId = await rtcEngine.getVideoDeviceManager().getDevice()
}
})
} else {
agora.setVideoDeviceManager(rtcEngine.getVideoDeviceManager().getDevice())
setting.videoDeviceId = rtcEngine.getVideoDeviceManager().getDevice()
await agora.setVideoDeviceManager(await rtcEngine.getVideoDeviceManager().getDevice())
setting.videoDeviceId = await rtcEngine.getVideoDeviceManager().getDevice()
}
// 播放设备
if (setting.playBackDeviceId) {
agora.getAudioMediaList().then(async (res) => {
await agora.getAudioMediaList().then(async (res) => {
let item = res.playBackList.find((item: any) => item.deviceId === setting.playBackDeviceId);
if (item) {
agora.setPlaybackDevice(setting.playBackDeviceId)
await agora.setPlaybackDevice(setting.playBackDeviceId)
} else {
agora.setPlaybackDevice(res.playBackItem.deviceId)
await agora.setPlaybackDevice(res.playBackItem.deviceId)
setting.playBackDeviceId = res.playBackItem.deviceId
}
})
} else {
let deviceId = rtcEngine.getAudioDeviceManager().getPlaybackDefaultDevice().deviceId;
agora.setPlaybackDevice(deviceId)
let deviceId = await rtcEngine.getAudioDeviceManager().getPlaybackDefaultDevice().deviceId;
await agora.setPlaybackDevice(deviceId)
setting.playBackDeviceId = deviceId
}
// 音频设备
if (setting.ecordingDeviceId) {
agora.getAudioMediaList().then(async (res) => {
await agora.getAudioMediaList().then(async (res) => {
let item = res.ecordingList.find((item: any) => item.deviceId === setting.ecordingDeviceId);
if (item) {
agora.setRecordingDevice(setting.ecordingDeviceId)
await agora.setRecordingDevice(setting.ecordingDeviceId)
} else {
agora.setRecordingDevice(res.ecordingItem.deviceId)
await agora.setRecordingDevice(res.ecordingItem.deviceId)
setting.ecordingDeviceId = res.ecordingItem.deviceId
}
})
} else {
let deviceId = rtcEngine.getAudioDeviceManager().getRecordingDefaultDevice().deviceId;
agora.setRecordingDevice(deviceId)
let deviceId = await rtcEngine.getAudioDeviceManager().getRecordingDefaultDevice().deviceId;
await agora.setRecordingDevice(deviceId)
setting.ecordingDeviceId = deviceId
}
setTimeout(() => {
setTimeout(async () => {
storage.setItem('setting', JSON.stringify(setting))
if (bool) {
const setting = await JSON.parse(storage.getItem('setting') as string)
if (setting.videoDeviceId) agora.setVideoDeviceManager(setting.videoDeviceId) //指定摄像头头采集设备
if (setting.playBackDeviceId) agora.setPlaybackDevice(setting.playBackDeviceId) //指定播放设备
if (setting.playBackVolume) agora.setPlaybackDeviceVolume(setting.playBackVolume) // 设置播放设备音量
if (setting.ecordingDeviceId) agora.setRecordingDevice(setting.ecordingDeviceId) // 设置音频采集设备
if (setting.ecordingVolume) agora.setRecordingDeviceVolume(setting.ecordingVolume) // 设置音频设备音量
}
}, 1000);
},
// 事件回调