|
@@ -645,34 +645,54 @@ export const ClassroomPage = () => {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- // 切换摄像头状态
|
|
|
|
|
- const toggleCamera = async () => {
|
|
|
|
|
|
|
+ // 加入RTC频道
|
|
|
|
|
+ const joinRtcChannel = async () => {
|
|
|
if (!aliRtcEngine.current) return;
|
|
if (!aliRtcEngine.current) return;
|
|
|
|
|
|
|
|
|
|
+ const timestamp = Math.floor(Date.now() / 1000) + 3600 * 3;
|
|
|
|
|
+ const token = await generateToken(RTC_APP_ID, RTC_APP_KEY, classId, userId, timestamp);
|
|
|
|
|
+ await aliRtcEngine.current.joinChannel(
|
|
|
|
|
+ {
|
|
|
|
|
+ channelId: classId,
|
|
|
|
|
+ userId,
|
|
|
|
|
+ appId: RTC_APP_ID,
|
|
|
|
|
+ token,
|
|
|
|
|
+ timestamp,
|
|
|
|
|
+ },
|
|
|
|
|
+ userId
|
|
|
|
|
+ );
|
|
|
|
|
+ showToast('info', '已加入RTC频道');
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ // 离开RTC频道
|
|
|
|
|
+ const leaveRtcChannel = async () => {
|
|
|
|
|
+ if (!aliRtcEngine.current) return;
|
|
|
|
|
+ await aliRtcEngine.current.leaveChannel();
|
|
|
|
|
+ showToast('info', '已离开RTC频道');
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ // 开启摄像头预览
|
|
|
|
|
+ const startCameraPreview = async () => {
|
|
|
|
|
+ if (!aliRtcEngine.current) return;
|
|
|
|
|
+ aliRtcEngine.current.setLocalViewConfig('localPreviewer', AliRtcVideoTrack.AliRtcVideoTrackCamera);
|
|
|
|
|
+ await aliRtcEngine.current.startPreview();
|
|
|
|
|
+ showToast('info', '摄像头已开启');
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ // 关闭摄像头预览
|
|
|
|
|
+ const stopCameraPreview = async () => {
|
|
|
|
|
+ if (!aliRtcEngine.current) return;
|
|
|
|
|
+ await aliRtcEngine.current.stopPreview();
|
|
|
|
|
+ showToast('info', '摄像头已关闭');
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ // 切换摄像头状态
|
|
|
|
|
+ const toggleCamera = async () => {
|
|
|
try {
|
|
try {
|
|
|
if (isCameraOn) {
|
|
if (isCameraOn) {
|
|
|
- // 关闭摄像头并退出RTC频道
|
|
|
|
|
- await aliRtcEngine.current.stopPreview();
|
|
|
|
|
- await aliRtcEngine.current.leaveChannel();
|
|
|
|
|
- showToast('info', '摄像头已关闭并退出RTC频道');
|
|
|
|
|
|
|
+ await stopCameraPreview();
|
|
|
} else {
|
|
} else {
|
|
|
- // 加入RTC频道并配置本地预览
|
|
|
|
|
- const timestamp = Math.floor(Date.now() / 1000) + 3600 * 3;
|
|
|
|
|
- const token = await generateToken(RTC_APP_ID, RTC_APP_KEY, classId, userId, timestamp);
|
|
|
|
|
- await aliRtcEngine.current.joinChannel(
|
|
|
|
|
- {
|
|
|
|
|
- channelId: classId,
|
|
|
|
|
- userId,
|
|
|
|
|
- appId: RTC_APP_ID,
|
|
|
|
|
- token,
|
|
|
|
|
- timestamp,
|
|
|
|
|
- },
|
|
|
|
|
- userId
|
|
|
|
|
- );
|
|
|
|
|
- // 统一设置本地预览配置
|
|
|
|
|
- aliRtcEngine.current.setLocalViewConfig('localPreviewer', AliRtcVideoTrack.AliRtcVideoTrackCamera);
|
|
|
|
|
- await aliRtcEngine.current.startPreview();
|
|
|
|
|
- showToast('info', '已加入RTC频道并开启摄像头');
|
|
|
|
|
|
|
+ await startCameraPreview();
|
|
|
}
|
|
}
|
|
|
setIsCameraOn(!isCameraOn);
|
|
setIsCameraOn(!isCameraOn);
|
|
|
} catch (err) {
|
|
} catch (err) {
|