From dd440c6b0fe1a4d2c201406a873865be119cd751 Mon Sep 17 00:00:00 2001 From: "M. E. Abdelsalam" Date: Tue, 24 Dec 2024 22:17:18 +0200 Subject: [PATCH 1/2] refactor: calls table and corresponding tables have been dropped; call is replaced with session_id. --- apps/nova/src/components/Call/GhostView.tsx | 2 +- .../src/components/Interviews/Interview.tsx | 2 +- apps/nova/src/components/Lessons/Lesson.tsx | 2 +- .../PendingInterview/index.tsx | 10 +- .../Interview/ScheduledInterview/index.tsx | 10 +- apps/nova/src/hooks/call.ts | 16 +- apps/nova/src/pages/Call.tsx | 38 +-- packages/atlas/src/atlas.ts | 6 +- packages/atlas/src/call.ts | 19 -- packages/atlas/src/chat.ts | 4 +- packages/atlas/src/session.ts | 12 + packages/auth/src/middleware.ts | 5 +- packages/headless/package.json | 4 +- .../headless/src/{calls.ts => sessions.ts} | 132 ++++---- packages/models/fixtures/db.ts | 13 +- .../models/migrations/1716146586880_setup.js | 22 +- packages/models/scripts/seed.ts | 23 +- packages/models/src/cache/call.ts | 68 ---- packages/models/src/cache/index.ts | 6 +- packages/models/src/cache/peer.ts | 16 +- packages/models/src/cache/session.ts | 70 ++++ packages/models/src/calls.ts | 303 ------------------ packages/models/src/index.ts | 1 - packages/models/src/interviews.ts | 55 +++- packages/models/src/lessons.ts | 68 ++-- packages/models/src/lib/utils.ts | 12 + packages/models/tests/cache/call.test.ts | 62 ---- packages/models/tests/cache/peer.test.ts | 20 +- packages/models/tests/cache/session.test.ts | 69 ++++ packages/models/tests/calls.test.ts | 137 -------- packages/models/tests/lessons.test.ts | 2 +- packages/sol/package.json | 11 +- packages/sol/src/ghost.ts | 8 +- packages/sol/src/index.ts | 1 + packages/sol/src/session.ts | 12 + packages/types/src/api.ts | 2 +- packages/types/src/call.ts | 79 ----- packages/types/src/index.ts | 2 +- packages/types/src/interview.ts | 19 +- packages/types/src/lesson.ts | 8 +- packages/types/src/peer.ts | 6 +- packages/types/src/room.ts | 2 +- packages/types/src/session.ts | 37 +++ packages/types/src/user.ts | 2 +- packages/types/src/wss.ts | 32 +- services/server/fixtures/db.ts | 14 +- services/server/fixtures/shared.ts | 3 - services/server/fixtures/wss.ts | 10 +- services/server/src/handlers/call.ts | 67 ---- services/server/src/handlers/chat.ts | 27 +- services/server/src/handlers/interview.ts | 8 +- services/server/src/handlers/invoice.ts | 2 - services/server/src/handlers/lesson.ts | 8 +- services/server/src/handlers/peer.ts | 22 +- services/server/src/handlers/session.ts | 67 ++++ services/server/src/index.ts | 2 +- services/server/src/lib/error.ts | 2 +- .../server/src/lib/{call.ts => session.ts} | 22 +- services/server/src/lib/utils.ts | 5 - .../server/src/middleware/accessControl.ts | 6 +- services/server/src/routes/call.ts | 9 - services/server/src/routes/chat.ts | 2 +- services/server/src/routes/index.ts | 4 +- services/server/src/routes/session.ts | 9 + services/server/src/validation/utils.ts | 2 + .../server/src/wss/handlers/connection.ts | 37 +-- services/server/src/wss/handlers/index.ts | 6 +- .../server/src/wss/handlers/inputDevices.ts | 14 +- services/server/src/wss/handlers/peer.ts | 28 +- services/server/src/wss/handlers/session.ts | 100 ++++++ services/server/src/wss/utils.ts | 4 +- services/server/tests/api/call.test.ts | 66 ---- services/server/tests/api/user.test.ts | 3 +- services/server/tests/wss/call.test.ts | 24 +- 74 files changed, 804 insertions(+), 1199 deletions(-) delete mode 100644 packages/atlas/src/call.ts create mode 100644 packages/atlas/src/session.ts rename packages/headless/src/{calls.ts => sessions.ts} (90%) delete mode 100644 packages/models/src/cache/call.ts create mode 100644 packages/models/src/cache/session.ts delete mode 100644 packages/models/src/calls.ts create mode 100644 packages/models/src/lib/utils.ts delete mode 100644 packages/models/tests/cache/call.test.ts create mode 100644 packages/models/tests/cache/session.test.ts delete mode 100644 packages/models/tests/calls.test.ts create mode 100644 packages/sol/src/session.ts delete mode 100644 packages/types/src/call.ts create mode 100644 packages/types/src/session.ts delete mode 100644 services/server/src/handlers/call.ts create mode 100644 services/server/src/handlers/session.ts rename services/server/src/lib/{call.ts => session.ts} (83%) delete mode 100644 services/server/src/lib/utils.ts delete mode 100644 services/server/src/routes/call.ts create mode 100644 services/server/src/routes/session.ts create mode 100644 services/server/src/wss/handlers/session.ts delete mode 100644 services/server/tests/api/call.test.ts diff --git a/apps/nova/src/components/Call/GhostView.tsx b/apps/nova/src/components/Call/GhostView.tsx index 292edb45..5b5b1ef7 100644 --- a/apps/nova/src/components/Call/GhostView.tsx +++ b/apps/nova/src/components/Call/GhostView.tsx @@ -1,6 +1,6 @@ import { useFormatMessage } from "@litespace/luna/hooks/intl"; import { Typography } from "@litespace/luna/Typography"; -import { RemoteStream } from "@litespace/headless/calls"; +import { RemoteStream } from "@litespace/headless/sessions"; import { isEmpty } from "lodash"; import React from "react"; import UserMedia from "@/components/Call/UserMedia"; diff --git a/apps/nova/src/components/Interviews/Interview.tsx b/apps/nova/src/components/Interviews/Interview.tsx index f9382a42..d72077f9 100644 --- a/apps/nova/src/components/Interviews/Interview.tsx +++ b/apps/nova/src/components/Interviews/Interview.tsx @@ -97,7 +97,7 @@ const Interview: React.FC<{
{upcoming ? ( - + diff --git a/apps/nova/src/components/TutorOnboardingSteps/Interview/ScheduledInterview/index.tsx b/apps/nova/src/components/TutorOnboardingSteps/Interview/ScheduledInterview/index.tsx index b1cc49de..25cc8b55 100644 --- a/apps/nova/src/components/TutorOnboardingSteps/Interview/ScheduledInterview/index.tsx +++ b/apps/nova/src/components/TutorOnboardingSteps/Interview/ScheduledInterview/index.tsx @@ -1,14 +1,13 @@ import { destructureInterviewStatus } from "@litespace/sol/interview"; -import { ISession, IInterview } from "@litespace/types"; +import { IInterview, IRoom } from "@litespace/types"; import React, { useMemo } from "react"; import PendingInterview from "@/components/TutorOnboardingSteps/Interview/ScheduledInterview/PendingInterview"; import PassedInterview from "@/components/TutorOnboardingSteps/Interview/ScheduledInterview/PassedInterview"; const ScheduledInterview: React.FC<{ interview: IInterview.Self; - session: ISession.Self; - members: ISession.PopuldatedMember[]; -}> = ({ interview, session, members }) => { + members: IRoom.PopulatedMember[]; +}> = ({ interview, members }) => { // todo: handle canceled and rejected const { pending, passed, rejected, canceled } = useMemo( () => destructureInterviewStatus(interview.status), @@ -17,7 +16,7 @@ const ScheduledInterview: React.FC<{ const interviewer = useMemo(() => { return ( - members.find((member) => member.userId === interview.ids.interviewer) || + members.find((member) => member.id === interview.ids.interviewer) || null ); }, [interview.ids.interviewer, members]); @@ -25,7 +24,7 @@ const ScheduledInterview: React.FC<{ return (
{pending && interviewer ? ( - + ) : passed && interviewer ? ( | null; }> = ({ current }) => { // const onScheduleSuccess = useCallback(() => { diff --git a/apps/nova/src/components/TutorOnboardingSteps/index.tsx b/apps/nova/src/components/TutorOnboardingSteps/index.tsx index 86af132e..a45ce790 100644 --- a/apps/nova/src/components/TutorOnboardingSteps/index.tsx +++ b/apps/nova/src/components/TutorOnboardingSteps/index.tsx @@ -6,11 +6,10 @@ import { Element, IInterview } from "@litespace/types"; const TutorOnboardingSteps: React.FC<{ step: number; - interviews: IInterview.FindPagedInterviewsProps; current: Element | null; -}> = ({ step, interviews, current }) => { +}> = ({ step, current }) => { if (step === TutorOnboardingStep.Interview) - return ; + return ; if (step === TutorOnboardingStep.Media) return ; if (step === TutorOnboardingStep.Profile) return "todo"; return null; diff --git a/apps/nova/src/pages/Call.tsx b/apps/nova/src/pages/Call.tsx index 99951434..30308278 100644 --- a/apps/nova/src/pages/Call.tsx +++ b/apps/nova/src/pages/Call.tsx @@ -9,19 +9,17 @@ import { // import { useMediaQueries } from "@litespace/luna/hooks/media"; // import { useRender } from "@litespace/luna/hooks/common"; // import { useFormatMessage } from "@litespace/luna/hooks/intl"; -import { useParams } from "react-router-dom"; import cn from "classnames"; // import { useFullScreen } from "@/hooks/call"; // import Media from "@/components/Call/Media"; // import Messages from "@/components/Chat/Messages"; import { orNull, orUndefined } from "@litespace/sol/utils"; import { - useSessionMembers, - // useCall, + //useSessionMembers, + //usePeerIds, useSessionV2, - useFindSessionRoomById, + //useFindSessionRoomById, useFullScreen, - usePeerIds, } from "@litespace/headless/sessions"; import { useDisplayRecorder } from "@litespace/headless/recorder"; import { isGhost } from "@/lib/ghost"; @@ -33,7 +31,6 @@ import Microphone from "@litespace/assets/Microphone"; import VideoSlash from "@litespace/assets/VideoSlash"; import MicrophoneSlash from "@litespace/assets/MicrophoneSlash"; import { useUser } from "@litespace/headless/context/user"; -import { ISession } from "@litespace/types"; // import GhostView from "@/components/Call/GhostView"; const Call: React.FC = () => { @@ -41,23 +38,10 @@ const Call: React.FC = () => { // const chat = useRender(); // const intl = useFormatMessage(); // const mediaQueries = useMediaQueries(); - const { id } = useParams<{ id: ISession.Id }>(); // const { isFullScreen, toggleFullScreen, ref } = useFullScreen(); - const { sessionId } = useMemo(() => { - return { sessionId: id || null }; - }, [id]); - - - const callRoom = useFindSessionRoomById(!isGhost ? sessionId : null); - - const mateInfo = useMemo(() => { - if (!callRoom.data) return; - return callRoom.data.members.find((member) => member.id !== user?.id); - }, [callRoom.data, user?.id]); - - const members = useSessionMembers(sessionId); - useEffect(() => console.log("In App members: ", members), [members]); + //const members = useSessionMembers(sessionId); + //useEffect(() => console.log("In App members: ", members), [members]); // const messages = useMemo( // () => @@ -118,6 +102,7 @@ const Call: React.FC = () => { const fullScreen = useFullScreen(); + /* const peers = usePeerIds( useMemo( () => ({ @@ -130,6 +115,7 @@ const Call: React.FC = () => { [sessionId, mateInfo?.id, user?.role] ) ); + */ const onCloseSession = useCallback(() => { // peers.ghost.refetch(); @@ -150,12 +136,12 @@ const Call: React.FC = () => { useMemo( () => ({ isGhost, - ghostPeerId: orNull(peers.ghost.data), - tutorPeerId: orNull(peers.tutor.data), + ghostPeerId: orNull("ghost"), // TODO: pass peers.ghost.data + tutorPeerId: orNull("ghost"), // TODO: pass peers.tutor.data userId: orNull(user?.id), onCloseSession, }), - [onCloseSession, peers.ghost.data, peers.tutor.data, user?.id] + [onCloseSession, user?.id] ) ); @@ -177,7 +163,7 @@ const Call: React.FC = () => { screen: mateScreenStream, }, speaking: true, - name: orUndefined(mateInfo?.name), + name: undefined // orUndefined(mateInfo?.name), }, fullScreen: { enabled: fullScreen.enabled, @@ -189,7 +175,6 @@ const Call: React.FC = () => { fullScreen.enabled, fullScreen.exit, fullScreen.start, - mateInfo?.name, mateScreenStream, mateStream, user?.name, @@ -302,12 +287,14 @@ const Call: React.FC = () => { /* * TODO: replace this by members views */ + /*

Joined members

{members.map((m) => ( ))}
+ */ } {/*