Skip to content

Commit

Permalink
refactor(flat-stores): automatically on stage in small class mode (#1867
Browse files Browse the repository at this point in the history
)

* fix(flat-stores): update device states when self on stage

* refactor(flat-stores): automatically on stage in small class mode
  • Loading branch information
hyrious authored Mar 14, 2023
1 parent 68c109d commit 184e9ba
Showing 1 changed file with 31 additions and 16 deletions.
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

0 comments on commit 184e9ba

Please sign in to comment.