|
|
@@ -421,7 +421,10 @@ export const useClassroom = () => {
|
|
|
|
|
|
// 课堂操作方法
|
|
|
const login = async (userId: string): Promise<void> => {
|
|
|
- if(!role) return;
|
|
|
+ if(!role) {
|
|
|
+ showToast('error', '角色不存在');
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
try {
|
|
|
const { ImEngine: ImEngineClass } = window.AliVCInteraction;
|
|
|
@@ -462,32 +465,34 @@ export const useClassroom = () => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- const joinClass = async (classId?: string): Promise<void> => {
|
|
|
+ const joinClass = async (classId: string): Promise<void> => {
|
|
|
if (!imEngine.current || !aliRtcEngine.current) return;
|
|
|
|
|
|
- // 优先使用URL参数中的classId和role
|
|
|
- const { id: pathClassId, role: pathRole } = useParams();
|
|
|
- const finalClassId = (classId || pathClassId) as string;
|
|
|
- if (pathRole && ['teacher', 'student'].includes(pathRole)) {
|
|
|
- setRole(pathRole === 'teacher' ? Role.Teacher : Role.Student);
|
|
|
- }
|
|
|
+ // // 优先使用URL参数中的classId和role
|
|
|
+ // const { id: pathClassId, role: pathRole } = useParams();
|
|
|
+ // const finalClassId = (classId || pathClassId) as string;
|
|
|
+ // if (pathRole && ['teacher', 'student'].includes(pathRole)) {
|
|
|
+ // setRole(pathRole === 'teacher' ? Role.Teacher : Role.Student);
|
|
|
+ // }
|
|
|
|
|
|
- if (!finalClassId) {
|
|
|
- setErrorMessage('课堂ID不能为空');
|
|
|
- showToast('error', '请输入有效的课堂ID');
|
|
|
- return;
|
|
|
- }
|
|
|
+ // if (!finalClassId) {
|
|
|
+ // setErrorMessage('课堂ID不能为空');
|
|
|
+ // showToast('error', '请输入有效的课堂ID');
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
|
|
|
try {
|
|
|
const gm = imEngine.current.getGroupManager();
|
|
|
const mm = imEngine.current.getMessageManager();
|
|
|
imGroupManager.current = gm || null;
|
|
|
imMessageManager.current = mm || null;
|
|
|
- await gm!.joinGroup(finalClassId);
|
|
|
+ await gm!.joinGroup(classId);
|
|
|
listenGroupEvents();
|
|
|
listenMessageEvents();
|
|
|
|
|
|
- await joinRtcChannel(finalClassId);
|
|
|
+ await joinRtcChannel(classId);
|
|
|
+
|
|
|
+ buildShareLink(classId)
|
|
|
|
|
|
setIsJoinedClass(true);
|
|
|
setErrorMessage('');
|
|
|
@@ -498,7 +503,7 @@ export const useClassroom = () => {
|
|
|
|
|
|
if (imGroupManager.current) {
|
|
|
try {
|
|
|
- await imGroupManager.current.leaveGroup(finalClassId);
|
|
|
+ await imGroupManager.current.leaveGroup(classId);
|
|
|
} catch (leaveErr) {
|
|
|
console.error('离开IM群组失败:', leaveErr);
|
|
|
}
|
|
|
@@ -601,6 +606,17 @@ export const useClassroom = () => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ const buildShareLink = (classId: string) => {
|
|
|
+ const getBaseUrl = () => {
|
|
|
+ const protocol = window.location.protocol;
|
|
|
+ const host = window.location.host;
|
|
|
+ return `${protocol}//${host}`;
|
|
|
+ }
|
|
|
+ // const baseUrl = window.location.href.split('?')[0].replace(/\/[^/]*$/, '');
|
|
|
+ const baseUrl = getBaseUrl();
|
|
|
+ setShareLink(`${baseUrl}/mobile/classroom/${classId}/student`);
|
|
|
+ }
|
|
|
+
|
|
|
const createClass = async (className: string, maxMembers = 200): Promise<string | null> => {
|
|
|
if (!imEngine.current || !isLoggedIn || role !== Role.Teacher) {
|
|
|
showToast('error', '只有老师可以创建课堂');
|
|
|
@@ -646,8 +662,9 @@ export const useClassroom = () => {
|
|
|
|
|
|
await joinRtcChannel(response.groupId);
|
|
|
|
|
|
- const baseUrl = window.location.href.split('?')[0].replace(/\/[^/]*$/, '');
|
|
|
- setShareLink(`${baseUrl}/mobile/classroom/${response.groupId}/student`);
|
|
|
+ // const baseUrl = window.location.href.split('?')[0].replace(/\/[^/]*$/, '');
|
|
|
+ // setShareLink(`${baseUrl}/mobile/classroom/${response.groupId}/student`);
|
|
|
+ buildShareLink(response.groupId)
|
|
|
|
|
|
return response.groupId;
|
|
|
} catch (joinErr: any) {
|