Skip to content

Commit

Permalink
feat(whiteboard): add the resize EventListener event to change whiteb…
Browse files Browse the repository at this point in the history
…oard size (#941)
  • Loading branch information
Cheerego7 committed Sep 9, 2021
1 parent b656bc6 commit b4b9805
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
font-size: 16px;
// Windows 下菜单栏在窗口以内,需要分割
border-top: 0.5px #dbe1ea solid;
border-bottom: 0.5px solid #dbe1e9;
user-select: none;
&.isMac {
border-top: none;
Expand Down
2 changes: 1 addition & 1 deletion web/flat-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@netless/redo-undo": "^0.0.5",
"@netless/tool-box": "^0.1.5",
"@netless/video-js-plugin": "^0.3.6",
"@netless/window-manager": "0.1.55",
"@netless/window-manager": "^0.1.63-canary.1",
"@videojs/vhs-utils": "^2.3.0",
"@zip.js/zip.js": "^2.3.7",
"agora-rtc-sdk-ng": "^4.5.0",
Expand Down
2 changes: 0 additions & 2 deletions web/flat-web/src/components/RealtimePanel.less
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
width: @panel-width;
height: 100%;
position: relative;
padding-top: 8px;
border-left: 0.5px solid #dbe1e9;
}

.realtime-panel-video-slot {
Expand Down
52 changes: 51 additions & 1 deletion web/flat-web/src/components/Whiteboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const Whiteboard = observer<WhiteboardProps>(function Whiteboard({ whiteb
collectorContainer: collectorEl,
/* the containerSizeRatio config limit width and height ratio of windowManager
for make sure windowManager sync in whiteboard. */
containerSizeRatio: whiteboardStore.updateWhiteboardResize(),
containerSizeRatio: whiteboardStore.getWhiteboardRatio(),
collectorStyles: {
position: "absolute",
right: "10px",
Expand All @@ -48,6 +48,17 @@ export const Whiteboard = observer<WhiteboardProps>(function Whiteboard({ whiteb
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [whiteboardEl, collectorEl, room]);

useEffect(() => {
if (whiteboardEl) {
whiteboardOnResize();
window.addEventListener("resize", whiteboardOnResize);
}
return () => {
window.removeEventListener("resize", whiteboardOnResize);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [whiteboardEl]);

const bindWhiteboard = useCallback((ref: HTMLDivElement | null) => {
if (ref) {
setWhiteboardEl(ref);
Expand Down Expand Up @@ -86,6 +97,45 @@ export const Whiteboard = observer<WhiteboardProps>(function Whiteboard({ whiteb
[room],
);

const whiteboardOnResize = (): void => {
if (whiteboardEl) {
const whiteboardRatio = whiteboardStore.getWhiteboardRatio();

if (window.innerHeight < 600 || window.innerWidth < 800) {
whiteboardEl.style.minWidth = "550px";
whiteboardEl.style.minHeight = `${550 * whiteboardRatio}px`;
}

if (whiteboardStore.smallClassRatio === whiteboardRatio) {
const classRoomRightSideWidth = 304;
const classRoomTopBarHeight = 182;

const whiteboardWidth = Math.min(
window.innerWidth - classRoomRightSideWidth,
(window.innerHeight - classRoomTopBarHeight) / whiteboardRatio,
);

const whiteboardHeight = whiteboardWidth * whiteboardRatio;

whiteboardEl.style.width = `${whiteboardWidth}px`;
whiteboardEl.style.height = `${whiteboardHeight}px`;
} else {
const classRoomRightSideWidth = 304;
const classRoomTopBarHeight = 50;

const whiteboardWidth = Math.min(
window.innerWidth - classRoomRightSideWidth,
(window.innerHeight - classRoomTopBarHeight) / whiteboardRatio,
);

const whiteboardHeight = whiteboardWidth * whiteboardRatio;

whiteboardEl.style.width = `${whiteboardWidth}px`;
whiteboardEl.style.height = `${whiteboardHeight}px`;
}
}
};

return (
room && (
<div
Expand Down
13 changes: 10 additions & 3 deletions web/flat-web/src/pages/BigClassPage/BigClassPage.less
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
body {
background-color: #dfe1e5;
}

.realtime-container {
text-align: center;
}

.realtime-box {
width: 100%;
height: 100vh;
overflow: hidden;
display: flex;
display: inline-flex;
flex-direction: column;
background-color: #fff;

.container {
position: relative;
Expand Down
38 changes: 20 additions & 18 deletions web/flat-web/src/pages/BigClassPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,26 +171,28 @@ export const BigClassPage = observer<BigClassPageProps>(function BigClassPage()
}

return (
<div className="realtime-box">
<TopBar
isMac={runtime.isMac}
left={renderTopBarLeft()}
center={renderTopBarCenter()}
right={renderTopBarRight()}
/>
<div className="realtime-content">
<div className="container">
<ShareScreen shareScreenStore={shareScreenStore} />
<Whiteboard whiteboardStore={whiteboardStore} />
<div className="realtime-container">
<div className="realtime-box">
<TopBar
isMac={runtime.isMac}
left={renderTopBarLeft()}
center={renderTopBarCenter()}
right={renderTopBarRight()}
/>
<div className="realtime-content">
<div className="container">
<ShareScreen shareScreenStore={shareScreenStore} />
<Whiteboard whiteboardStore={whiteboardStore} />
</div>
{renderRealtimePanel()}
</div>
{renderRealtimePanel()}
<ExitRoomConfirm isCreator={classRoomStore.isCreator} {...exitConfirmModalProps} />
<RoomStatusStoppedModal
isCreator={classRoomStore.isCreator}
isRemoteLogin={classRoomStore.isRemoteLogin}
roomStatus={classRoomStore.roomStatus}
/>
</div>
<ExitRoomConfirm isCreator={classRoomStore.isCreator} {...exitConfirmModalProps} />
<RoomStatusStoppedModal
isCreator={classRoomStore.isCreator}
isRemoteLogin={classRoomStore.isRemoteLogin}
roomStatus={classRoomStore.roomStatus}
/>
</div>
);

Expand Down
13 changes: 10 additions & 3 deletions web/flat-web/src/pages/OneToOnePage/OneToOnePage.less
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
body {
background-color: #dfe1e5;
}

.one-to-one-realtime-container {
text-align: center;
}

.one-to-one-realtime-box {
width: 100%;
height: 100vh;
overflow: hidden;
display: flex;
display: inline-flex;
flex-direction: column;
background-color: #fff;

.container {
position: relative;
Expand Down
38 changes: 20 additions & 18 deletions web/flat-web/src/pages/OneToOnePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,28 @@ export const OneToOnePage = observer<OneToOnePageProps>(function OneToOnePage()
}

return (
<div className="one-to-one-realtime-box">
<TopBar
isMac={runtime.isMac}
left={renderTopBarLeft()}
center={renderTopBarCenter()}
right={renderTopBarRight()}
/>
<div className="one-to-one-realtime-content">
<div className="container">
<ShareScreen shareScreenStore={shareScreenStore} />
<Whiteboard whiteboardStore={whiteboardStore} />
<div className="one-to-one-realtime-container">
<div className="one-to-one-realtime-box">
<TopBar
isMac={runtime.isMac}
left={renderTopBarLeft()}
center={renderTopBarCenter()}
right={renderTopBarRight()}
/>
<div className="one-to-one-realtime-content">
<div className="container">
<ShareScreen shareScreenStore={shareScreenStore} />
<Whiteboard whiteboardStore={whiteboardStore} />
</div>
{renderRealtimePanel()}
</div>
{renderRealtimePanel()}
<ExitRoomConfirm isCreator={classRoomStore.isCreator} {...exitConfirmModalProps} />
<RoomStatusStoppedModal
isCreator={classRoomStore.isCreator}
isRemoteLogin={classRoomStore.isRemoteLogin}
roomStatus={classRoomStore.roomStatus}
/>
</div>
<ExitRoomConfirm isCreator={classRoomStore.isCreator} {...exitConfirmModalProps} />
<RoomStatusStoppedModal
isCreator={classRoomStore.isCreator}
isRemoteLogin={classRoomStore.isRemoteLogin}
roomStatus={classRoomStore.roomStatus}
/>
</div>
);

Expand Down
14 changes: 10 additions & 4 deletions web/flat-web/src/pages/SmallClassPage/SmallClassPage.less
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
body {
background-color: #dfe1e5;
}

.realtime-container {
text-align: center;
}

.realtime-box {
width: 100%;
height: 100vh;
overflow: hidden;
display: flex;
display: inline-flex;
flex-direction: column;
background-color: #fff;

.container {
position: relative;
Expand All @@ -23,7 +30,6 @@
height: 130px;
border-top: 0.5px #dbe1ea solid;
box-shadow: 0px 8px 24px 0px rgba(68, 78, 96, 0.08);
border-bottom: 0.5px solid #dbe1e9;

&::-webkit-scrollbar {
display: none;
Expand Down
40 changes: 21 additions & 19 deletions web/flat-web/src/pages/SmallClassPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,27 +150,29 @@ export const SmallClassPage = observer<SmallClassPageProps>(function SmallClassP
}

return (
<div className="realtime-box">
<TopBar
isMac={runtime.isMac}
left={renderTopBarLeft()}
center={renderTopBarCenter()}
right={renderTopBarRight()}
/>
{renderAvatars()}
<div className="realtime-content">
<div className="container">
<ShareScreen shareScreenStore={shareScreenStore} />
<Whiteboard whiteboardStore={whiteboardStore} />
<div className="realtime-container">
<div className="realtime-box">
<TopBar
isMac={runtime.isMac}
left={renderTopBarLeft()}
center={renderTopBarCenter()}
right={renderTopBarRight()}
/>
{renderAvatars()}
<div className="realtime-content">
<div className="container">
<ShareScreen shareScreenStore={shareScreenStore} />
<Whiteboard whiteboardStore={whiteboardStore} />
</div>
{renderRealtimePanel()}
</div>
{renderRealtimePanel()}
<ExitRoomConfirm isCreator={classRoomStore.isCreator} {...exitConfirmModalProps} />
<RoomStatusStoppedModal
isCreator={classRoomStore.isCreator}
isRemoteLogin={classRoomStore.isRemoteLogin}
roomStatus={classRoomStore.roomStatus}
/>
</div>
<ExitRoomConfirm isCreator={classRoomStore.isCreator} {...exitConfirmModalProps} />
<RoomStatusStoppedModal
isCreator={classRoomStore.isCreator}
isRemoteLogin={classRoomStore.isRemoteLogin}
roomStatus={classRoomStore.roomStatus}
/>
</div>
);

Expand Down
2 changes: 1 addition & 1 deletion web/flat-web/src/stores/WhiteboardStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class WhiteboardStore {
this.isFocusWindow = isFocus;
};

public updateWhiteboardResize = (): number => {
public getWhiteboardRatio = (): number => {
// the Ratio of whiteboard compute method is height / width.
if (this.roomType === RoomType.SmallClass) {
return this.smallClassRatio;
Expand Down
Loading

0 comments on commit b4b9805

Please sign in to comment.