发言人5分钟未推音视频流自动下麦

This commit is contained in:
yj 2025-02-17 10:35:25 +08:00
parent 4cf65d50a3
commit 7363635217
3 changed files with 73 additions and 16 deletions

View File

@ -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<StreamPublishState>(1);
const [videoStatus, setVideoStatus] = useState<StreamPublishState>(1);
const [roomUserList, setRoomUserList] = useState<any>([])
const [_speackUid, setSpeackUid] = useState<any>([])
const [currentSpeakUser, setCurrentSpeakUser] = useState<any>([])
@ -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: <ExclamationCircleFilled />,
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()

View File

@ -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)

View File

@ -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
}
`,
})