diff --git a/src/views/meeting/meeting-room/meeting-room-student.vue b/src/views/meeting/meeting-room/meeting-room-student.vue index 1d4890c..0a9fcda 100644 --- a/src/views/meeting/meeting-room/meeting-room-student.vue +++ b/src/views/meeting/meeting-room/meeting-room-student.vue @@ -176,8 +176,25 @@ const isTeacherDualStream = computed(() => Boolean(teacherUid.value && screenShareOwnerUid.value)); + /** 根据投屏用户短 UID 计算实际的声网 UID */ + function calculateScreenActualUid(uid: number): number { + return uid + 1000000; + } + + /** 获取当前投屏的实际声网 UID(如果有) */ + const screenShareActualUid = computed(() => { + if (typeof screenShareOwnerUid.value === 'number' && screenShareOwnerUid.value > 0) { + return calculateScreenActualUid(screenShareOwnerUid.value); + } + return null; + }); + const teacherPreferredPrimaryUid = computed(() => { - return screenShareOwnerUid.value ?? speakerUid.value ?? (teacherUid.value || null); + // 如果有投屏,优先使用投屏的实际 UID + if (screenShareActualUid.value) { + return screenShareActualUid.value; + } + return speakerUid.value ?? (teacherUid.value || null); }); const primaryUid = computed(() => { @@ -197,7 +214,9 @@ if (!teacherUid.value || !screenShareOwnerUid.value) { return null; } - return primaryUid.value === screenShareOwnerUid.value ? teacherUid.value : screenShareOwnerUid.value; + // 如果主讲是投屏,小窗显示老师摄像头;否则显示投屏 + const primaryIsScreen = primaryUid.value === screenShareActualUid.value; + return primaryIsScreen ? teacherUid.value : screenShareActualUid.value; }); const selfWindowUid = computed(() => secondaryUid.value); @@ -215,7 +234,7 @@ if (!selfWindowUid.value) { return userName.value; } - if (selfWindowUid.value === screenShareOwnerUid.value) { + if (selfWindowUid.value === screenShareActualUid.value) { return `${screenOwnerName.value || '主讲'}(投屏)`; } return '主讲(摄像头)'; @@ -235,7 +254,7 @@ }); /** 是否为投屏主画面 */ - const isPrimaryScreenSharing = computed(() => Boolean(primaryUid.value && screenShareOwnerUid.value === primaryUid.value)); + const isPrimaryScreenSharing = computed(() => Boolean(primaryUid.value && primaryUid.value === screenShareActualUid.value)); /** 舞台容器 DOM */ const stageRef = ref(null); @@ -537,6 +556,7 @@ const targetUid = packet.data?.targetUid; if (typeof targetUid === 'number') { screenShareOwnerUid.value = targetUid; + console.log('[屏幕共享] 收到开始投屏消息:', { targetUid, calculatedActualUid: calculateScreenActualUid(targetUid) }); Toast.info?.(`用户 ${targetUid} 开始投屏`); } break; @@ -545,6 +565,7 @@ const targetUid = packet.data?.targetUid; if (typeof targetUid === 'number') { screenShareOwnerUid.value = null; + console.log('[屏幕共享] 收到停止投屏消息:', { targetUid }); Toast.info?.(`用户 ${targetUid} 停止投屏`); } break;