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(flat-stores): automatically on stage in small class mode #1867

Merged
merged 2 commits into from
Mar 14, 2023
Merged
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
47 changes: 31 additions & 16 deletions packages/flat-stores/src/classroom-store/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Diff, Storage } from "@netless/fastboard";
import type { Storage } from "@netless/fastboard";

import { SideEffectManager } from "side-effect-manager";
import { action, autorun, makeAutoObservable, observable, reaction, runInAction } from "mobx";
Expand Down Expand Up @@ -505,9 +505,7 @@ export class ClassroomStore {
}),
);

const updateUserStagingState = async (
diff?: Diff<OnStageUsersStorageState>,
): Promise<void> => {
const updateUserStagingState = async (): Promise<void> => {
const wasJoinerOnStage = this.onStageUserUUIDs.includes(this.userUUID);
const onStageUsers = Object.keys(onStageUsersStorage.state).filter(
userUUID => onStageUsersStorage.state[userUUID],
Expand Down Expand Up @@ -559,10 +557,7 @@ export class ClassroomStore {
});
}

if (
isJoinerOnStage &&
(diff?.[this.userUUID] || !deviceStateStorage.state[this.userUUID])
) {
if (!wasJoinerOnStage && isJoinerOnStage) {
this.updateDeviceState(
this.userUUID,
preferencesStore.autoCameraOn,
Expand Down Expand Up @@ -695,6 +690,29 @@ export class ClassroomStore {
}
}

if (
this.roomType === RoomType.SmallClass &&
!this.isCreator &&
!onStageUsersStorage.state[this.userUUID] &&
this.assertStageNotFull(false)
) {
if (!fastboard.syncedStore.isRoomWritable) {
this.whiteboardStore.updateWritable(true);
// @FIXME add reliable way to ensure writable is set
await new Promise<void>(resolve => {
const disposer = fastboard.syncedStore.addRoomWritableChangeListener(
isWritable => {
if (isWritable) {
disposer();
resolve();
}
},
);
});
}
this.onStageUsersStorage.setState({ [this.userUUID]: true });
}

if (this.isCreator) {
await this.recording.joinRoom({
roomID: this.roomUUID,
Expand Down Expand Up @@ -1033,18 +1051,15 @@ export class ClassroomStore {
}
};

private assertStageNotFull(): boolean {
private assertStageNotFull(showWarning = true): boolean {
const limit = this.roomType === RoomType.SmallClass ? 16 : 1;
if (this.onStageUserUUIDs.length < limit) {
return true;
}
message.warn({
content: FlatI18n.t(
"warn-staging-limit." +
(this.roomType === RoomType.SmallClass ? "small-class" : "other"),
),
style: { whiteSpace: "pre" },
});
const i18nKey =
"warn-staging-limit." +
(this.roomType === RoomType.SmallClass ? "small-class" : "other");
showWarning && message.warn({ content: FlatI18n.t(i18nKey), style: { whiteSpace: "pre" } });
return false;
}

Expand Down