|
@@ -474,26 +474,9 @@ export const ClassroomPage = () => {
|
|
|
listenMessageEvents();
|
|
listenMessageEvents();
|
|
|
listenRtcEvents();
|
|
listenRtcEvents();
|
|
|
|
|
|
|
|
- // 加入RTC频道
|
|
|
|
|
- const timestamp = Math.floor(Date.now() / 1000) + 3600 * 3;
|
|
|
|
|
- const token = await generateToken(RTC_APP_ID, RTC_APP_KEY, classId, userId, timestamp);
|
|
|
|
|
- aliRtcEngine.current.setChannelProfile(AliRtcSdkChannelProfile.AliRtcSdkCommunication);
|
|
|
|
|
- await aliRtcEngine.current.joinChannel(
|
|
|
|
|
- {
|
|
|
|
|
- channelId: classId,
|
|
|
|
|
- userId,
|
|
|
|
|
- appId: RTC_APP_ID,
|
|
|
|
|
- token,
|
|
|
|
|
- timestamp,
|
|
|
|
|
- },
|
|
|
|
|
- userId
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
- // 设置本地预览
|
|
|
|
|
|
|
+ // 设置本地预览配置
|
|
|
aliRtcEngine.current.setLocalViewConfig('localPreviewer', AliRtcVideoTrack.AliRtcVideoTrackCamera);
|
|
aliRtcEngine.current.setLocalViewConfig('localPreviewer', AliRtcVideoTrack.AliRtcVideoTrackCamera);
|
|
|
|
|
|
|
|
- // 保留基础RTC连接,视频发布逻辑已移至startClass
|
|
|
|
|
-
|
|
|
|
|
setIsJoinedClass(true);
|
|
setIsJoinedClass(true);
|
|
|
setErrorMessage('');
|
|
setErrorMessage('');
|
|
|
showToast('success', '加入课堂成功');
|
|
showToast('success', '加入课堂成功');
|
|
@@ -544,21 +527,6 @@ export const ClassroomPage = () => {
|
|
|
throw new Error('RTC连接未建立');
|
|
throw new Error('RTC连接未建立');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 加入RTC频道
|
|
|
|
|
- const timestamp = Math.floor(Date.now() / 1000) + 3600 * 3;
|
|
|
|
|
- const token = await generateToken(RTC_APP_ID, RTC_APP_KEY, classId, userId, timestamp);
|
|
|
|
|
- aliRtcEngine.current.setChannelProfile(AliRtcSdkChannelProfile.AliRtcSdkCommunication);
|
|
|
|
|
- await aliRtcEngine.current.joinChannel(
|
|
|
|
|
- {
|
|
|
|
|
- channelId: classId,
|
|
|
|
|
- userId,
|
|
|
|
|
- appId: RTC_APP_ID,
|
|
|
|
|
- token,
|
|
|
|
|
- timestamp,
|
|
|
|
|
- },
|
|
|
|
|
- userId
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
// 开启老师视频
|
|
// 开启老师视频
|
|
|
try {
|
|
try {
|
|
|
aliRtcEngine.current!.setLocalViewConfig('localPreviewer', AliRtcVideoTrack.AliRtcVideoTrackCamera);
|
|
aliRtcEngine.current!.setLocalViewConfig('localPreviewer', AliRtcVideoTrack.AliRtcVideoTrackCamera);
|
|
@@ -701,12 +669,28 @@ export const ClassroomPage = () => {
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
if (isCameraOn) {
|
|
if (isCameraOn) {
|
|
|
|
|
+ // 关闭摄像头并退出RTC频道
|
|
|
await aliRtcEngine.current.stopPreview();
|
|
await aliRtcEngine.current.stopPreview();
|
|
|
|
|
+ await aliRtcEngine.current.leaveChannel();
|
|
|
|
|
+ showToast('info', '摄像头已关闭并退出RTC频道');
|
|
|
} 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
|
|
|
|
|
+ );
|
|
|
await aliRtcEngine.current.startPreview();
|
|
await aliRtcEngine.current.startPreview();
|
|
|
|
|
+ showToast('info', '已加入RTC频道并开启摄像头');
|
|
|
}
|
|
}
|
|
|
setIsCameraOn(!isCameraOn);
|
|
setIsCameraOn(!isCameraOn);
|
|
|
- showToast('info', `摄像头已${isCameraOn ? '关闭' : '开启'}`);
|
|
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
console.error('切换摄像头状态失败:', err);
|
|
console.error('切换摄像头状态失败:', err);
|
|
|
showToast('error', '切换摄像头失败');
|
|
showToast('error', '切换摄像头失败');
|