Skip to content

Commit

Permalink
Merge pull request #316 from Jw705/refactor/240312-compression
Browse files Browse the repository at this point in the history
Refactor(#309): ํ™”์ดํŠธ๋ณด๋“œ ์ •๋ณด๋ฅผ ์••์ถ•ํ•ด์„œ ์ „์†กํ•˜๋„๋ก ๊ฐœ์„ 
  • Loading branch information
Jw705 authored Mar 18, 2024
2 parents b94c2d9 + 0707f47 commit 4a5363a
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 119 deletions.
2 changes: 1 addition & 1 deletion backend/src/lecture/dto/whiteboard-event.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export class WhiteboardEventDto {
objects: fabric.Object[];
objects: Uint8Array;

viewport: number[];

Expand Down
2 changes: 1 addition & 1 deletion backend/src/lecture/lecture.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class LectureService {

async saveWhiteBoardLog(lecture: Lecture, whiteboardEventDto: WhiteboardEventDto) {
const whiteboardLog = new this.whiteboardLogModel({
canvasJSON: whiteboardEventDto.canvasJSON,
objects: whiteboardEventDto.objects,
viewport: whiteboardEventDto.viewport,
eventTime: whiteboardEventDto.eventTime,
width: whiteboardEventDto.width,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/lecture/schema/whiteboard-log.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type WhiteBoardLogDocument = HydratedDocument<WhiteboardLog>;
@Schema()
export class WhiteboardLog {
@Prop({ required: true })
objects: fabric.Object[];
objects: Uint8Array;

@Prop({ required: true })
viewport: number[];
Expand Down
38 changes: 33 additions & 5 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dotenv": "^16.3.1",
"fabric": "^5.3.0",
"modernizr": "^3.13.0",
"pako": "^2.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.18.0",
Expand All @@ -23,6 +24,7 @@
},
"devDependencies": {
"@types/fabric": "^5.3.6",
"@types/pako": "^2.0.3",
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@typescript-eslint/eslint-plugin": "^6.0.0",
Expand Down
14 changes: 0 additions & 14 deletions frontend/public/dummy70.json

This file was deleted.

30 changes: 0 additions & 30 deletions frontend/public/reviewLecture.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,18 @@ const HeaderInstructorControls = ({ setLectureCode, setLectureTitle }: HeaderIns
offerToReceiveVideo: false
});
saveCanvasData(fabricCanvasRef!, canvasData, startTime);
const reducedCanvasData: object = {
//objects: new Uint8Array(), // Uint8Array ํ˜•ํƒœ์˜ ๋ฐ์ดํ„ฐ๋Š” ์„œ๋ฒ„๋กœ ์ „์†ก์‹œ ์˜ค๋ฅ˜๊ฐ€ ๋‚˜์„œ ์ผ๋‹จ ๋ณด๋‚ด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
viewport: canvasData.viewport,
eventTime: canvasData.eventTime,
width: canvasData.width,
height: canvasData.height
};
socketRef.current.emit("presenterOffer", {
whiteboard: canvasData,
socketId: socketRef.current.id,
roomId: roomid,
SDP: SDP
SDP: SDP,
whiteboard: reducedCanvasData // TODO: ํ˜„์žฌ whiteboard์˜ objects ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๋‚ด๋Š” ๊ฒฝ์šฐ ์„œ๋ฒ„์— SDP ๊ฐ’์ด ๋ˆ„๋ฝ๋˜๋Š” ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
});
pcRef.current.setLocalDescription(SDP);
getPresenterCandidate();
Expand Down Expand Up @@ -250,23 +257,14 @@ const HeaderInstructorControls = ({ setLectureCode, setLectureTitle }: HeaderIns
const onFrame = () => {
saveCanvasData(fabricCanvasRef!, canvasData, startTime).then(
([isCanvasDataChanged, isViewportChanged, isSizeChanged]) => {
// ์บ”๋ฒ„์Šค ๋‚ด๋ถ€ ๊ฐ์ฒด๊ฐ€ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ์—๋Š” oobjects๋ฅผ ์ œ์™ธํ•œ ๋‚˜๋จธ์ง€ ๋ฐ์ดํ„ฐ๋งŒ ์ „์†ก
if (!isCanvasDataChanged && (isViewportChanged || isSizeChanged)) {
const reducedCanvasData: ICanvasData = {
objects: [],
viewport: canvasData.viewport,
eventTime: canvasData.eventTime,
width: canvasData.width,
height: canvasData.width
};
submitData(reducedCanvasData);
} else if (isCanvasDataChanged || isViewportChanged || isSizeChanged) {
if (isCanvasDataChanged || isViewportChanged || isSizeChanged) {
// ์บ”๋ฒ„์Šค ๋‚ด๋ถ€ ๊ฐ์ฒด ๋ณ€ํ™” ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•œ canvasJSON ๋ฐ์ดํ„ฐ๋Š” ์ œ์™ธํ•˜๊ณ  ์ „์†ก
const reducedCanvasData: ICanvasData = {
objects: canvasData.objects,
viewport: canvasData.viewport,
eventTime: canvasData.eventTime,
width: canvasData.width,
height: canvasData.width
height: canvasData.height
};
submitData(reducedCanvasData);
}
Expand Down Expand Up @@ -323,7 +321,7 @@ const HeaderInstructorControls = ({ setLectureCode, setLectureTitle }: HeaderIns
};

let canvasData: ICanvasData = {
objects: [],
objects: new Uint8Array(),
viewport: [0, 0, 0, 0, 0, 0],
eventTime: 0,
width: 0,
Expand Down Expand Up @@ -361,15 +359,6 @@ const HeaderInstructorControls = ({ setLectureCode, setLectureTitle }: HeaderIns
}
});
setInstructorSocket(lectureSocketRef.current);

// ์ง€์—ฐ ์‹œ๊ฐ„ ์ฒดํฌ๋ฅผ ์œ„ํ•ด ํฐ ํฌ๊ธฐ์˜ ๋”๋ฏธ ๋ฐ์ดํ„ฐ๋ฅผ ํ™”์ดํŠธ๋ณด๋“œ์— ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค. ๊ฐœ์„ ์ด ๋๋‚˜๋ฉด ์ œ๊ฑฐ ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.
axios("./dummy70.json")
.then(({ data }) => {
fabricCanvasRef!.loadFromJSON(data.canvasJSON, () => {});
})
.catch((error) => {
console.log("ํ™”์ดํŠธ๋ณด๋“œ ๋ฐ์ดํ„ฐ ๋กœ๋”ฉ ์‹คํŒจ", error);
});
};
const handleServerError = (err: any) => {
console.error(err.message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import calcNormalizedVolume from "@/utils/calcNormalizedVolume";
import selectedSpeakerState from "@/stores/stateSelectedSpeaker";
import speakerVolumeState from "@/stores/stateSpeakerVolume";
import micVolumeState from "@/stores/stateMicVolume";
import participantCavasInstanceState from "@/stores/stateParticipantCanvasInstance";
import participantCanvasInstanceState from "@/stores/stateParticipantCanvasInstance";
import participantSocketRefState from "@/stores/stateParticipantSocketRef";

interface HeaderParticipantControlsProps {
Expand All @@ -36,7 +36,7 @@ const HeaderParticipantControls = ({ setLectureCode, setLectureTitle }: HeaderPa

const selectedSpeaker = useRecoilValue(selectedSpeakerState);
const speakerVolume = useRecoilValue(speakerVolumeState);
const fabricCanvasRef = useRecoilValue(participantCavasInstanceState);
const fabricCanvasRef = useRecoilValue(participantCanvasInstanceState);
const setSpeakerVolume = useSetRecoilState(speakerVolumeState);
const setMicVolumeState = useSetRecoilState(micVolumeState);
const setParticipantSocket = useSetRecoilState(participantSocketRefState);
Expand Down Expand Up @@ -93,11 +93,6 @@ const HeaderParticipantControls = ({ setLectureCode, setLectureTitle }: HeaderPa
(audioContextRef.current as any).setSinkId(selectedSpeaker);
}, [selectedSpeaker]);

/* ------------------------------------------------------------------------------- */
// ํ™”์ดํŠธ๋ณด๋“œ ์ง€์—ฐ ์‹œ๊ฐ„ ์ฒดํฌ๋ฅผ ์œ„ํ•ด ์ž„์‹œ๋กœ ์ถ”๊ฐ€ํ•œ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค. ์ถ”ํ›„ ์‚ญ์ œ๋  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.
let startTime = Date.now();
/* ------------------------------------------------------------------------------- */

const enterLecture = async () => {
await checkAuth();
await initConnection();
Expand All @@ -122,7 +117,7 @@ const HeaderParticipantControls = ({ setLectureCode, setLectureTitle }: HeaderPa
};

let canvasData: ICanvasData = {
objects: [],
objects: new Uint8Array(),
viewport: [1, 0, 0, 1, 0, 0],
eventTime: 0,
width: 0,
Expand Down Expand Up @@ -272,8 +267,7 @@ const HeaderParticipantControls = ({ setLectureCode, setLectureTitle }: HeaderPa

const handleServerAnswer = (data: any) => {
if (!pcRef.current) return;
// const startTime = new Date(data.startTime).getTime();
startTime = new Date(data.startTime).getTime();
const startTime = new Date(data.startTime).getTime();
const updateElapsedTime = () => {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
setElapsedTime(elapsedTime);
Expand All @@ -284,8 +278,7 @@ const HeaderParticipantControls = ({ setLectureCode, setLectureTitle }: HeaderPa
loadCanvasData({
fabricCanvas: fabricCanvasRef!,
currentData: canvasData,
newData: data.whiteboard,
debugData: {}
newData: data.whiteboard
});
canvasData = data.whiteboard;
pcRef.current.setRemoteDescription(data.SDP);
Expand All @@ -299,12 +292,10 @@ const HeaderParticipantControls = ({ setLectureCode, setLectureTitle }: HeaderPa
showToast({ message: "์„œ๋ฒ„ ์—ฐ๊ฒฐ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค", type: "alert" });
};
const handleWhiteboardUpdate = (data: any) => {
const debugData = { startTime: startTime, arriveTime: Date.now() };
loadCanvasData({
fabricCanvas: fabricCanvasRef!,
currentData: canvasData,
newData: data.content,
debugData: debugData
newData: data.content
});
canvasData = data.content;
};
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/Participant/Participant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useSetRecoilState, useRecoilValue } from "recoil";
import { fabric } from "fabric";

import Header from "@/components/Header/Header";
import participantCavasInstanceState from "@/stores/stateParticipantCanvasInstance";
import participantCanvasInstanceState from "@/stores/stateParticipantCanvasInstance";
import CloseIcon from "@/assets/svgs/close.svg?react";
import QuestionIcon from "@/assets/svgs/whiteboard/question.svg?react";
import LogToggleButton from "@/components/Button/LogToggleButton";
Expand All @@ -13,7 +13,7 @@ import isQuestionLogOpenState from "@/stores/stateIsQuestionLogOpen";

const Participant = () => {
const canvasContainerRef = useRef<HTMLDivElement>(null);
const setCanvas = useSetRecoilState(participantCavasInstanceState);
const setCanvas = useSetRecoilState(participantCanvasInstanceState);
const canvasRef = useRef<HTMLCanvasElement>(null);
const isQuestionLogOpen = useRecoilValue(isQuestionLogOpenState);
useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Review/Review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Review = () => {
const lectureId = new URLSearchParams(useLocation().search).get("id") || "nodata";
let startTime = Date.now();
let canvasData: ICanvasData = {
objects: [],
objects: new Uint8Array(0),
viewport: [0, 0, 0, 0, 0, 0],
eventTime: 0,
width: 0,
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/stores/stateParticipantCanvasInstance.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { atom } from "recoil";
import { fabric } from "fabric";

const participantCavasInstanceState = atom<fabric.Canvas | null>({
key: "participantCavasInstanceState",
const participantCanvasInstanceState = atom<fabric.Canvas | null>({
key: "participantCanvasInstanceState",
default: null,
dangerouslyAllowMutability: true
});

export default participantCavasInstanceState;
export default participantCanvasInstanceState;
Loading

0 comments on commit 4a5363a

Please sign in to comment.