@@ -2,53 +2,15 @@ import { createResource } from "frappe-ui";
22import { type Socket , io } from "socket.io-client" ;
33import { computed , onUnmounted , readonly , ref } from "vue" ;
44import { 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
5315export 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 }
0 commit comments