Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(classroom): adjust small class #1570

Merged
merged 1 commit into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions desktop/renderer-app/src/pages/SmallClassPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ export const SmallClassPage = observer<SmallClassPageProps>(function SmallClassP
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [classRoomStore.classMode, whiteboardStore.room, classRoomStore.users.currentUser?.isSpeak]);

// Turn off the microphone automatically when it becomes lecture mode.
useEffect(() => {
if (!classRoomStore.isCreator && whiteboardStore.room) {
const currentUser = classRoomStore.users.currentUser;
if (classRoomStore.classMode === ClassModeType.Lecture && currentUser) {
classRoomStore.updateDeviceState(currentUser.userUUID, currentUser.camera, false);
}
}
}, [classRoomStore, classRoomStore.classMode, whiteboardStore.room]);

useEffect(() => {
if (classRoomStore.isRecording) {
window.clearTimeout(updateLayoutTimeoutRef.current);
Expand Down Expand Up @@ -278,20 +288,20 @@ export const SmallClassPage = observer<SmallClassPageProps>(function SmallClassP
return classRoomStore.classMode === ClassModeType.Lecture ? (
<TopBarRoundBtn
dark
icon={<SVGModeInteractive />}
title={t("lecture-mode")}
icon={<SVGModeLecture />}
title={t("switch-to-interactive-mode")}
onClick={classRoomStore.toggleClassMode}
>
{t("switch-to-interactive-mode")}
{t("lecture-mode")}
</TopBarRoundBtn>
) : (
<TopBarRoundBtn
dark
icon={<SVGModeLecture />}
title={t("interactive-mode")}
icon={<SVGModeInteractive />}
title={t("switch-to-lecture-mode")}
onClick={classRoomStore.toggleClassMode}
>
{t("switch-to-lecture-mode")}
{t("interactive-mode")}
</TopBarRoundBtn>
);
}
Expand Down Expand Up @@ -370,7 +380,17 @@ export const SmallClassPage = observer<SmallClassPageProps>(function SmallClassP
isCreator={classRoomStore.isCreator}
rtcAvatar={classRoomStore.rtc.getAvatar(user.rtcUID)}
small={true}
updateDeviceState={classRoomStore.updateDeviceState}
updateDeviceState={(uid, camera, mic) => {
// Disallow toggling mic when not speak.
const _mic =
whiteboardStore.isWritable ||
user.userUUID === classRoomStore.ownerUUID ||
user.userUUID !== classRoomStore.users.currentUser?.userUUID ||
classRoomStore.classMode !== ClassModeType.Lecture
? mic
: user.mic;
classRoomStore.updateDeviceState(uid, camera, _mic);
}}
userUUID={classRoomStore.userUUID}
/>
);
Expand Down
4 changes: 4 additions & 0 deletions desktop/renderer-app/src/stores/class-room-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,10 @@ export class ClassRoomStore {
}
return true;
});
// Turn on the microphone automatically.
if (accept && userUUID === this.userUUID && this.users.currentUser) {
this.updateDeviceState(userUUID, this.users.currentUser.camera, true);
}
}
});

Expand Down
12 changes: 8 additions & 4 deletions desktop/renderer-app/src/stores/whiteboard-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,14 @@ export class WhiteboardStore {
this.isWritable = isWritable;

if (oldWritable !== isWritable && this.room) {
await this.room.setWritable(isWritable);
this.room.disableDeviceInputs = !isWritable;
if (isWritable) {
this.room.disableSerialization = false;
try {
await this.room.setWritable(isWritable);
this.room.disableDeviceInputs = !isWritable;
if (isWritable) {
this.room.disableSerialization = false;
}
} catch {
/* ignored */
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions packages/flat-i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@
"view-all-rooms-in-periodic-rooms": "View all ({{count}}) rooms",
"ending": "Ending...",
"follow-your-perspective-tips": "Other users will follow your perspective",
"interactive-mode": "Currently in interactive mode",
"lecture-mode": "Currently in lecture mode",
"interactive-mode": "Interactive Mode",
"lecture-mode": "Lecture Mode",
"more": "More",
"pause": "pause",
"pausing": "Pausing...",
Expand Down
8 changes: 4 additions & 4 deletions packages/flat-i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,10 @@
"resume": "恢复上课",
"start": "开始上课",
"follow-your-perspective-tips": "其他用户将跟随您的视角",
"lecture-mode": "当前为讲课模式",
"switch-to-interactive-mode": "互动模式",
"interactive-mode": "当前为互动模式",
"switch-to-lecture-mode": "讲课模式",
"lecture-mode": "讲课模式",
"switch-to-interactive-mode": "切换为互动模式",
"interactive-mode": "互动模式",
"switch-to-lecture-mode": "切换为讲课模式",
"recording-completed-tips": "录制完成,可到历史记录查看",
"general-settings": "常规设置",
"shortcut-settings": "热键设置",
Expand Down
34 changes: 27 additions & 7 deletions web/flat-web/src/pages/SmallClassPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ export const SmallClassPage = observer<SmallClassPageProps>(function SmallClassP
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [classRoomStore.classMode, whiteboardStore.room, classRoomStore.users.currentUser?.isSpeak]);

// Turn off the microphone automatically when it becomes lecture mode.
useEffect(() => {
if (!classRoomStore.isCreator && whiteboardStore.room) {
const currentUser = classRoomStore.users.currentUser;
if (classRoomStore.classMode === ClassModeType.Lecture && currentUser) {
classRoomStore.updateDeviceState(currentUser.userUUID, currentUser.camera, false);
}
}
}, [classRoomStore, classRoomStore.classMode, whiteboardStore.room]);

useEffect(() => {
if (classRoomStore.isRecording) {
window.clearTimeout(updateLayoutTimeoutRef.current);
Expand Down Expand Up @@ -230,20 +240,20 @@ export const SmallClassPage = observer<SmallClassPageProps>(function SmallClassP
return classRoomStore.classMode === ClassModeType.Lecture ? (
<TopBarRoundBtn
dark
icon={<SVGModeInteractive />}
title={t("lecture-mode")}
icon={<SVGModeLecture />}
title={t("switch-to-interactive-mode")}
onClick={classRoomStore.toggleClassMode}
>
{t("switch-to-interactive-mode")}
{t("lecture-mode")}
</TopBarRoundBtn>
) : (
<TopBarRoundBtn
dark
icon={<SVGModeLecture />}
title={t("interactive-mode")}
icon={<SVGModeInteractive />}
title={t("switch-to-lecture-mode")}
onClick={classRoomStore.toggleClassMode}
>
{t("switch-to-lecture-mode")}
{t("interactive-mode")}
</TopBarRoundBtn>
);
}
Expand Down Expand Up @@ -318,7 +328,17 @@ export const SmallClassPage = observer<SmallClassPageProps>(function SmallClassP
isCreator={classRoomStore.isCreator}
rtcAvatar={classRoomStore.rtc.getAvatar(user.rtcUID)}
small={true}
updateDeviceState={classRoomStore.updateDeviceState}
updateDeviceState={(uid, camera, mic) => {
// Disallow toggling mic when not speak.
const _mic =
whiteboardStore.isWritable ||
user.userUUID === classRoomStore.ownerUUID ||
user.userUUID !== classRoomStore.users.currentUser?.userUUID ||
classRoomStore.classMode !== ClassModeType.Lecture
? mic
: user.mic;
classRoomStore.updateDeviceState(uid, camera, _mic);
}}
userUUID={classRoomStore.userUUID}
/>
);
Expand Down
4 changes: 4 additions & 0 deletions web/flat-web/src/stores/class-room-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,10 @@ export class ClassRoomStore {
}
return true;
});
// Turn on the microphone automatically.
if (accept && userUUID === this.userUUID && this.users.currentUser) {
this.updateDeviceState(userUUID, this.users.currentUser.camera, true);
}
}
});

Expand Down
12 changes: 8 additions & 4 deletions web/flat-web/src/stores/whiteboard-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,14 @@ export class WhiteboardStore {

this.isWritable = isWritable;
if (oldWritable !== isWritable && this.room) {
await this.room.setWritable(isWritable);
this.room.disableDeviceInputs = !isWritable;
if (isWritable) {
this.room.disableSerialization = false;
try {
await this.room.setWritable(isWritable);
this.room.disableDeviceInputs = !isWritable;
if (isWritable) {
this.room.disableSerialization = false;
}
} catch {
/* ignored */
}
}
};
Expand Down