|
|
@@ -6,7 +6,7 @@ import { useParams } from 'react-router';
|
|
|
import AliRtcEngine, { AliRtcSubscribeState, AliRtcVideoTrack } from 'aliyun-rtc-sdk';
|
|
|
import { toast } from 'react-toastify';
|
|
|
import { User } from '../../hooks/AuthProvider';
|
|
|
-import { classroomDataClient } from '@/client/api';
|
|
|
+import { classroomDataClient, aliyunClient } from '@/client/api';
|
|
|
import "https://g.alicdn.com/apsara-media-box/imp-interaction/1.6.1/alivc-im.iife.js"
|
|
|
export enum Role {
|
|
|
Teacher = 'admin',
|
|
|
@@ -127,7 +127,14 @@ export const useClassroom = ({ user }:{ user : User }) => {
|
|
|
showMessage(`IM断开连接: ${code}`);
|
|
|
// 自动重连
|
|
|
try {
|
|
|
- const { token, nonce, timestamp } = await ClassroomAPI.getIMToken(userId, role);
|
|
|
+ const res = await aliyunClient.im_token.$post({
|
|
|
+ json: { role }
|
|
|
+ });
|
|
|
+ if(!res.ok) {
|
|
|
+ const { message } = await res.json()
|
|
|
+ throw new Error(message)
|
|
|
+ }
|
|
|
+ const { token, nonce, timestamp } = await res.json()
|
|
|
await imEngine.current!.login({
|
|
|
user: {
|
|
|
userId,
|
|
|
@@ -406,7 +413,14 @@ export const useClassroom = ({ user }:{ user : User }) => {
|
|
|
|
|
|
try {
|
|
|
const { ImEngine: ImEngineClass } = window.AliVCInteraction;
|
|
|
- const {appId, appSign, timestamp, nonce, token} = await ClassroomAPI.getIMToken(userId, role);
|
|
|
+ const res = await aliyunClient.im_token.$post({
|
|
|
+ json: { role }
|
|
|
+ });
|
|
|
+ if(!res.ok) {
|
|
|
+ const { message } = await res.json()
|
|
|
+ throw new Error(message)
|
|
|
+ }
|
|
|
+ const {appId, appSign, timestamp, nonce, token} = await res.json();
|
|
|
imEngine.current = ImEngineClass.createEngine();
|
|
|
await imEngine.current.init({
|
|
|
deviceId: 'xxxx',
|
|
|
@@ -674,8 +688,14 @@ export const useClassroom = ({ user }:{ user : User }) => {
|
|
|
publishAudio = false,
|
|
|
publishScreen = false,
|
|
|
} = publishOptions || {};
|
|
|
-
|
|
|
- const {appId, token, timestamp} = await ClassroomAPI.getRTCToken(classId, userId);
|
|
|
+ const res = await aliyunClient.rtc_token.$post({
|
|
|
+ json: { channelId: classId }
|
|
|
+ });
|
|
|
+ if(!res.ok) {
|
|
|
+ const { message } = await res.json()
|
|
|
+ throw new Error(message)
|
|
|
+ }
|
|
|
+ const { appId, token, timestamp } = await res.json()
|
|
|
await aliRtcEngine.current.publishLocalVideoStream(publishVideo);
|
|
|
await aliRtcEngine.current.publishLocalAudioStream(publishAudio);
|
|
|
await aliRtcEngine.current.publishLocalScreenShareStream(publishScreen);
|
|
|
@@ -715,7 +735,6 @@ export const useClassroom = ({ user }:{ user : User }) => {
|
|
|
await aliRtcEngine.current?.publishLocalVideoStream(true)
|
|
|
|
|
|
}
|
|
|
- await aliRtcEngine.current?.startAndPublishDefaultDevices()
|
|
|
setIsCameraOn(!isCameraOn);
|
|
|
} catch (err) {
|
|
|
console.error('切换摄像头状态失败:', err);
|
|
|
@@ -737,7 +756,6 @@ export const useClassroom = ({ user }:{ user : User }) => {
|
|
|
} else {
|
|
|
await aliRtcEngine.current?.publishLocalAudioStream(true);
|
|
|
}
|
|
|
- await aliRtcEngine.current?.startAndPublishDefaultDevices();
|
|
|
setIsAudioOn(!isAudioOn);
|
|
|
} catch (err) {
|
|
|
console.error('切换麦克风状态失败:', err);
|
|
|
@@ -763,7 +781,6 @@ export const useClassroom = ({ user }:{ user : User }) => {
|
|
|
AliRtcVideoTrack.AliRtcVideoTrackScreen
|
|
|
);
|
|
|
}
|
|
|
- await aliRtcEngine.current?.startAndPublishDefaultDevices()
|
|
|
setIsScreenSharing(!isScreenSharing);
|
|
|
} catch (err) {
|
|
|
console.error('切换屏幕分享失败:', err);
|