Skip to content

Commit

Permalink
fix(region): set region when in room (#802)
Browse files Browse the repository at this point in the history
* fix(region): set region when in room

* fix(region): set region in room (renderer)
  • Loading branch information
hyrious committed Jul 20, 2021
1 parent 217510d commit 8f7ed14
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 16 deletions.
16 changes: 14 additions & 2 deletions desktop/renderer-app/src/components/Whiteboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,32 @@ import ToolBox from "@netless/tool-box";
import ZoomController from "@netless/zoom-controller";
import classNames from "classnames";
import { observer } from "mobx-react-lite";
import React, { useCallback } from "react";
import React, { useCallback, useEffect } from "react";
import { RoomPhase } from "white-web-sdk";
import { Region } from "flat-components";
import pagesSVG from "../assets/image/pages.svg";
import { ConfigStore } from "../stores/ConfigStore";
import { WhiteboardStore } from "../stores/WhiteboardStore";
import { isSupportedImageType, onDropImage } from "../utils/dnd/image";
import "./Whiteboard.less";

export interface WhiteboardProps {
whiteboardStore: WhiteboardStore;
configStore: ConfigStore;
}

export const Whiteboard = observer<WhiteboardProps>(function Whiteboard({ whiteboardStore }) {
export const Whiteboard = observer<WhiteboardProps>(function Whiteboard({
whiteboardStore,
configStore,
}) {
const { room } = whiteboardStore;

useEffect(() => {
if (room) {
configStore.setRegion(room.region as Region);
}
}, [room, configStore]);

const bindWhiteboard = useCallback(
(ref: HTMLDivElement) => {
if (room) {
Expand Down
5 changes: 3 additions & 2 deletions desktop/renderer-app/src/pages/BigClassPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
import InviteButton from "../../components/InviteButton";
import { RealtimePanel } from "../../components/RealtimePanel";
import { TopBarRightBtn } from "../../components/TopBarRightBtn";
import { GlobalStoreContext } from "../../components/StoreProvider";
import { ConfigStoreContext, GlobalStoreContext } from "../../components/StoreProvider";
import { TopBarRoundBtn } from "../../components/TopBarRoundBtn";
import { Whiteboard } from "../../components/Whiteboard";
import {
Expand Down Expand Up @@ -90,6 +90,7 @@ export const BigClassPage = observer<BigClassPageProps>(function BigClassPage()
const classRoomStore = useClassRoomStore(params.roomUUID, params.ownerUUID, recordingConfig);
const whiteboardStore = classRoomStore.whiteboardStore;
const globalStore = useContext(GlobalStoreContext);
const configStore = useContext(ConfigStoreContext);
const { confirm, ...exitConfirmModalProps } = useExitRoomConfirmModal(classRoomStore);

const [speakingJoiner, setSpeakingJoiner] = useState<User | undefined>(() =>
Expand Down Expand Up @@ -178,7 +179,7 @@ export const BigClassPage = observer<BigClassPageProps>(function BigClassPage()
right={renderTopBarRight()}
/>
<div className="realtime-content">
<Whiteboard whiteboardStore={whiteboardStore} />
<Whiteboard whiteboardStore={whiteboardStore} configStore={configStore} />
{renderRealtimePanel()}
</div>
<ExitRoomConfirm isCreator={classRoomStore.isCreator} {...exitConfirmModalProps} />
Expand Down
5 changes: 3 additions & 2 deletions desktop/renderer-app/src/pages/OneToOnePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { usePowerSaveBlocker } from "../../utils/hooks/usePowerSaveBlocker";
import { useWindowSize } from "../../utils/hooks/useWindowSize";
import { CloudStorageButton } from "../../components/CloudStorageButton";
import { AgoraCloudRecordBackgroundConfigItem } from "../../apiMiddleware/flatServer/agora";
import { GlobalStoreContext } from "../../components/StoreProvider";
import { ConfigStoreContext, GlobalStoreContext } from "../../components/StoreProvider";
import { runtime } from "../../utils/runtime";
import { useTranslation } from "react-i18next";

Expand Down Expand Up @@ -72,6 +72,7 @@ export const OneToOnePage = observer<OneToOnePageProps>(function OneToOnePage()
const classRoomStore = useClassRoomStore(params.roomUUID, params.ownerUUID, recordingConfig);
const whiteboardStore = classRoomStore.whiteboardStore;
const globalStore = useContext(GlobalStoreContext);
const configStore = useContext(ConfigStoreContext);
const { confirm, ...exitConfirmModalProps } = useExitRoomConfirmModal(classRoomStore);

const [isRealtimeSideOpen, openRealtimeSide] = useState(true);
Expand Down Expand Up @@ -136,7 +137,7 @@ export const OneToOnePage = observer<OneToOnePageProps>(function OneToOnePage()
right={renderTopBarRight()}
/>
<div className="one-to-one-realtime-content">
<Whiteboard whiteboardStore={whiteboardStore} />
<Whiteboard whiteboardStore={whiteboardStore} configStore={configStore} />
{renderRealtimePanel()}
</div>
<ExitRoomConfirm isCreator={classRoomStore.isCreator} {...exitConfirmModalProps} />
Expand Down
5 changes: 3 additions & 2 deletions desktop/renderer-app/src/pages/SmallClassPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { usePowerSaveBlocker } from "../../utils/hooks/usePowerSaveBlocker";
import "./SmallClassPage.less";
import { useWindowSize } from "../../utils/hooks/useWindowSize";
import { CloudStorageButton } from "../../components/CloudStorageButton";
import { GlobalStoreContext } from "../../components/StoreProvider";
import { ConfigStoreContext, GlobalStoreContext } from "../../components/StoreProvider";
import { runtime } from "../../utils/runtime";

const CLASSROOM_WIDTH = 1200;
Expand Down Expand Up @@ -97,6 +97,7 @@ export const SmallClassPage = observer<SmallClassPageProps>(function SmallClassP
);
const whiteboardStore = classRoomStore.whiteboardStore;
const globalStore = useContext(GlobalStoreContext);
const configStore = useContext(ConfigStoreContext);
const { confirm, ...exitConfirmModalProps } = useExitRoomConfirmModal(classRoomStore);

const { room, phase } = whiteboardStore;
Expand Down Expand Up @@ -158,7 +159,7 @@ export const SmallClassPage = observer<SmallClassPageProps>(function SmallClassP
/>
{renderAvatars()}
<div className="realtime-content">
<Whiteboard whiteboardStore={whiteboardStore} />
<Whiteboard whiteboardStore={whiteboardStore} configStore={configStore} />
{renderRealtimePanel()}
</div>
<ExitRoomConfirm isCreator={classRoomStore.isCreator} {...exitConfirmModalProps} />
Expand Down
16 changes: 14 additions & 2 deletions web/flat-web/src/components/Whiteboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,32 @@ import ToolBox from "@netless/tool-box";
import ZoomController from "@netless/zoom-controller";
import classNames from "classnames";
import { observer } from "mobx-react-lite";
import React, { useCallback } from "react";
import React, { useCallback, useEffect } from "react";
import { RoomPhase } from "white-web-sdk";
import { Region } from "flat-components";
import pagesSVG from "../assets/image/pages.svg";
import { ConfigStore } from "../stores/ConfigStore";
import { WhiteboardStore } from "../stores/WhiteboardStore";
import { isSupportedImageType, onDropImage } from "../utils/dnd/image";
import "./Whiteboard.less";

export interface WhiteboardProps {
whiteboardStore: WhiteboardStore;
configStore: ConfigStore;
}

export const Whiteboard = observer<WhiteboardProps>(function Whiteboard({ whiteboardStore }) {
export const Whiteboard = observer<WhiteboardProps>(function Whiteboard({
whiteboardStore,
configStore,
}) {
const { room } = whiteboardStore;

useEffect(() => {
if (room) {
configStore.setRegion(room.region as Region);
}
}, [room, configStore]);

const bindWhiteboard = useCallback(
(ref: HTMLDivElement) => {
if (room) {
Expand Down
5 changes: 3 additions & 2 deletions web/flat-web/src/pages/BigClassPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
} from "../../components/ExitRoomConfirm";
import InviteButton from "../../components/InviteButton";
import { RealtimePanel } from "../../components/RealtimePanel";
import { GlobalStoreContext } from "../../components/StoreProvider";
import { ConfigStoreContext, GlobalStoreContext } from "../../components/StoreProvider";
import { TopBarRightBtn } from "../../components/TopBarRightBtn";
import { TopBarRoundBtn } from "../../components/TopBarRoundBtn";
import { Whiteboard } from "../../components/Whiteboard";
Expand Down Expand Up @@ -87,6 +87,7 @@ export const BigClassPage = observer<BigClassPageProps>(function BigClassPage()
const classRoomStore = useClassRoomStore(params.roomUUID, params.ownerUUID, recordingConfig);
const whiteboardStore = classRoomStore.whiteboardStore;
const globalStore = useContext(GlobalStoreContext);
const configStore = useContext(ConfigStoreContext);
const { confirm, ...exitConfirmModalProps } = useExitRoomConfirmModal(classRoomStore);

const [speakingJoiner, setSpeakingJoiner] = useState<User | undefined>(() =>
Expand Down Expand Up @@ -175,7 +176,7 @@ export const BigClassPage = observer<BigClassPageProps>(function BigClassPage()
right={renderTopBarRight()}
/>
<div className="realtime-content">
<Whiteboard whiteboardStore={whiteboardStore} />
<Whiteboard whiteboardStore={whiteboardStore} configStore={configStore} />
{renderRealtimePanel()}
</div>
<ExitRoomConfirm isCreator={classRoomStore.isCreator} {...exitConfirmModalProps} />
Expand Down
5 changes: 3 additions & 2 deletions web/flat-web/src/pages/OneToOnePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { useComputed } from "../../utils/mobx";
import { RouteNameType, RouteParams } from "../../utils/routes";
import { CloudStorageButton } from "../../components/CloudStorageButton";
import { AgoraCloudRecordBackgroundConfigItem } from "../../apiMiddleware/flatServer/agora";
import { GlobalStoreContext } from "../../components/StoreProvider";
import { ConfigStoreContext, GlobalStoreContext } from "../../components/StoreProvider";
import { runtime } from "../../utils/runtime";
import { useTranslation } from "react-i18next";

Expand Down Expand Up @@ -68,6 +68,7 @@ export const OneToOnePage = observer<OneToOnePageProps>(function OneToOnePage()
const classRoomStore = useClassRoomStore(params.roomUUID, params.ownerUUID, recordingConfig);
const whiteboardStore = classRoomStore.whiteboardStore;
const globalStore = useContext(GlobalStoreContext);
const configStore = useContext(ConfigStoreContext);
const { confirm, ...exitConfirmModalProps } = useExitRoomConfirmModal(classRoomStore);

const [isRealtimeSideOpen, openRealtimeSide] = useState(true);
Expand Down Expand Up @@ -130,7 +131,7 @@ export const OneToOnePage = observer<OneToOnePageProps>(function OneToOnePage()
right={renderTopBarRight()}
/>
<div className="one-to-one-realtime-content">
<Whiteboard whiteboardStore={whiteboardStore} />
<Whiteboard whiteboardStore={whiteboardStore} configStore={configStore} />
{renderRealtimePanel()}
</div>
<ExitRoomConfirm isCreator={classRoomStore.isCreator} {...exitConfirmModalProps} />
Expand Down
5 changes: 3 additions & 2 deletions web/flat-web/src/pages/SmallClassPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { RouteNameType, RouteParams } from "../../utils/routes";

import "./SmallClassPage.less";
import { CloudStorageButton } from "../../components/CloudStorageButton";
import { GlobalStoreContext } from "../../components/StoreProvider";
import { ConfigStoreContext, GlobalStoreContext } from "../../components/StoreProvider";
import { runtime } from "../../utils/runtime";
import { RtcChannelType } from "../../apiMiddleware/rtc/room";
import { useTranslation } from "react-i18next";
Expand Down Expand Up @@ -93,6 +93,7 @@ export const SmallClassPage = observer<SmallClassPageProps>(function SmallClassP
);
const whiteboardStore = classRoomStore.whiteboardStore;
const globalStore = useContext(GlobalStoreContext);
const configStore = useContext(ConfigStoreContext);
const { confirm, ...exitConfirmModalProps } = useExitRoomConfirmModal(classRoomStore);

const { room, phase } = whiteboardStore;
Expand Down Expand Up @@ -152,7 +153,7 @@ export const SmallClassPage = observer<SmallClassPageProps>(function SmallClassP
/>
{renderAvatars()}
<div className="realtime-content">
<Whiteboard whiteboardStore={whiteboardStore} />
<Whiteboard whiteboardStore={whiteboardStore} configStore={configStore} />
{renderRealtimePanel()}
</div>
<ExitRoomConfirm isCreator={classRoomStore.isCreator} {...exitConfirmModalProps} />
Expand Down

0 comments on commit 8f7ed14

Please sign in to comment.