From c15fcb9d1962617a2dede385b729c39ebd910fa8 Mon Sep 17 00:00:00 2001 From: yj <1336058017@qq.com> Date: Mon, 28 Oct 2024 15:19:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/StupWizard/index.tsx | 10 +------ src/page/Meeting/index.tsx | 45 +++++++++++++++-------------- src/utils/package/agora.ts | 18 +++++++++--- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/src/components/StupWizard/index.tsx b/src/components/StupWizard/index.tsx index a11ae66..9e09414 100644 --- a/src/components/StupWizard/index.tsx +++ b/src/components/StupWizard/index.tsx @@ -11,14 +11,9 @@ const fs = require('fs').promises; const { exec } = require('child_process'); const StupWizard = forwardRef((_props: any, ref: any) => { useImperativeHandle(ref, () => ({ - changeModal: (index: number = 0, data: any) => { + changeModal: (index: number = 0) => { if (location.hash.indexOf('/meeting') === -1) { agora.init() - } else { - agora.muteLocalAudioStream(true) - } - if (data) { - setIsMuteLocalAudioStream(data.active) } setList((res: any) => { res.forEach((item: any) => { @@ -63,7 +58,6 @@ const StupWizard = forwardRef((_props: any, ref: any) => { } ]) const [isStupWizard, setIsStupWizard] = useState(false); - const [isMuteLocalAudioStream, setIsMuteLocalAudioStream] = useState(true); return ( <> { onClick={async () => { if (location.hash.indexOf('/meeting') === -1) { agora.release() - } else { - agora.muteLocalAudioStream(!isMuteLocalAudioStream) } setIsStupWizard(false) }} diff --git a/src/page/Meeting/index.tsx b/src/page/Meeting/index.tsx index e5990ae..9b97a7b 100644 --- a/src/page/Meeting/index.tsx +++ b/src/page/Meeting/index.tsx @@ -928,8 +928,7 @@ const Meeting: React.FC = () => { // 声网初始化 const agoraInit = async () => { await agora.init(true) - await agora.muteLocalAudioStream(state.enableMicr) - await agora.muteLocalVideoStream(state.enableCamera) + await agora.muteLocalVideoStream(userInfo, state.enableMicr, state.enableCamera) await getJoin(state.enableMicr, state.enableCamera) agora.registerEventHandler({ onJoinChannelSuccess: async (connection: RtcConnection, _elapsed: number) => { @@ -1071,26 +1070,30 @@ const Meeting: React.FC = () => { if (item.uid === userInfo.uid) { const footerListTemplate = [...footerList] await agora.getVideoDeviceManager().then(async (res) => { - if (res.list.length) { - footerListTemplate[0][1].title = item.enableCamera ? '关闭视频' : '开启视频' - footerListTemplate[0][1].active = !item.enableCamera - await agora.muteLocalVideoStream(item.enableCamera) - } else { - footerListTemplate[0][1].title = '开启视频' - footerListTemplate[0][1].active = true - await agora.muteLocalVideoStream(false) - } + getUserRoomInfo().then(async (r) => { + if (res.list.length) { + footerListTemplate[0][1].title = item.enableCamera ? '关闭视频' : '开启视频' + footerListTemplate[0][1].active = !item.enableCamera + await agora.muteLocalVideoStream(r, item.enableMicr, item.enableCamera) + } else { + footerListTemplate[0][1].title = '开启视频' + footerListTemplate[0][1].active = true + await agora.muteLocalVideoStream(r, item.enableMicr, false) + } + }) }) await agora.getAudioMediaList().then(async (res) => { - if (res.ecordingList.length) { - footerListTemplate[0][0].title = item.enableMicr ? '静音' : '解除静音' - footerListTemplate[0][0].active = !item.enableMicr - await agora.muteLocalAudioStream(item.enableMicr) - } else { - footerListTemplate[0][0].title = '解除静音' - footerListTemplate[0][0].active = true - await agora.muteLocalAudioStream(false) - } + getUserRoomInfo().then(async (r) => { + if (res.ecordingList.length) { + footerListTemplate[0][0].title = item.enableMicr ? '静音' : '解除静音' + footerListTemplate[0][0].active = !item.enableMicr + await agora.muteLocalAudioStream(r, item.enableMicr, item.enableCamera) + } else { + footerListTemplate[0][0].title = '解除静音' + footerListTemplate[0][0].active = true + await agora.muteLocalAudioStream(r, false, item.enableCamera) + } + }) }) if (!role.ID.includes(userInfo.roleId)) { if (item.isRoomManager) { @@ -1423,7 +1426,7 @@ const Meeting: React.FC = () => { }) break; case '设置': - stupWizardRef.current.changeModal(0, footerList[0][0]) + stupWizardRef.current.changeModal() break; case '邀请人员': await getUserRoomInfo().then(async (res) => { diff --git a/src/utils/package/agora.ts b/src/utils/package/agora.ts index 072badc..800b809 100644 --- a/src/utils/package/agora.ts +++ b/src/utils/package/agora.ts @@ -380,17 +380,27 @@ export const agora = { rtcEngine.enableLoopbackRecording(false) }, // 取消或恢复发布本地音频流 - muteLocalAudioStream: async (publishMicrophoneTrack: boolean) => { + muteLocalAudioStream: async (data: any, publishMicrophoneTrack: boolean, publishCameraTrack: boolean) => { // await rtcEngine.muteLocalAudioStream(mute) await rtcEngine.updateChannelMediaOptions({ - publishMicrophoneTrack,//设置是否发布麦克风采集到的音频 + clientRoleType: data ? ClientRoleType.ClientRoleBroadcaster : ClientRoleType.ClientRoleAudience, //用户角色 ClientRoleBroadcaster 主播 ClientRoleAudience 观众 + autoSubscribeAudio: true,//设置是否自动订阅所有音频流 + autoSubscribeVideo: true,//设置是否自动订阅所有视频流 + publishMicrophoneTrack: publishMicrophoneTrack,//设置是否发布麦克风采集到的音频 + publishCameraTrack: publishCameraTrack,//设置是否发布摄像头采集的视频 + publishScreenTrack: false,//设置是否发布屏幕采集的视频 }) }, // 取消或恢复发布本地视频流 - muteLocalVideoStream: async (publishCameraTrack: boolean) => { + muteLocalVideoStream: async (data: any, publishMicrophoneTrack: boolean, publishCameraTrack: boolean) => { // await rtcEngine.muteLocalVideoStream(mute) await rtcEngine.updateChannelMediaOptions({ - publishCameraTrack,//设置是否发布摄像头采集的视频 + clientRoleType: data ? ClientRoleType.ClientRoleBroadcaster : ClientRoleType.ClientRoleAudience, //用户角色 ClientRoleBroadcaster 主播 ClientRoleAudience 观众 + autoSubscribeAudio: true,//设置是否自动订阅所有音频流 + autoSubscribeVideo: true,//设置是否自动订阅所有视频流 + publishMicrophoneTrack: publishMicrophoneTrack,//设置是否发布麦克风采集到的音频 + publishCameraTrack: publishCameraTrack,//设置是否发布摄像头采集的视频 + publishScreenTrack: false,//设置是否发布屏幕采集的视频 }) }, // 摄像头采集