From 73636352172097cddf390ca55a08723cba8b1dce Mon Sep 17 00:00:00 2001 From: yj <1336058017@qq.com> Date: Mon, 17 Feb 2025 10:35:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E8=A8=80=E4=BA=BA5=E5=88=86=E9=92=9F?= =?UTF-8?q?=E6=9C=AA=E6=8E=A8=E9=9F=B3=E8=A7=86=E9=A2=91=E6=B5=81=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E4=B8=8B=E9=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/page/Meeting/index.tsx | 62 ++++++++++++++++++++++++++++++++++++-- src/utils/package/agora.ts | 21 ++++++------- vite.config.ts | 6 ++-- 3 files changed, 73 insertions(+), 16 deletions(-) diff --git a/src/page/Meeting/index.tsx b/src/page/Meeting/index.tsx index a3a022d..08e05d7 100644 --- a/src/page/Meeting/index.tsx +++ b/src/page/Meeting/index.tsx @@ -13,7 +13,7 @@ import ImageUrl from '@/utils/package/imageUrl' import { agora } from '@/utils/package/agora' import dayjs from 'dayjs'; import durationPlugin from 'dayjs/plugin/duration'; -import { AudioVolumeInfo, ConnectionChangedReasonType, ConnectionStateType, LocalVideoStreamReason, LocalVideoStreamState, RenderModeType, RtcConnection, RtcStats, UserOfflineReasonType, VideoSourceType, VideoStreamType } from 'agora-electron-sdk'; +import { AudioVolumeInfo, ConnectionChangedReasonType, ConnectionStateType, LocalVideoStreamReason, LocalVideoStreamState, RenderModeType, RtcConnection, RtcStats, StreamPublishState, UserOfflineReasonType, VideoSourceType, VideoStreamType } from 'agora-electron-sdk'; import Avatar from '@/components/Avatar'; import SharedFilesModel from '@/components/SharedFilesModel'; import StupWizard from '@/components/StupWizard'; @@ -158,6 +158,8 @@ const Meeting: React.FC = () => { itemIndex: 0, rowIndex: 0, }); + const [audioStatus, setAudioStatus] = useState(1); + const [videoStatus, setVideoStatus] = useState(1); const [roomUserList, setRoomUserList] = useState([]) const [_speackUid, setSpeackUid] = useState([]) const [currentSpeakUser, setCurrentSpeakUser] = useState([]) @@ -1182,6 +1184,56 @@ const Meeting: React.FC = () => { return () => clearTimeout(timer); }, [isClickedMediaSteam]); + useEffect(() => { + let timer: NodeJS.Timeout | string = ''; + if (audioStatus === 1 && videoStatus === 1) { + if (timer) { + clearTimeout(timer) + timer = '' + } + timer = setTimeout(() => { + setRoomUserList((res: any) => { + let userItem = res.find((item: any) => item.uid === userInfo.uid) + if (!role.ID.includes(userInfo.roleId) && userItem && userItem.isRoomManager) { + DeleteRoomManager({ + roomId: state.roomId, + roomNum: state.channelId, + userId: userInfo.uid + }) + confirm({ + title: '提示', + icon: , + content: `由于您长时间未发言,已自动取消发言权限,是否重新申请发言?`, + centered: true, + okText: '确定', + cancelText: '取消', + async onOk() { + GetApplySpeak(state.channelId).then(res => { + if (res.code === 200) { + setIsClicked(true); + message.success('申请发言成功') + } + }) + }, + onCancel() { + + } + }) + } + clearTimeout(timer) + timer = '' + return res + }) + }, 1000 * 60 * 5); + } else { + if (timer) { + clearTimeout(timer) + timer = '' + } + } + return () => timer ? clearTimeout(timer) : ''; + }, [audioStatus, videoStatus]); + useEffect(() => { let timer: NodeJS.Timeout | undefined; if (timer) { @@ -1411,7 +1463,13 @@ const Meeting: React.FC = () => { }) } }) - } + }, + onVideoPublishStateChanged: (_source: VideoSourceType, _channel: string, _oldState: StreamPublishState, newState: StreamPublishState, _elapseSinceLastState: number) => { + setVideoStatus(newState) + }, + onAudioPublishStateChanged: (_channel: string, _oldState: StreamPublishState, newState: StreamPublishState, _elapseSinceLastState: number) => { + setAudioStatus(newState) + }, }) if (state.enableCamera) { await agora.startCameraCapture() diff --git a/src/utils/package/agora.ts b/src/utils/package/agora.ts index 6494db7..1b5063a 100644 --- a/src/utils/package/agora.ts +++ b/src/utils/package/agora.ts @@ -21,7 +21,8 @@ import { ColorEnhanceOptions, LowlightEnhanceOptions, VirtualBackgroundSource, - AudienceLatencyLevelType + AudienceLatencyLevelType, + StreamPublishState } from "agora-electron-sdk"; import { GetRoomRtcToken, GetAgoraConf } from "@/api/Home/Index"; import { storage } from '@/utils'; @@ -151,7 +152,7 @@ export const agora = { }, 1000); }, // 事件回调 - registerEventHandler: ({ onJoinChannelSuccess, onUserJoined, onUserOffline, onAudioVolumeIndication, onRtcStats, onConnectionStateChanged, onLocalVideoStateChanged, onConnectionLost, onTokenPrivilegeWillExpire }: any) => { + registerEventHandler: ({ onJoinChannelSuccess, onUserJoined, onUserOffline, onAudioVolumeIndication, onRtcStats, onConnectionStateChanged, onLocalVideoStateChanged, onConnectionLost, onTokenPrivilegeWillExpire, onVideoPublishStateChanged, onAudioPublishStateChanged }: any) => { rtcEngine.registerEventHandler({ // 监听本地用户加入频道事件 onJoinChannelSuccess: async (connection: RtcConnection, elapsed: number) => { @@ -166,17 +167,13 @@ export const agora = { await onUserOffline?.(connection, remoteUid, reason) }, // // 视频发布状态改变回调 - // onVideoPublishStateChanged: (source: any, channel: any, oldState: any, newState: any, elapseSinceLastState: any) => { - // if (newState === 1) { - - // } - // }, + onVideoPublishStateChanged: (source: VideoSourceType, channel: string, oldState: StreamPublishState, newState: StreamPublishState, elapseSinceLastState: number) => { + onVideoPublishStateChanged?.(source, channel, oldState, newState, elapseSinceLastState) + }, // // 音频发布状态改变回调 - // onAudioPublishStateChanged: (channel: any, oldState: any, newState: any, elapseSinceLastState: any) => { - // if (newState === 1) { - - // } - // }, + onAudioPublishStateChanged: (channel: string, oldState: StreamPublishState, newState: StreamPublishState, elapseSinceLastState: number) => { + onAudioPublishStateChanged?.(channel, oldState, newState, elapseSinceLastState) + }, // // 用户音量提示回调。 onAudioVolumeIndication: async (_connection: RtcConnection, speakers: AudioVolumeInfo[], _speakerNumber: number, _totalVolume: number) => { await onAudioVolumeIndication?.(speakers) diff --git a/vite.config.ts b/vite.config.ts index b086ef7..7606db2 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -76,7 +76,8 @@ export default defineConfig({ ColorEnhanceOptions, LowlightEnhanceOptions, VirtualBackgroundSource, - AudienceLatencyLevelType + AudienceLatencyLevelType, + StreamPublishState } = require("agora-electron-sdk") export { createAgoraRtcEngine, @@ -101,7 +102,8 @@ export default defineConfig({ ColorEnhanceOptions, LowlightEnhanceOptions, VirtualBackgroundSource, - AudienceLatencyLevelType + AudienceLatencyLevelType, + StreamPublishState } `, })