Skip to content

Commit

Permalink
refactor(backend): improve join call events logic
Browse files Browse the repository at this point in the history
  • Loading branch information
neuodev committed Dec 2, 2024
1 parent 9a01806 commit 9bbbc92
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 221 deletions.
70 changes: 0 additions & 70 deletions apps/nova/src/components/Chat/MessageGroup.tsx

This file was deleted.

10 changes: 3 additions & 7 deletions apps/nova/src/components/UpcomingLessons/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ export const Content: React.FC<ContentProps> = ({ query }) => {
const canceled = useCallback(
(item: Lessons[0], tutor: ILesson.PopuldatedMember) => {
if (!item.lesson.canceledBy && !item.lesson.canceledBy) return null;
if (
item.lesson.canceledBy === tutor.userId ||
item.call.canceledBy === tutor.userId
)
return "tutor";
if (item.lesson.canceledBy === tutor.userId) return "tutor";
return "student";
},
[]
Expand Down Expand Up @@ -51,8 +47,8 @@ export const Content: React.FC<ContentProps> = ({ query }) => {
return (
<LessonCard
key={item.lesson.id}
start={item.call.start}
duration={item.call.duration}
start={item.lesson.start}
duration={item.lesson.duration}
onJoin={() => console.log("join")}
onCancel={() => console.log("canceled")}
onRebook={() => console.log("rebook")}
Expand Down
5 changes: 4 additions & 1 deletion packages/models/src/calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export class Calls {
callId,
userId,
tx,
}: WithOptionalTx<{ callId: number; userId: number }>): Promise<ICall.Member> {
}: WithOptionalTx<{
callId: number;
userId: number;
}>): Promise<ICall.Member> {
const rows = await this.builder(tx)
.members.insert({
call_id: callId,
Expand Down
12 changes: 6 additions & 6 deletions packages/models/tests/calls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ describe(nameof(Calls), () => {
expect(await calls.findCallMembers([call.id])).to.be.of.length(0);

const member = await calls.addMember({
call: call.id,
user: tutor.id,
callId: call.id,
userId: tutor.id,
});
expect(await calls.findCallMembers([call.id])).to.be.of.length(1);
expect(member.callId).to.be.eq(call.id);
Expand All @@ -44,15 +44,15 @@ describe(nameof(Calls), () => {
expect(await calls.findCallMembers([call.id])).to.be.of.length(0);

await calls.addMember({
call: call.id,
user: tutor.id,
callId: call.id,
userId: tutor.id,
});

expect(await calls.findCallMembers([call.id])).to.be.of.length(1);

await calls.removeMember({
call: call.id,
user: tutor.id,
callId: call.id,
userId: tutor.id,
});

expect(await calls.findCallMembers([call.id])).to.be.of.length(0);
Expand Down
4 changes: 2 additions & 2 deletions packages/models/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"strict": true,
"baseUrl": "./",
"skipLibCheck": true,
"module": "ESNext",
"module": "nodenext",
"declaration": true,
"declarationDir": "types",
"sourceMap": true,
"outDir": "dist",
"moduleResolution": "node",
"moduleResolution": "nodenext",
"allowSyntheticDefaultImports": true,
"emitDeclarationOnly": true,
"resolveJsonModule": true,
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ export type FindUserCallsApiResponse = {
calls: Self[];
members: Record<string, PopuldatedMember[]>;
};

export type Type = "lesson" | "interview";
14 changes: 10 additions & 4 deletions packages/types/src/wss.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IMessage, IRule, ITutor, Server } from "@/index";
import { IMessage, IRule, ITutor, Server, ICall } from "@/index";

/**
* Events emitted by the client
Expand Down Expand Up @@ -37,6 +37,9 @@ export enum ServerEvent {
MemberJoinedCall = "MemberJoinedCallId",
MemberLeftCall = "MemberLeftCallId",

/**
* @deprecated
*/
UserJoinedCall = "UserJoinedCall",
UserSharedScreen = "UserSharedScreen",
UserStatusChanged = "UserStatusChanged",
Expand Down Expand Up @@ -81,7 +84,10 @@ export type ClientEventsMap = {
[ClientEvent.ToggleCamera]: EventCallback<{ call: number; camera: boolean }>;
[ClientEvent.ToggleMic]: EventCallback<{ call: number; mic: boolean }>;
[ClientEvent.UserTyping]: EventCallback<{ roomId: number }>;
[ClientEvent.JoinCall]: EventCallback<{ callId: number }>;
[ClientEvent.JoinCall]: EventCallback<{
callId: number;
type: ICall.Type;
}>;
[ClientEvent.LeaveCall]: EventCallback<{ callId: number }>;
};

Expand All @@ -98,8 +104,8 @@ export type ServerEventsMap = {

[ServerEvent.UserJoinedCall]: EventCallback<{ peerId: string }>;

[ServerEvent.MemberJoinedCall]: EventCallback<{ memberId: number }>;
[ServerEvent.MemberLeftCall]: EventCallback<{ memberId: number }>;
[ServerEvent.MemberJoinedCall]: EventCallback<{ userId: number }>;
[ServerEvent.MemberLeftCall]: EventCallback<{ userId: number }>;

[ServerEvent.CameraToggled]: EventCallback<{ user: number; camera: boolean }>;
[ServerEvent.MicToggled]: EventCallback<{ user: number; mic: boolean }>;
Expand Down
1 change: 0 additions & 1 deletion services/server/fixtures/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export class Api {
static async forUser(role: IUser.Role) {
const email = faker.internet.email();
const password = faker.internet.password();
// NOTE: should be db.createUser
await db.user({ role, email, password });
return await Api.fromCredentials(email, password);
}
Expand Down
Loading

0 comments on commit 9bbbc92

Please sign in to comment.