This commit is contained in:
yj 2024-08-07 10:21:45 +08:00
parent 2c8f281a0f
commit aa17766689
2 changed files with 44 additions and 22 deletions

View File

@ -127,24 +127,40 @@ const Meeting: React.FC = () => {
enableCamera: true
})
await getRoomUser()
setTimeout(() => {
agora.setupLocalVideo({
uid: Number(info.localUid),
view: document.getElementById(`video-${info.localUid}`) as HTMLElement,
channelId: info.channelId,
sourceType: VideoSourceType.VideoSourceCameraPrimary,
})
setTimeout(async () => {
let view = document.getElementById(`video-${info.localUid}`) as HTMLElement;
if (view && !view.getAttribute('load')) {
await agora.setupLocalVideo({
uid: Number(info.localUid),
view,
channelId: info.channelId,
sourceType: VideoSourceType.VideoSourceCameraPrimary,
})
view.setAttribute('load', 'true')
}
if (String(info.localUid).length === 9) {
await agora.setupLocalVideo({
uid: Number(info.localUid),
view: document.getElementById(`look-video`) as HTMLElement,
channelId: info.channelId,
sourceType: VideoSourceType.VideoSourceScreen,
})
}
getShowUser();
}, 1000);
},
onUserJoined: async (info: any, remoteUid: any, _elapsed: any) => {
await getRoomUser()
setTimeout(() => {
agora.setupRemoteVideoJoin({
uid: Number(remoteUid),
view: document.getElementById(`video-${remoteUid}`) as HTMLElement,
channelId: info.channelId,
})
setTimeout(async () => {
let view = document.getElementById(`video-${remoteUid}`) as HTMLElement;
if (view && !view.getAttribute('load')) {
await agora.setupRemoteVideoJoin({
uid: Number(remoteUid),
view,
channelId: info.channelId,
})
view.setAttribute('load', 'true')
}
}, 1000);
},
onUserOffline: async (info: any, remoteUid: any, _reason: any) => {
@ -153,6 +169,14 @@ const Meeting: React.FC = () => {
view: document.getElementById(`video-${remoteUid}`) as HTMLElement,
channelId: info.channelId,
})
if (String(info.localUid).length === 9) {
await agora.setupRemoteVideo({
uid: Number(remoteUid),
view: document.getElementById(`look-video`) as HTMLElement,
channelId: info.channelId,
sourceType: VideoSourceType.VideoSourceScreen,
})
}
setTimeout(() => {
getRoomUser()
}, 1000);

View File

@ -56,6 +56,9 @@ const agora = {
onUserOffline: async (info: any, remoteUid: any, reason: any) => {
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) => {
// if (newState === 1) {
@ -150,7 +153,8 @@ const agora = {
// 摄像头采集
setCameraCapture: () => {
agora.stopScreenCapture()
// rtcEngine.destroyRendererByConfig(option.sourceType, option.channelId, option.account)
const user = JSON.parse(storage.getItem('user') as string)
rtcEngine.destroyRendererByConfig(VideoSourceType.VideoSourceScreen, option.channelId, Number(user.screenShareId))
agora.setupLocalVideo({
uid: Number(option.uid),
view: document.getElementById(`video-${option.uid}`),
@ -173,11 +177,11 @@ const agora = {
// 共享屏幕采集
setDesktopCapturerVideo: async (targetSource: any) => {
// await rtcEngine.stopCameraCapture(option.sourceType)
// rtcEngine.destroyRendererByConfig(option.sourceType, option.channelId, option.account)
const user = JSON.parse(storage.getItem('user') as string)
rtcEngine.destroyRendererByConfig(VideoSourceType.VideoSourceScreen, option.channelId, Number(user.screenShareId))
rtcEngine.joinChannelEx(
option.token,
{ channelId: option.channelId, localUid: Number(user.uid) },
{ channelId: option.channelId, localUid: Number(user.screenShareId) },
{
autoSubscribeAudio: false,
autoSubscribeVideo: false,
@ -187,12 +191,6 @@ const agora = {
publishScreenTrack: true,
}
);
await agora.setupLocalVideo({
uid: Number(user.uid),
view: document.getElementById(`look-video`),
channelId: option.channelId,
sourceType: VideoSourceType.VideoSourceScreen,
})
agora.stopScreenCapture();
if (
targetSource.type ===