|
@@ -92,6 +92,7 @@ export const useClassroom = () => {
|
|
|
const [questions, setQuestions] = useState<Question[]>([]);
|
|
const [questions, setQuestions] = useState<Question[]>([]);
|
|
|
const [students, setStudents] = useState<Array<{id: string, name: string}>>([]);
|
|
const [students, setStudents] = useState<Array<{id: string, name: string}>>([]);
|
|
|
const [shareLink, setShareLink] = useState<string>('');
|
|
const [shareLink, setShareLink] = useState<string>('');
|
|
|
|
|
+ const [showCameraOverlay, setShowCameraOverlay] = useState<boolean>(true);
|
|
|
|
|
|
|
|
// SDK实例
|
|
// SDK实例
|
|
|
const imEngine = useRef<ImEngine | null>(null);
|
|
const imEngine = useRef<ImEngine | null>(null);
|
|
@@ -99,7 +100,8 @@ export const useClassroom = () => {
|
|
|
const imMessageManager = useRef<ImMessageManager | null>(null);
|
|
const imMessageManager = useRef<ImMessageManager | null>(null);
|
|
|
const aliRtcEngine = useRef<AliRtcEngine | null>(null);
|
|
const aliRtcEngine = useRef<AliRtcEngine | null>(null);
|
|
|
const remoteVideoElMap = useRef<Record<string, HTMLVideoElement>>({});
|
|
const remoteVideoElMap = useRef<Record<string, HTMLVideoElement>>({});
|
|
|
- const remoteVideoContainer = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
|
+ const remoteScreenContainer = useRef<HTMLDivElement>(null); // 主屏幕共享容器(重命名)
|
|
|
|
|
+ const remoteCameraContainer = useRef<HTMLDivElement>(null); // 摄像头小窗容器
|
|
|
|
|
|
|
|
// 辅助函数
|
|
// 辅助函数
|
|
|
const showMessage = (text: string): void => {
|
|
const showMessage = (text: string): void => {
|
|
@@ -275,7 +277,13 @@ export const useClassroom = () => {
|
|
|
if (el) {
|
|
if (el) {
|
|
|
aliRtcEngine.current!.setRemoteViewConfig(null, userId, type === 'camera' ? AliRtcVideoTrack.AliRtcVideoTrackCamera : AliRtcVideoTrack.AliRtcVideoTrackScreen);
|
|
aliRtcEngine.current!.setRemoteViewConfig(null, userId, type === 'camera' ? AliRtcVideoTrack.AliRtcVideoTrackCamera : AliRtcVideoTrack.AliRtcVideoTrackScreen);
|
|
|
el.pause();
|
|
el.pause();
|
|
|
- remoteVideoContainer.current?.removeChild(el);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 根据流类型从不同容器移除
|
|
|
|
|
+ if (type === 'camera') {
|
|
|
|
|
+ remoteCameraContainer.current?.removeChild(el);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ remoteScreenContainer.current?.removeChild(el);
|
|
|
|
|
+ }
|
|
|
delete remoteVideoElMap.current[vid];
|
|
delete remoteVideoElMap.current[vid];
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
@@ -321,13 +329,12 @@ export const useClassroom = () => {
|
|
|
video.playsInline = true;
|
|
video.playsInline = true;
|
|
|
video.className = 'w-80 h-45 mr-2 mb-2 bg-black';
|
|
video.className = 'w-80 h-45 mr-2 mb-2 bg-black';
|
|
|
|
|
|
|
|
- if (!remoteVideoContainer.current) {
|
|
|
|
|
- console.error('远程视频容器未找到');
|
|
|
|
|
|
|
+ if (!remoteCameraContainer.current) {
|
|
|
|
|
+ console.error('摄像头视频容器未找到');
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- remoteVideoContainer.current.style.display = 'block';
|
|
|
|
|
- remoteVideoContainer.current.appendChild(video);
|
|
|
|
|
|
|
+ remoteCameraContainer.current.appendChild(video);
|
|
|
remoteVideoElMap.current[`camera_${userId}`] = video;
|
|
remoteVideoElMap.current[`camera_${userId}`] = video;
|
|
|
|
|
|
|
|
aliRtcEngine.current!.setRemoteViewConfig(
|
|
aliRtcEngine.current!.setRemoteViewConfig(
|
|
@@ -346,6 +353,7 @@ export const useClassroom = () => {
|
|
|
|
|
|
|
|
case 1: // 取消订阅
|
|
case 1: // 取消订阅
|
|
|
console.log(`取消订阅用户 ${userId} 的视频流`);
|
|
console.log(`取消订阅用户 ${userId} 的视频流`);
|
|
|
|
|
+ showMessage(`取消订阅用户 ${userId} 的视频流`);
|
|
|
removeRemoteVideo(userId, 'camera');
|
|
removeRemoteVideo(userId, 'camera');
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
@@ -380,14 +388,14 @@ export const useClassroom = () => {
|
|
|
const video = document.createElement('video');
|
|
const video = document.createElement('video');
|
|
|
video.autoplay = true;
|
|
video.autoplay = true;
|
|
|
video.playsInline = true;
|
|
video.playsInline = true;
|
|
|
- video.className = 'w-80 h-45 mr-2 mb-2 bg-black';
|
|
|
|
|
|
|
+ video.className = 'w-full h-full bg-black';
|
|
|
|
|
|
|
|
- if (!remoteVideoContainer.current) {
|
|
|
|
|
- console.error('远程视频容器未找到');
|
|
|
|
|
|
|
+ if (!remoteScreenContainer.current) {
|
|
|
|
|
+ console.error('屏幕共享容器未找到');
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- remoteVideoContainer.current.appendChild(video);
|
|
|
|
|
|
|
+ remoteScreenContainer.current.appendChild(video);
|
|
|
remoteVideoElMap.current[`screen_${userId}`] = video;
|
|
remoteVideoElMap.current[`screen_${userId}`] = video;
|
|
|
|
|
|
|
|
aliRtcEngine.current!.setRemoteViewConfig(
|
|
aliRtcEngine.current!.setRemoteViewConfig(
|
|
@@ -406,6 +414,7 @@ export const useClassroom = () => {
|
|
|
|
|
|
|
|
case 1: // 取消订阅
|
|
case 1: // 取消订阅
|
|
|
console.log(`取消订阅用户 ${userId} 的屏幕分享流`);
|
|
console.log(`取消订阅用户 ${userId} 的屏幕分享流`);
|
|
|
|
|
+ showMessage(`取消订阅用户 ${userId} 的屏幕分享流`);
|
|
|
removeRemoteVideo(userId, 'screen');
|
|
removeRemoteVideo(userId, 'screen');
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
@@ -917,7 +926,10 @@ export const useClassroom = () => {
|
|
|
questions,
|
|
questions,
|
|
|
students,
|
|
students,
|
|
|
shareLink,
|
|
shareLink,
|
|
|
- remoteVideoContainer,
|
|
|
|
|
|
|
+ remoteScreenContainer, // 重命名为remoteScreenContainer
|
|
|
|
|
+ remoteCameraContainer, // 导出摄像头容器ref
|
|
|
|
|
+ showCameraOverlay,
|
|
|
|
|
+ setShowCameraOverlay,
|
|
|
|
|
|
|
|
// 方法
|
|
// 方法
|
|
|
login,
|
|
login,
|