Skip to content

Commit 33f6ae7

Browse files
committed
refactor: common types
1 parent 829980f commit 33f6ae7

9 files changed

Lines changed: 381 additions & 212 deletions

File tree

frontend/src/composables/useMeetingPreviewPresence.ts

Lines changed: 16 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,15 @@ import { createResource } from "frappe-ui";
22
import { type Socket, io } from "socket.io-client";
33
import { computed, onUnmounted, readonly, ref } from "vue";
44
import { session } from "../data/session";
5-
import type { FrappeRequestError, ParticipantPreview } from "../types";
6-
7-
interface TokenResponse {
8-
auth_token?: string;
9-
sfu_url?: string;
10-
sfu_port?: number;
11-
error?: string;
12-
}
13-
14-
interface ParticipantResponse {
15-
success: boolean;
16-
participants?: Array<{
17-
id: string;
18-
user_id?: string;
19-
info: {
20-
name?: string;
21-
userId?: string;
22-
avatar?: string;
23-
audio_enabled?: boolean;
24-
video_enabled?: boolean;
25-
is_guest?: boolean;
26-
};
27-
}>;
28-
error?: string;
29-
}
30-
31-
interface JoinResponse {
32-
success: boolean;
33-
error?: string;
34-
}
35-
36-
interface ParticipantJoinedData {
37-
roomId: string;
38-
participantId: string;
39-
userData: {
40-
name?: string;
41-
userId: string;
42-
avatar?: string;
43-
audio_enabled: boolean;
44-
video_enabled: boolean;
45-
};
46-
}
47-
48-
interface ParticipantLeftData {
49-
roomId: string;
50-
participantId: string;
51-
}
5+
import type {
6+
FrappeRequestError,
7+
ParticipantJoinedEvent,
8+
ParticipantLeftEvent,
9+
ParticipantPreview,
10+
PresenceJoinResponse,
11+
PresenceParticipantsResponse,
12+
PresenceTokenResponse,
13+
} from "../types";
5214

5315
export function useMeetingPreviewPresence(meetingId: string) {
5416
const participants = ref<ParticipantPreview[]>([]);
@@ -59,7 +21,7 @@ export function useMeetingPreviewPresence(meetingId: string) {
5921
url: "meet.api.meeting.get_sfu_presence_preview_token",
6022
params: { meeting_id: meetingId },
6123
auto: false,
62-
onSuccess(data: TokenResponse) {
24+
onSuccess(data: PresenceTokenResponse) {
6325
if (data && (data.auth_token || data.sfu_url)) {
6426
connectToSFU(data);
6527
} else {
@@ -77,7 +39,7 @@ export function useMeetingPreviewPresence(meetingId: string) {
7739
fetchPresenceToken.fetch();
7840
}
7941

80-
const connectToSFU = (tokenData: TokenResponse) => {
42+
const connectToSFU = (tokenData: PresenceTokenResponse) => {
8143
if (!tokenData.sfu_url || !tokenData.auth_token) {
8244
error.value = "Invalid token data";
8345
return;
@@ -118,7 +80,7 @@ export function useMeetingPreviewPresence(meetingId: string) {
11880
},
11981
},
12082
// keep callback since we do evoke it
121-
(joinResponse: JoinResponse) => {
83+
(joinResponse: PresenceJoinResponse) => {
12284
if (!joinResponse.success) {
12385
console.error(
12486
"Failed to join room for presence preview:",
@@ -131,7 +93,7 @@ export function useMeetingPreviewPresence(meetingId: string) {
13193
currentSocket.emit(
13294
"get_room_participants",
13395
{},
134-
(response: ParticipantResponse) => {
96+
(response: PresenceParticipantsResponse) => {
13597
if (response.success && response.participants) {
13698
participants.value = response.participants.map((p) => ({
13799
user_id: p.info.userId || p.user_id || p.id,
@@ -152,13 +114,14 @@ export function useMeetingPreviewPresence(meetingId: string) {
152114
error.value = err.message || "Failed to connect to SFU";
153115
});
154116

155-
currentSocket.on("participant_joined", (data: ParticipantJoinedData) => {
117+
currentSocket.on("participant_joined", (data: ParticipantJoinedEvent) => {
156118
const newParticipant: ParticipantPreview = {
157119
user_id: data.userData.userId,
158120
full_name: data.userData.name || data.userData.userId,
159121
avatar_url: data.userData.avatar,
160122
has_video: data.userData.video_enabled,
161123
has_audio: data.userData.audio_enabled,
124+
is_guest: data.userData.is_guest,
162125
};
163126

164127
const existingIndex = participants.value.findIndex(
@@ -169,7 +132,7 @@ export function useMeetingPreviewPresence(meetingId: string) {
169132
}
170133
});
171134

172-
currentSocket.on("participant_left", (data: ParticipantLeftData) => {
135+
currentSocket.on("participant_left", (data: ParticipantLeftEvent) => {
173136
if (data.participantId.startsWith("preview-")) {
174137
return;
175138
}

frontend/src/types.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { UserData } from "../../types";
2+
13
export type Platform = "win" | "mac" | "linux" | "unknown";
24

35
export interface FrappeRequestError extends Error {
@@ -7,11 +9,11 @@ export interface FrappeRequestError extends Error {
79
export interface Participant {
810
user_id: string;
911
user_name?: string;
10-
avatar?: string;
12+
avatar?: UserData["avatar"];
1113
initials?: string;
12-
audio_enabled?: boolean;
13-
video_enabled?: boolean;
14-
is_guest?: boolean;
14+
audio_enabled?: UserData["audio_enabled"];
15+
video_enabled?: UserData["video_enabled"];
16+
is_guest?: UserData["is_guest"];
1517
}
1618

1719
export interface ParticipantPreview {
@@ -20,4 +22,16 @@ export interface ParticipantPreview {
2022
avatar_url?: string;
2123
has_video: boolean;
2224
has_audio: boolean;
25+
is_guest?: boolean;
2326
}
27+
28+
export type {
29+
ParticipantInfo,
30+
ParticipantJoinedEvent,
31+
ParticipantLeftEvent,
32+
PresenceJoinResponse,
33+
PresenceParticipantsResponse,
34+
PresenceTokenResponse,
35+
PreviewParticipantInfo,
36+
UserData,
37+
} from "../../types";

frontend/vite.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,8 @@ export default defineConfig({
6363
},
6464
server: {
6565
allowedHosts: true,
66+
fs: {
67+
allow: [path.resolve(__dirname, "..")],
68+
},
6669
},
6770
});

sfu-server/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ EXPOSE 3000
3232
HEALTHCHECK --interval=30s --timeout=3s --retries=3 CMD curl -fsS http://127.0.0.1:3000/health || exit 1
3333

3434
ENTRYPOINT ["/usr/bin/tini","--"]
35-
CMD ["node","dist/server.js"]
35+
CMD ["node","dist/sfu-server/src/server.js"]

sfu-server/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"name": "meet-sfu-server",
33
"version": "0.0.1",
44
"description": "SFU server for Frappe Meet",
5-
"main": "dist/server.js",
5+
"main": "dist/sfu-server/src/server.js",
66
"scripts": {
77
"build": "tsc",
8-
"start": "node dist/server.js",
8+
"start": "node dist/sfu-server/src/server.js",
99
"dev": "ts-node src/server.ts",
1010
"dev:watch": "npx nodemon",
1111
"spawn-fake": "node scripts/spawn-fake-users.js",

0 commit comments

Comments
 (0)