Skip to content

Commit

Permalink
refactor: calls table and corresponding tables have been dropped; cal…
Browse files Browse the repository at this point in the history
…l is replaced with session_id.
  • Loading branch information
mmoehabb committed Dec 24, 2024
1 parent bcf8d6f commit 674e5aa
Show file tree
Hide file tree
Showing 75 changed files with 804 additions and 1,323 deletions.
2 changes: 1 addition & 1 deletion apps/nova/src/components/Call/GhostView.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion apps/nova/src/components/Interviews/Interview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const Interview: React.FC<{

<div className="flex flex-row gap-2 mt-4">
{upcoming ? (
<Link to={Route.Call.replace(":id", interview.ids.call.toString())}>
<Link to={Route.Call.replace(":id", interview.ids.session)}>
<Button size={sm ? ButtonSize.Small : ButtonSize.Tiny}>
{!started
? intl.formatMessage(
Expand Down
2 changes: 1 addition & 1 deletion apps/nova/src/components/Lessons/Lesson.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const Lesson: React.FC<

<div className="flex flex-row gap-2 mt-4">
{upcoming ? (
<Link to={Route.Call.replace(":id", lesson.callId.toString())}>
<Link to={Route.Call.replace(":id", lesson.sessionId)}>
<Button size={sm ? ButtonSize.Small : ButtonSize.Tiny}>
{inprogress
? intl("page.lessons.lesson.join.inprogress", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {
} from "@litespace/luna/Button";
import { asFullAssetUrl } from "@litespace/luna/backend";
import { useFormatMessage } from "@litespace/luna/hooks/intl";
import { ICall } from "@litespace/types";
import { ISession } from "@litespace/types";
import React from "react";
import { Link } from "react-router-dom";
import { Route } from "@/types/routes";

const PendingInterview: React.FC<{
interviewer: ICall.PopuldatedMember;
call: ICall.Self;
}> = ({ interviewer, call }) => {
interviewer: ISession.PopuldatedMember;
session: ISession.Self;
}> = ({ interviewer, session }) => {
const intl = useFormatMessage();
return (
<div>
Expand Down Expand Up @@ -57,7 +57,7 @@ const PendingInterview: React.FC<{
</p>

<div className="flex flex-row gap-4 mt-6">
<Link to={Route.Call.replace(":id", call.id.toString())}>
<Link to={Route.Call.replace(":id", session.sessionId)}>
<Button
size={ButtonSize.Small}
type={ButtonType.Main}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { destructureInterviewStatus } from "@litespace/sol/interview";
import { ICall, IInterview } from "@litespace/types";
import { ISession, IInterview } 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;
call: ICall.Self;
members: ICall.PopuldatedMember[];
}> = ({ interview, call, members }) => {
session: ISession.Self;
members: ISession.PopuldatedMember[];
}> = ({ interview, session, members }) => {
// todo: handle canceled and rejected
const { pending, passed, rejected, canceled } = useMemo(
() => destructureInterviewStatus(interview.status),
Expand All @@ -25,7 +25,7 @@ const ScheduledInterview: React.FC<{
return (
<div>
{pending && interviewer ? (
<PendingInterview interviewer={interviewer} call={call} />
<PendingInterview interviewer={interviewer} session={session} />
) : passed && interviewer ? (
<PassedInterview
feedback={interview.feedback.interviewer}
Expand Down
16 changes: 8 additions & 8 deletions apps/nova/src/hooks/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useCallback, useEffect, useState, useRef } from "react";
import { isPermissionDenied, safe } from "@/lib/error";
import { MediaConnection } from "peerjs";
import peer from "@/lib/peer";
import { Wss } from "@litespace/types";
import { ISession, Wss } from "@litespace/types";
import hark from "hark";
import { useToast } from "@litespace/luna/Toast";
import { useFormatMessage } from "@litespace/luna/hooks/intl";
Expand Down Expand Up @@ -235,7 +235,7 @@ function useStreamState(stream: MediaStream | null) {

export function useCallEvents(
stream: MediaStream | null,
call: number | null,
session: ISession.Id | null,
mate?: number
) {
const [mateVideo, setMateVideo] = useState<boolean>(false);
Expand All @@ -245,18 +245,18 @@ export function useCallEvents(

const notifyCameraToggle = useCallback(
(camera: boolean) => {
if (!call || !socket) return;
socket.emit(Wss.ClientEvent.ToggleCamera, { call, camera });
if (!session || !socket) return;
socket.emit(Wss.ClientEvent.ToggleCamera, { session, camera });
},
[call, socket]
[session, socket]
);

const notifyMicToggle = useCallback(
(mic: boolean) => {
if (!call || !socket) return;
socket.emit(Wss.ClientEvent.ToggleMic, { call, mic });
if (!session || !socket) return;
socket.emit(Wss.ClientEvent.ToggleMic, { session, mic });
},
[call, socket]
[session, socket]
);

const onCameraToggle = useCallback(
Expand Down
38 changes: 16 additions & 22 deletions apps/nova/src/pages/Call.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import cn from "classnames";
// import Messages from "@/components/Chat/Messages";
import { orNull, orUndefined } from "@litespace/sol/utils";
import {
useCallMembers,
useSessionMembers,
// useCall,
useCallV2,
useFindCallRoomById,
useSessionV2,
useFindSessionRoomById,
useFullScreen,
usePeerIds,
} from "@litespace/headless/calls";
} from "@litespace/headless/sessions";
import { useDisplayRecorder } from "@litespace/headless/recorder";
import { isGhost } from "@/lib/ghost";
import CallView, { CallViewProps } from "@/components/Call/CallView";
Expand All @@ -32,37 +32,31 @@ import Video from "@litespace/assets/Video";
import Microphone from "@litespace/assets/Microphone";
import VideoSlash from "@litespace/assets/VideoSlash";
import MicrophoneSlash from "@litespace/assets/MicrophoneSlash";
import { ICall } from "@litespace/types";
import { useUser } from "@litespace/headless/context/user";
import { ISession } from "@litespace/types";
// import GhostView from "@/components/Call/GhostView";

const Call: React.FC = () => {
const { user } = useUser();
// const chat = useRender();
// const intl = useFormatMessage();
// const mediaQueries = useMediaQueries();
const { id, type } = useParams<{ id: string; type: ICall.Type }>();
const { id } = useParams<{ id: ISession.Id }>();
// const { isFullScreen, toggleFullScreen, ref } = useFullScreen();

const callId = useMemo(() => {
const call = Number(id);
if (!id || Number.isNaN(call)) return null;
return call;
const { sessionId } = useMemo(() => {
return { sessionId: id || null };
}, [id]);

const ctype = useMemo(() => {
if (type != "lesson" && type != "interview") return null;
return type;
}, [type]);

const callRoom = useFindCallRoomById(!isGhost ? callId : null);
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 = useCallMembers(callId, ctype);
const members = useSessionMembers(sessionId);
useEffect(() => console.log("In App members: ", members), [members]);

// const messages = useMemo(
Expand Down Expand Up @@ -127,17 +121,17 @@ const Call: React.FC = () => {
const peers = usePeerIds(
useMemo(
() => ({
callId,
sessionId,
isGhost,
mateUserId: orNull(mateInfo?.id),
role: orNull(user?.role),
disableGhost: false,
}),
[callId, mateInfo?.id, user?.role]
[sessionId, mateInfo?.id, user?.role]
)
);

const onCloseCall = useCallback(() => {
const onCloseSession = useCallback(() => {
// peers.ghost.refetch();
// peers.tutor.refetch();
}, []);
Expand All @@ -152,16 +146,16 @@ const Call: React.FC = () => {
});
*/

const { userMedia, mateStream, mateScreenStream, ghostStreams } = useCallV2(
const { userMedia, mateStream, mateScreenStream, ghostStreams } = useSessionV2(
useMemo(
() => ({
isGhost,
ghostPeerId: orNull(peers.ghost.data),
tutorPeerId: orNull(peers.tutor.data),
userId: orNull(user?.id),
onCloseCall,
onCloseSession,
}),
[onCloseCall, peers.ghost.data, peers.tutor.data, user?.id]
[onCloseSession, peers.ghost.data, peers.tutor.data, user?.id]
)
);

Expand Down
6 changes: 3 additions & 3 deletions packages/atlas/src/atlas.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { User } from "@/user";
import { Auth } from "@/auth";
import { Backend } from "@litespace/types";
import { Call } from "@/call";
import { Session } from "@/session";
import { Plan } from "@/plan";
import { Coupon } from "@/coupon";
import { Invite } from "@/invite";
Expand All @@ -23,7 +23,7 @@ import { Peer } from "@/peer";
export class Atlas {
public readonly user: User;
public readonly auth: Auth;
public readonly call: Call;
public readonly session: Session;
public readonly plan: Plan;
public readonly coupon: Coupon;
public readonly invite: Invite;
Expand All @@ -44,7 +44,7 @@ export class Atlas {
constructor(backend: Backend, token: AuthToken | null) {
this.user = new User(backend, token);
this.auth = new Auth(backend, token);
this.call = new Call(backend, token);
this.session = new Session(backend, token);
this.plan = new Plan(backend, token);
this.coupon = new Coupon(backend, token);
this.invite = new Invite(backend, token);
Expand Down
19 changes: 0 additions & 19 deletions packages/atlas/src/call.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/atlas/src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export class Chat extends Base {
return await this.get({ route: `/api/v1/chat/room/members/${room}` });
}

async findCallRoom(call: number): Promise<IRoom.FindCallRoomApiResponse> {
return await this.get({ route: `/api/v1/chat/room/call/${call}` });
async findSessionRoom(session: string): Promise<IRoom.FindSessionRoomApiResponse> {
return await this.get({ route: `/api/v1/chat/room/session/${session}` });
}

async updateRoom(
Expand Down
12 changes: 12 additions & 0 deletions packages/atlas/src/session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Base } from "@/base";
import { ISession } from "@litespace/types";

export class Session extends Base {
async findUserSessions(userId: number): Promise<ISession.FindUserSessionsApiResponse> {
return await this.get({ route: `/api/v1/session/list/user/${userId}` });
}

async findSessionMembers(sessionId: string): Promise<ISession.FindSessionMembersApiResponse> {
return await this.get({ route: `/api/v1/session/${sessionId}/members` });
}
}
5 changes: 1 addition & 4 deletions packages/auth/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { users } from "@litespace/models";
import { safe } from "@litespace/sol/error";
import { asGhost } from "@litespace/sol/ghost";
import { isAdmin } from "@/authorization";
import { IUser } from "@litespace/types";

export function authMiddleware({
jwtSecret,
Expand All @@ -24,9 +23,7 @@ export function authMiddleware({
if (type === "Basic") {
const data = Buffer.from(token, "base64").toString("utf-8");
const [username, password] = data.split(":");
const call = Number(username);
const valid = !Number.isNaN(call) && password === ghostPassword;
if (valid) req.user = asGhost(call);
if (password === ghostPassword) req.user = asGhost(username);
}

if (type === "Bearer") {
Expand Down
4 changes: 2 additions & 2 deletions packages/headless/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"./topic": "./dist/topic.js",
"./query": "./dist/query.js",
"./constants": "./dist/constants/index.js",
"./calls": "./dist/calls.js",
"./sessions": "./dist/sessions.js",
"./invoices": "./dist/invoices.js",
"./lessons": "./dist/lessons.js",
"./interviews": "./dist/interviews.js",
Expand All @@ -47,7 +47,7 @@
"./rating": "./dist/rating.js",
"./query": "./dist/query.js",
"./constants": "./dist/constants/index.js",
"./calls": "./dist/calls.js",
"./sessions": "./dist/sessions.js",
"./interviews": "./dist/interviews.js",
"./invoices": "./dist/invoices.js",
"./lessons": "./dist/lessons.js",
Expand Down
Loading

0 comments on commit 674e5aa

Please sign in to comment.