diff --git a/src/components/JoinSetting/index.tsx b/src/components/JoinSetting/index.tsx index 9f8455f..317e792 100644 --- a/src/components/JoinSetting/index.tsx +++ b/src/components/JoinSetting/index.tsx @@ -123,31 +123,35 @@ const JoinSetting = forwardRef((_props: any, ref: any) => { { joinRoomSettingForm.map((item, index) => { return
{ - let msg = ''; - if (index === 0) { - await agora.getAudioMediaList().then(res => { - if (!res.ecordingList.length) { - msg = '未检测到麦克风!' - } - }) - } else { - await agora.getVideoDeviceManager().then(res => { - if (!res.list.length) { - msg = '未检测到摄像头!' - } - }) - } - if (msg) { - message.error('未检测到麦克风!') - return - } - const list = [...joinRoomSettingForm] - list[index].active = !list[index].active - setJoinRoomSettingForm(list) - if (index === 1) { - if (list[index].active) { - agora.startPreview('videoPreview', Number(user.account)) + if (user.roleId === '1'){ + let msg = ''; + if (index === 0) { + await agora.getAudioMediaList().then(res => { + if (!res.ecordingList.length) { + msg = '未检测到麦克风!' + } + }) + } else { + await agora.getVideoDeviceManager().then(res => { + if (!res.list.length) { + msg = '未检测到摄像头!' + } + }) } + if (msg) { + message.error('未检测到麦克风!') + return + } + const list = [...joinRoomSettingForm] + list[index].active = !list[index].active + setJoinRoomSettingForm(list) + if (index === 1) { + if (list[index].active) { + agora.startPreview('videoPreview', Number(user.account)) + } + } + }else{ + message.error('您不是管理员,无法开启此功能!') } }}> diff --git a/src/page/Meeting/index.tsx b/src/page/Meeting/index.tsx index fd64671..a33e1d9 100644 --- a/src/page/Meeting/index.tsx +++ b/src/page/Meeting/index.tsx @@ -122,6 +122,7 @@ const Meeting: React.FC = () => { const [isShareUser, setIsShareUser] = useState(null) const [currentLookUserStatus, setCurrentLookUserStatus] = useState<0 | 1 | 2 | 3 | 4>(1) let userInfo = JSON.parse(storage.getItem('user') as string) + const msgTips = '您不是管理员,无法开启此功能!' useEffect(() => { let time = null as any; setUser(userInfo) @@ -188,6 +189,7 @@ const Meeting: React.FC = () => { channelId: state.channelId, uid: userInfo.uid, token: state.token, + roleId: userInfo.roleId, }) storage.setItem('noViewChatList', 0) window.addEventListener('customStorageChange', handleCustomStorageChange); @@ -227,18 +229,6 @@ const Meeting: React.FC = () => { const item = roomUserList.find((item: any) => item.screenShareId === String(isShare)) setIsShareUser(item || null) } - function moveObjectToFront(arr: any, objToMove: any) { - const index = arr.findIndex((item: any) => { - return item.uid === objToMove.uid; - }); - - if (index !== -1) { - const movedObj = arr.splice(index, 1)[0]; - arr.unshift(movedObj); - } - return arr; - } - setRoomUserList(moveObjectToFront(roomUserList, userInfo)) }, [isShare, roomUserList]); useEffect(() => { @@ -306,7 +296,7 @@ const Meeting: React.FC = () => { case 'OperCamera': setAllUserListData('OperCamera', item) break; - // 管理员用户信息刷新 + // 主讲人用户信息刷新 case 'ManagerRefresh': setAllUserListData('ManagerRefresh', item) break; @@ -351,6 +341,24 @@ const Meeting: React.FC = () => { }, [recorder]) const changeAgoraDevice = () => { + function moveAdminsAndSpeakersToFront(arr: any[]): any[] { + // 创建一个新的数组来存放管理员和主讲人 + const adminsAndSpeakers = [] as any; + // 创建一个新的数组来存放其他用户 + const otherUsers = [] as any; + // 遍历原始数组 + arr.forEach((item: any) => { + if (item.role === '1' || item.isRoomManager) { + // 如果是管理员或主讲人,添加到 adminsAndSpeakers 数组 + adminsAndSpeakers.push(item); + } else { + // 否则,添加到 otherUsers 数组 + otherUsers.push(item); + } + }); + // 将管理员和主讲人放在数组的最前面 + return [...adminsAndSpeakers, ...otherUsers]; + } setRoomUserList((res: any) => { res.forEach((item: any) => { if (item.uid === userInfo.uid) { @@ -373,7 +381,7 @@ const Meeting: React.FC = () => { item.isShow = true; } }); - return res + return moveAdminsAndSpeakersToFront(res) }) } // 替换数据 @@ -709,17 +717,43 @@ const Meeting: React.FC = () => { } // 开关麦克风 const postOpenMicr = async (enableMicr: boolean, uid: string, isAll?: boolean): Promise => { - if (isAll) { - await PostMuteAll({ - roomNum: state.channelId, - enableMicr - }) + if (user.roleId === '1') { + if (isAll) { + await PostMuteAll({ + roomNum: state.channelId, + enableMicr + }) + } else { + let msg = ''; + if (uid === user.uid) { + await agora.getAudioMediaList().then(res => { + if (!res.ecordingList.length) { + msg = '未检测到麦克风!' + } + }) + } + if (msg) { + message.error(msg) + return + } + await PostOpenMicr({ + roomNum: state.channelId, + uid, + enableMicr + }) + } } else { + message.error(msgTips) + } + } + // 开关视频 + const postOpenCamera = async (enableCamera: boolean, uid: string): Promise => { + if (user.roleId === '1') { let msg = ''; if (uid === user.uid) { - await agora.getAudioMediaList().then(res => { - if (!res.ecordingList.length) { - msg = '未检测到麦克风!' + await agora.getVideoDeviceManager().then(res => { + if (!res.list.length) { + msg = '未检测到摄像头!' } }) } @@ -727,37 +761,19 @@ const Meeting: React.FC = () => { message.error(msg) return } - await PostOpenMicr({ + if (enableCamera) { + await agora.startCameraCapture() + } else { + await agora.stopCameraCapture(); + } + await PostOpenCamera({ roomNum: state.channelId, uid, - enableMicr + enableCamera }) - } - } - // 开关视频 - const postOpenCamera = async (enableCamera: boolean, uid: string): Promise => { - let msg = ''; - if (uid === user.uid) { - await agora.getVideoDeviceManager().then(res => { - if (!res.list.length) { - msg = '未检测到摄像头!' - } - }) - } - if (msg) { - message.error(msg) - return - } - if (enableCamera) { - await agora.startCameraCapture() } else { - await agora.stopCameraCapture(); + message.error(msgTips) } - await PostOpenCamera({ - roomNum: state.channelId, - uid, - enableCamera - }) } // 演讲者模式 // const changeSpeakerMode = (): void => { @@ -910,9 +926,9 @@ const Meeting: React.FC = () => { {String(isShare) === item.screenShareId ?
屏幕分享中
: null} - - {user.roleId === '1' ? : ''} - {item.uid !== user.uid && user.roleId === '1' ? + {item.uid !== user.uid ? : null} - {item.uid !== user.uid && user.roleId === '1' ? : null} + >{item.isRoomManager ? '取消房间主讲人' : '设为房间主讲人'} : null}
- + : null}
{item.enableMicr ?
: null}
@@ -1120,7 +1136,7 @@ const Meeting: React.FC = () => { }) } }} - >{item.isRoomManager ? '取消房间管理员' : '设为房间管理员'} + >{item.isRoomManager ? '取消房间主讲人' : '设为房间主讲人'}