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) { if (location.hash.indexOf('/meeting') === -1) {
agora.init() agora.init()
agora.setDeviceManager()
} }
getDeviceList() getDeviceList()
} }

View File

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

View File

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