소스 검색

优化 toggleCamera

yourname 7 달 전
부모
커밋
6850b517e7
1개의 변경된 파일15개의 추가작업 그리고 25개의 파일을 삭제
  1. 15 25
      client/mobile/pages_classroom.tsx

+ 15 - 25
client/mobile/pages_classroom.tsx

@@ -723,38 +723,28 @@ export const ClassroomPage = () => {
     // showToast('info', '已离开RTC频道');
   };
 
-  // 开启摄像头预览
-  const startCameraPreview = async () => {
-    if (!aliRtcEngine.current) return;
-    
-    await leaveRtcChannel()
-    await joinRtcChannel(classId, {
-      publishVideo:true
-    })
-    aliRtcEngine.current.setLocalViewConfig('localPreviewer', AliRtcVideoTrack.AliRtcVideoTrackCamera);
-    await aliRtcEngine.current.startPreview();
-    // showToast('info', '摄像头已开启');
-  };
 
-  // 关闭摄像头预览
-  const stopCameraPreview = async () => {
-    if (!aliRtcEngine.current) return;
-
-    await leaveRtcChannel()
-    await joinRtcChannel(classId, {
-      publishVideo: false
-    })
-    await aliRtcEngine.current.stopPreview();
-    // showToast('info', '摄像头已关闭');
-  };
 
   // 切换摄像头状态
   const toggleCamera = async () => {
     try {
       if (isCameraOn) {
-        await stopCameraPreview();
+        await leaveRtcChannel();
+        await joinRtcChannel(classId, {
+          publishVideo: false,
+          publishAudio: isAudioOn,
+          publishScreen: isScreenSharing
+        });
+        await aliRtcEngine.current?.stopPreview();
       } else {
-        await startCameraPreview();
+        await leaveRtcChannel();
+        await joinRtcChannel(classId, {
+          publishVideo: true,
+          publishAudio: isAudioOn,
+          publishScreen: isScreenSharing
+        });
+        aliRtcEngine.current?.setLocalViewConfig('localPreviewer', AliRtcVideoTrack.AliRtcVideoTrackCamera);
+        await aliRtcEngine.current?.startPreview();
       }
       setIsCameraOn(!isCameraOn);
     } catch (err) {