This commit is contained in:
yj 2024-08-07 11:45:40 +08:00
parent 9015bba961
commit 690dfe2e13
3 changed files with 39 additions and 57 deletions

View File

@ -138,7 +138,7 @@ const Meeting: React.FC = () => {
}) })
view.setAttribute('load', 'true') view.setAttribute('load', 'true')
} }
if (String(info.localUid).length === 9) { if (String(info.localUid).length === 9 && userInfo.screenShareId == info.localUid) {
await agora.setupLocalVideo({ await agora.setupLocalVideo({
uid: Number(info.localUid), uid: Number(info.localUid),
view: document.getElementById(`look-video`) as HTMLElement, view: document.getElementById(`look-video`) as HTMLElement,
@ -161,8 +161,7 @@ const Meeting: React.FC = () => {
}) })
view.setAttribute('load', 'true') view.setAttribute('load', 'true')
} }
if (String(remoteUid).length === 9) { if (String(remoteUid).length === 9 && userInfo.screenShareId != remoteUid) {
console.log(String(remoteUid));
await agora.setupRemoteVideoJoin({ await agora.setupRemoteVideoJoin({
uid: Number(remoteUid), uid: Number(remoteUid),
view: document.getElementById(`look-video`) as HTMLElement, view: document.getElementById(`look-video`) as HTMLElement,
@ -174,7 +173,7 @@ const Meeting: React.FC = () => {
onUserOffline: async (info: any, remoteUid: any, _reason: any) => { onUserOffline: async (info: any, remoteUid: any, _reason: any) => {
await agora.setupRemoteVideo({ await agora.setupRemoteVideo({
uid: Number(remoteUid), uid: Number(remoteUid),
view: document.getElementById(`video-${remoteUid}`) as HTMLElement, view: null,
channelId: info.channelId, channelId: info.channelId,
}) })
setTimeout(() => { setTimeout(() => {
@ -182,7 +181,7 @@ const Meeting: React.FC = () => {
}, 1000); }, 1000);
} }
}) })
agora.setCameraCapture() agora.startCameraCapture()
agora.setJoinChannel({ agora.setJoinChannel({
channelId: state.channelId, channelId: state.channelId,
uid: userInfo.uid, uid: userInfo.uid,
@ -276,27 +275,6 @@ const Meeting: React.FC = () => {
}, [currentVideoId]) }, [currentVideoId])
useEffect(() => {
const userItem = allUserList.find((item: any) => item.uid === currentLookUserAccount)
if (userItem) {
if (userItem.uid === user.uid) {
// agora.setupLocalVideo({
// account: Number(userItem.uid),
// view: document.getElementById(`look-video`) as HTMLElement,
// channelId: state.channelId,
// sourceType: VideoSourceType.VideoSourceCameraPrimary,
// })
} else {
// agora.setupRemoteVideoJoin({
// account: Number(userItem.uid),
// view: document.getElementById(`look-video`) as HTMLElement,
// channelId: state.channelId,
// sourceType: VideoSourceType.VideoSourceCameraPrimary,
// })
}
}
}, [allUserList, currentLookUserAccount])
// 网络 // 网络
const handleNetworkChange = (): void => { const handleNetworkChange = (): void => {
if (navigator.onLine) { if (navigator.onLine) {
@ -360,7 +338,8 @@ const Meeting: React.FC = () => {
setIsSharedScreenModal(true) setIsSharedScreenModal(true)
break; break;
case '停止共享': case '停止共享':
agora.setCameraCapture() await agora.destroyRendererByConfig(user.screenShareId)
agora.stopScreenCapture()
footerListTemplate[itemIndex][rowIndex].title = '共享屏幕' footerListTemplate[itemIndex][rowIndex].title = '共享屏幕'
break; break;
case '关闭声音': case '关闭声音':
@ -379,13 +358,15 @@ const Meeting: React.FC = () => {
footerListTemplate[itemIndex][rowIndex].title = '开启视频' footerListTemplate[itemIndex][rowIndex].title = '开启视频'
footerListTemplate[itemIndex][rowIndex].active = true footerListTemplate[itemIndex][rowIndex].active = true
setFooterList(footerListTemplate) setFooterList(footerListTemplate)
postOpenCamera(false, user.uid) await postOpenCamera(false, user.uid)
await agora.stopCameraCapture();
break; break;
case '开启视频': case '开启视频':
footerListTemplate[itemIndex][rowIndex].title = '关闭视频' footerListTemplate[itemIndex][rowIndex].title = '关闭视频'
footerListTemplate[itemIndex][rowIndex].active = false footerListTemplate[itemIndex][rowIndex].active = false
setFooterList(footerListTemplate) setFooterList(footerListTemplate)
postOpenCamera(true, user.uid) await postOpenCamera(true, user.uid)
await agora.startCameraCapture()
break; break;
case '设置向导': case '设置向导':
// stupWizardRef.current.changeModal() // stupWizardRef.current.changeModal()

View File

@ -56,9 +56,6 @@ const agora = {
onUserOffline: async (info: any, remoteUid: any, reason: any) => { onUserOffline: async (info: any, remoteUid: any, reason: any) => {
await onUserOffline(info, remoteUid, reason) await onUserOffline(info, remoteUid, reason)
}, },
// onConnectionStateChanged: (connection: any, state: any, reason: any) => {
// console.log(connection, reason)
// },
// // 视频发布状态改变回调 // // 视频发布状态改变回调
// onVideoPublishStateChanged: (source: any, channel: any, oldState: any, newState: any, elapseSinceLastState: any) => { // onVideoPublishStateChanged: (source: any, channel: any, oldState: any, newState: any, elapseSinceLastState: any) => {
// if (newState === 1) { // if (newState === 1) {
@ -138,6 +135,22 @@ const agora = {
publishScreenTrack: false, publishScreenTrack: false,
}); });
}, },
// 共享屏幕单独用户
joinChannelEx: async (uid: any) => {
await rtcEngine.leaveChannelEx({ channelId: option.channelId, localUid: Number(uid) })
await rtcEngine.joinChannelEx(
option.token,
{ channelId: option.channelId, localUid: Number(uid) },
{
autoSubscribeAudio: false,
autoSubscribeVideo: false,
publishMicrophoneTrack: false,
publishCameraTrack: false,
clientRoleType: ClientRoleType.ClientRoleBroadcaster,
publishScreenTrack: true,
}
);
},
// 停止共享屏幕 // 停止共享屏幕
stopScreenCapture: () => { stopScreenCapture: () => {
rtcEngine.stopScreenCapture(); rtcEngine.stopScreenCapture();
@ -151,17 +164,12 @@ const agora = {
rtcEngine.muteLocalVideoStream(mute) rtcEngine.muteLocalVideoStream(mute)
}, },
// 摄像头采集 // 摄像头采集
setCameraCapture: () => { startCameraCapture: async () => {
agora.stopScreenCapture() await rtcEngine.startCameraCapture(VideoSourceType.VideoSourceCamera, {})
const user = JSON.parse(storage.getItem('user') as string) },
rtcEngine.destroyRendererByConfig(VideoSourceType.VideoSourceScreen, option.channelId, Number(user.screenShareId)) // 停止采集摄像头
agora.setupLocalVideo({ stopCameraCapture: async () => {
uid: Number(option.uid), await rtcEngine.stopCameraCapture()
view: document.getElementById(`video-${option.uid}`),
channelId: option.channelId,
sourceType: VideoSourceType.VideoSourceCameraPrimary,
})
rtcEngine.startCameraCapture(VideoSourceType.VideoSourceCamera, {})
}, },
// 加入频道 // 加入频道
setJoinChannel: async (data: any) => { setJoinChannel: async (data: any) => {
@ -178,7 +186,6 @@ const agora = {
setDesktopCapturerVideo: async (targetSource: any) => { setDesktopCapturerVideo: async (targetSource: any) => {
// await rtcEngine.stopCameraCapture(option.sourceType) // await rtcEngine.stopCameraCapture(option.sourceType)
const user = JSON.parse(storage.getItem('user') as string) const user = JSON.parse(storage.getItem('user') as string)
rtcEngine.destroyRendererByConfig(VideoSourceType.VideoSourceScreen, option.channelId, Number(user.screenShareId))
agora.stopScreenCapture(); agora.stopScreenCapture();
if ( if (
targetSource.type === targetSource.type ===
@ -204,18 +211,8 @@ const agora = {
} }
); );
} }
rtcEngine.joinChannelEx( await agora.destroyRendererByConfig(user.screenShareId)
option.token, await agora.joinChannelEx(user.screenShareId)
{ channelId: option.channelId, localUid: Number(user.screenShareId) },
{
autoSubscribeAudio: false,
autoSubscribeVideo: false,
publishMicrophoneTrack: false,
publishCameraTrack: false,
clientRoleType: ClientRoleType.ClientRoleBroadcaster,
publishScreenTrack: true,
}
);
}, },
// 停止录制音视频 // 停止录制音视频
stopRecording: () => { stopRecording: () => {
@ -223,6 +220,11 @@ const agora = {
rtcEngine.destroyMediaRecorder(iMediaRecorder) rtcEngine.destroyMediaRecorder(iMediaRecorder)
iMediaRecorder = "" iMediaRecorder = ""
}, },
// 销毁视频
destroyRendererByConfig: async (uid: any) => {
await rtcEngine.destroyRendererByConfig(VideoSourceType.VideoSourceScreen, option.channelId, Number(uid))
await rtcEngine.destroyRendererByConfig(VideoSourceType.VideoSourceRemote, option.channelId, Number(uid))
},
// 开始录制音视频 // 开始录制音视频
startRecording: (uid: number) => { startRecording: (uid: number) => {
iMediaRecorder = rtcEngine.createMediaRecorder({ iMediaRecorder = rtcEngine.createMediaRecorder({

View File

@ -24,7 +24,6 @@ export const onStart = async (callBack?: Function) => {
callBack() callBack()
} }
} catch (err) { } catch (err) {
console.log(err);
setTimeout(onStart, 5000); setTimeout(onStart, 5000);
} }
} }