|
|
@@ -1,5 +1,5 @@
|
|
|
import { useState, useEffect, useRef } from 'react';
|
|
|
-import { useParams, useSearchParams } from 'react-router';
|
|
|
+import { useParams } from 'react-router';
|
|
|
// import { ClassroomAPI } from '../../api/index.ts';
|
|
|
// @ts-types="../../../share/aliyun-rtc-sdk.d.ts"
|
|
|
// @ts-types="./alivc-im.iife.d.ts"
|
|
|
@@ -17,8 +17,6 @@ export enum Role {
|
|
|
type ImEngine = InstanceType<typeof AliVCInteraction.ImEngine>;
|
|
|
type ImGroupManager = AliVCInteraction.AliVCIMGroupManager;
|
|
|
type ImMessageManager = AliVCInteraction.AliVCIMMessageManager;
|
|
|
-type ImLogLevel = AliVCInteraction.ImLogLevel;
|
|
|
-type ImMessageLevel = AliVCInteraction.ImMessageLevel;
|
|
|
const { ERROR } = AliVCInteraction.ImLogLevel;
|
|
|
const { NORMAL, HIGH } = AliVCInteraction.ImMessageLevel;
|
|
|
|
|
|
@@ -27,14 +25,6 @@ interface ImUser {
|
|
|
userExtension?: string;
|
|
|
}
|
|
|
|
|
|
-interface ImGroupMessage {
|
|
|
- groupId: string;
|
|
|
- type: number;
|
|
|
- data: string;
|
|
|
- sender?: ImUser;
|
|
|
- timestamp?: number;
|
|
|
-}
|
|
|
-
|
|
|
// 互动消息类型
|
|
|
enum InteractionAction {
|
|
|
HandUp = 'hand_up',
|
|
|
@@ -197,63 +187,6 @@ export const useClassroom = ({ user }:{ user : User }) => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- // 重试操作函数
|
|
|
- const retryOperation = async <T>(
|
|
|
- operation: () => Promise<T>,
|
|
|
- maxRetries = 3,
|
|
|
- delay = 1000
|
|
|
- ): Promise<T> => {
|
|
|
- for (let i = 0; i < maxRetries; i++) {
|
|
|
- try {
|
|
|
- return await operation();
|
|
|
- } catch (error) {
|
|
|
- if (i === maxRetries - 1) throw error;
|
|
|
- await new Promise(resolve => setTimeout(resolve, delay * (i + 1)));
|
|
|
- }
|
|
|
- }
|
|
|
- throw new Error('Max retries exceeded');
|
|
|
- };
|
|
|
-
|
|
|
- // 保存IM消息到数据库(直接从IM消息对象创建)
|
|
|
- const saveImMessageToDatabase = async (
|
|
|
- msg: AliVCInteraction.ImMessage,
|
|
|
- type: 'text' | 'image' | 'system',
|
|
|
- content: string,
|
|
|
- senderName?: string
|
|
|
- ): Promise<void> => {
|
|
|
- if (!classId) return;
|
|
|
-
|
|
|
- try {
|
|
|
- await chatMessageClient.$post({
|
|
|
- json: {
|
|
|
- classId,
|
|
|
- type,
|
|
|
- content,
|
|
|
- senderId: msg.sender?.userId || null,
|
|
|
- senderName: senderName || msg.sender?.userId || '系统',
|
|
|
- timestamp: msg.timestamp || Date.now()
|
|
|
- }
|
|
|
- });
|
|
|
- } catch (error) {
|
|
|
- console.error('保存IM消息到数据库失败:', error);
|
|
|
- // 静默失败,不影响用户体验
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- // 批量保存消息到数据库
|
|
|
- const saveMessagesToDatabase = async (messages: Message[]): Promise<void> => {
|
|
|
- if (!classId || messages.length === 0) return;
|
|
|
-
|
|
|
- try {
|
|
|
- // 由于API只支持单条创建,这里逐条保存
|
|
|
- for (const message of messages) {
|
|
|
- await saveMessageToDatabase(message);
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- console.error('批量保存消息到数据库失败:', error);
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
const showToast = (type: 'info' | 'success' | 'error', message: string): void => {
|
|
|
if (type === 'info') {
|
|
|
toast.info(message);
|
|
|
@@ -264,9 +197,6 @@ export const useClassroom = ({ user }:{ user : User }) => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
// 事件监听函数
|
|
|
const listenImEvents = (): void => {
|
|
|
if (!imEngine.current) return;
|