Skip to content

Commit

Permalink
fix(classroom): enable device base on preferences when on stage (#1696)
Browse files Browse the repository at this point in the history
  • Loading branch information
crimx authored Sep 16, 2022
1 parent 079f939 commit 2994a05
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
38 changes: 32 additions & 6 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 { Storage } from "@netless/fastboard";
import type { Diff, Storage } from "@netless/fastboard";

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

const updateUserStagingState = async (): Promise<void> => {
const updateUserStagingState = async (
diff?: Diff<OnStageUsersStorageState>,
): Promise<void> => {
const onStageUsers = Object.keys(onStageUsersStorage.state).filter(
userUUID => onStageUsersStorage.state[userUUID],
);
Expand Down Expand Up @@ -406,9 +408,33 @@ export class ClassroomStore {
});

if (!this.isCreator) {
this.whiteboardStore.updateWritable(
Boolean(onStageUsersStorage.state[this.userUUID]),
);
const isJoinerOnStage = Boolean(onStageUsersStorage.state[this.userUUID]);
await this.whiteboardStore.updateWritable(isJoinerOnStage);

// @FIXME add reliable way to ensure writable is set
if (isJoinerOnStage && !fastboard.syncedStore.isRoomWritable) {
await new Promise<void>(resolve => {
const disposer = fastboard.syncedStore.addRoomWritableChangeListener(
isWritable => {
if (isWritable) {
disposer();
resolve();
}
},
);
});
}

if (
isJoinerOnStage &&
(diff?.[this.userUUID] || !deviceStateStorage.state[this.userUUID])
) {
this.updateDeviceState(
this.userUUID,
preferencesStore.autoCameraOn,
preferencesStore.autoMicOn,
);
}
}
};
updateUserStagingState();
Expand Down Expand Up @@ -607,7 +633,7 @@ export class ClassroomStore {
this.onStageUsersStorage.setState({ [userUUID]: false });
}
}
if (!this.isCreator && !onStage) {
if (!onStage && (!this.isCreator || userUUID !== this.userUUID)) {
this.updateDeviceState(userUUID, false, false);
}
};
Expand Down
2 changes: 1 addition & 1 deletion service-providers/fastboard/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class Fastboard extends IServiceWhiteboard {
};
}, "setWritable");
}
}),
}, true),
this._el$.subscribe(el => {
if (el) {
this.ui.mount(el, {
Expand Down

0 comments on commit 2994a05

Please sign in to comment.