From 8e0bfa8ce851e114658bc0b48eb492f72327878c Mon Sep 17 00:00:00 2001 From: yj <1336058017@qq.com> Date: Wed, 14 Aug 2024 16:19:11 +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/JoinMeetingModal/index.tsx | 2 - src/components/JoinSetting/index.tsx | 1 + src/components/StupWizard/index.tsx | 202 ++++++++++------------ src/utils/package/agora.ts | 69 ++++++-- 4 files changed, 152 insertions(+), 122 deletions(-) diff --git a/src/components/JoinMeetingModal/index.tsx b/src/components/JoinMeetingModal/index.tsx index d8edaae..0c7fb21 100644 --- a/src/components/JoinMeetingModal/index.tsx +++ b/src/components/JoinMeetingModal/index.tsx @@ -1,9 +1,7 @@ -import { GetCheckoutRoomNum, GetRoomInfo, GetRoomRtcToken } from '@/api/Home/Index'; import styles from '@/components/JoinMeetingModal/index.module.scss' import ImageUrl from '@/utils/package/ImageUrl'; import { Modal, message } from 'antd'; import { useState, useImperativeHandle, forwardRef, useRef } from "react"; -import { useNavigate } from 'react-router-dom'; import Avatar from '@/components/Avatar'; import JoinSetting from '../JoinSetting'; const JoinMeetingModal = forwardRef((props: any, ref: any) => { diff --git a/src/components/JoinSetting/index.tsx b/src/components/JoinSetting/index.tsx index c9bb388..e212ec3 100644 --- a/src/components/JoinSetting/index.tsx +++ b/src/components/JoinSetting/index.tsx @@ -21,6 +21,7 @@ const JoinSetting = forwardRef((_props: any, ref: any) => { }) if (location.hash.indexOf('/meeting') === -1) { agora.init() + agora.setDeviceManager() } getDeviceList() } diff --git a/src/components/StupWizard/index.tsx b/src/components/StupWizard/index.tsx index c30e120..442006b 100644 --- a/src/components/StupWizard/index.tsx +++ b/src/components/StupWizard/index.tsx @@ -1,20 +1,28 @@ import styles from '@/components/StupWizard/index.module.scss' import ImageUrl from '@/utils/package/ImageUrl'; -import {Button, Checkbox, Empty, Input, message, Modal, Popover, Radio, Select, Slider} from 'antd'; -import {forwardRef, useEffect, useImperativeHandle, useState} from "react"; +import { Button, Checkbox, Empty, Input, message, Modal, Popover, Radio, Select, Slider } from 'antd'; +import { forwardRef, useEffect, useImperativeHandle, useState } from "react"; import agora from '@/utils/package/agora' -import {CloseOutlined, LoadingOutlined, QuestionCircleOutlined} from '@ant-design/icons'; -import {storage} from '@/utils'; +import { CloseOutlined, LoadingOutlined, QuestionCircleOutlined } from '@ant-design/icons'; +import { storage } from '@/utils'; import path from 'path'; const fs = require('fs').promises; -const {exec} = require('child_process'); +const { exec } = require('child_process'); const StupWizard = forwardRef((props: any, ref: any) => { useImperativeHandle(ref, () => ({ changeModal: () => { if (location.hash.indexOf('/meeting') === -1) { agora.init() + agora.setDeviceManager() } + setList((res: any) => { + res.forEach((item: any) => { + item.active = false + }); + res[0].active = true; + return res + }) setIsStupWizard(true) } })) @@ -74,7 +82,7 @@ const StupWizard = forwardRef((props: any, ref: any) => { agora.stopPlaybackDeviceTest() agora.stopRecordingDeviceTest() }}> - + {row.title} ) @@ -88,18 +96,18 @@ const StupWizard = forwardRef((props: any, ref: any) => { top: '16px', cursor: 'pointer' }} - onClick={() => { - if (location.hash.indexOf('/meeting') === -1) { - agora.release() - } - setIsStupWizard(false) - }} + onClick={() => { + if (location.hash.indexOf('/meeting') === -1) { + agora.release() + } + setIsStupWizard(false) + }} /> - {list[0].active ? : null} - {list[1].active ? : null} - {list[2].active ? : null} - {list[3].active ? : null} - {list[4].active ? : null} + {list[0].active ? : null} + {list[1].active ? : null} + {list[2].active ? : null} + {list[3].active ? : null} + {list[4].active ? : null} @@ -124,7 +132,7 @@ const CurrencyComponents = () => { setting.closeSetting = e.target.value; storage.setItem('setting', JSON.stringify(setting)) setOperationValue(e.target.value) - }} style={{flexShrink: 0, margin: '10px 0'}} value={optionsValue}> + }} style={{ flexShrink: 0, margin: '10px 0' }} value={optionsValue}> 退出主程序 不退出程序,最小化到托盘 @@ -147,14 +155,7 @@ const VideoComponents = () => { const getVideoDeviceList = async (): Promise => { const userInfo = JSON.parse(storage.getItem('user') as string) agora.getVideoDeviceManager().then(async (res) => { - const {item, list} = res - if ((!setting.videoDeviceId && item) || (!(list.find((item: any) => item.deviceId === setting.videoDeviceId)) && item)) { - setting.videoDeviceId = item - } - if (!list.length) { - setting.videoDeviceId = '' - } - storage.setItem('setting', JSON.stringify(setting)) + const { item, list } = res setVideoDeviceManager({ list: list.map((row: any) => { return { @@ -185,12 +186,12 @@ const VideoComponents = () => { right: '50%', fontSize: '30px', top: '50%', - }}/> + }} /> :
-
- +
+
} @@ -202,8 +203,8 @@ const VideoComponents = () => { style={{ color: 'white' }}> - 解释说明:如未检测到摄像头请插拔后重试 - + 解释说明:如未检测到摄像头请插拔后重试 + } title="" > @@ -211,20 +212,20 @@ const VideoComponents = () => { color: 'white', cursor: 'pointer', marginRight: '10px' - }}/> + }} /> { - setting.ecordingDeviceId = e; - storage.setItem('setting', JSON.stringify(setting)) - setAudioDeviceManager({ - ...audioDeviceManager, - ecordingItem: e - }) - agora.setRecordingDevice(e) - }}/>; + setting.ecordingDeviceId = e; + storage.setItem('setting', JSON.stringify(setting)) + setAudioDeviceManager({ + ...audioDeviceManager, + ecordingItem: e + }) + agora.setRecordingDevice(e) + }} />; {audioDeviceManager.ecordingActive ?
{ agora.stopRecordingDeviceTest() setAudioDeviceManager({ @@ -342,26 +328,26 @@ const AudioComponents = () => { }}>测试
}
{audioDeviceManager.ecordingActive ?
- +
- +
- +
: null}
输入音量: - { - setting.ecordingVolume = e; - storage.setItem('setting', JSON.stringify(setting)) - await agora.setRecordingDeviceVolume(e) - setAudioDeviceManager({ - ...audioDeviceManager, - ecordingVolume: e, - }) - }} disabled={!audioDeviceManager.ecordingItem}/> + { + setting.ecordingVolume = e; + storage.setItem('setting', JSON.stringify(setting)) + await agora.setRecordingDeviceVolume(e) + setAudioDeviceManager({ + ...audioDeviceManager, + ecordingVolume: e, + }) + }} disabled={!audioDeviceManager.ecordingItem} />
{ @@ -379,16 +365,16 @@ const AudioComponents = () => { 扬声器: { setting.recordingFilesPath = e.target.value; @@ -481,7 +467,7 @@ const RecordingComponents = () => { window.electron.selectFilePath({ key: 'recordingFilesPath', }) - }} style={{backgroundColor: '#31353A', marginRight: '10px'}}>选择保存目录 + }} style={{ backgroundColor: '#31353A', marginRight: '10px' }}>选择保存目录 + }} style={{ backgroundColor: '#31353A' }}>打开
@@ -541,7 +527,7 @@ const FileComponents = () => { { setting.shareFilesPath = e.target.value; @@ -553,7 +539,7 @@ const FileComponents = () => { window.electron.selectFilePath({ key: 'shareFilesPath', }) - }} style={{backgroundColor: '#31353A', marginRight: '10px'}}>选择保存目录 + }} style={{ backgroundColor: '#31353A', marginRight: '10px' }}>选择保存目录 + }} style={{ backgroundColor: '#31353A' }}>打开
{ diff --git a/src/utils/package/agora.ts b/src/utils/package/agora.ts index 801dd11..00118a9 100644 --- a/src/utils/package/agora.ts +++ b/src/utils/package/agora.ts @@ -26,24 +26,69 @@ const agora = { }); if (bool) { const setting = JSON.parse(storage.getItem('setting') as string) - if (setting.videoDeviceId) { - agora.getVideoDeviceManager().then(async (res) => { - let item = res.list.find((item: any) => item.deviceId === setting.videoDeviceId); - if (item) { - agora.setVideoDeviceManager(setting.videoDeviceId) //通过设备 ID 指定视频采集设备。 - } else { - agora.setVideoDeviceManager(rtcEngine.getVideoDeviceManager().getDevice()) - } - }) - } else { - agora.setVideoDeviceManager(rtcEngine.getVideoDeviceManager().getDevice()) - } + 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 () => { + const setting = JSON.parse(storage.getItem('setting') as string) + // 摄像头 + if (setting.videoDeviceId) { + agora.getVideoDeviceManager().then(async (res) => { + let item = res.list.find((item: any) => item.deviceId === setting.videoDeviceId); + if (item) { + agora.setVideoDeviceManager(setting.videoDeviceId) + } else { + agora.setVideoDeviceManager(rtcEngine.getVideoDeviceManager().getDevice()) + setting.videoDeviceId = rtcEngine.getVideoDeviceManager().getDevice() + } + }) + } else { + agora.setVideoDeviceManager(rtcEngine.getVideoDeviceManager().getDevice()) + setting.videoDeviceId = rtcEngine.getVideoDeviceManager().getDevice() + } + + // 播放设备 + if (setting.playBackDeviceId) { + agora.getAudioMediaList().then(async (res) => { + let item = res.playBackList.find((item: any) => item.deviceId === setting.playBackDeviceId); + if (item) { + agora.setPlaybackDevice(setting.playBackDeviceId) + } else { + agora.setPlaybackDevice(res.playBackItem.deviceId) + setting.playBackDeviceId = res.playBackItem.deviceId + } + }) + } else { + let deviceId = rtcEngine.getAudioDeviceManager().getPlaybackDefaultDevice().deviceId; + agora.setPlaybackDevice(deviceId) + setting.playBackDeviceId = deviceId + } + + // 音频设备 + if (setting.ecordingDeviceId) { + agora.getAudioMediaList().then(async (res) => { + let item = res.ecordingList.find((item: any) => item.deviceId === setting.ecordingDeviceId); + if (item) { + agora.setRecordingDevice(setting.ecordingDeviceId) + } else { + agora.setRecordingDevice(res.ecordingItem.deviceId) + setting.ecordingDeviceId = res.ecordingItem.deviceId + } + }) + } else { + let deviceId = rtcEngine.getAudioDeviceManager().getRecordingDefaultDevice().deviceId; + agora.setRecordingDevice(deviceId) + setting.ecordingDeviceId = deviceId + } + setTimeout(() => { + storage.setItem('setting', JSON.stringify(setting)) + }, 1000); + }, // 事件回调 registerEventHandler: ({ onJoinChannelSuccess, onUserJoined, onUserOffline, onAudioVolumeIndication }: any) => { rtcEngine.registerEventHandler({