-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathMeetingPreview.vue
More file actions
267 lines (239 loc) · 7.52 KB
/
MeetingPreview.vue
File metadata and controls
267 lines (239 loc) · 7.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<template>
<div class="flex-1 flex flex-col" data-testid="meeting-preview">
<div class="bg-gray-50 px-6 pt-4 flex-shrink-0">
<div class="flex items-center justify-between">
<div class="flex items-center gap-2 cursor-pointer" @click="$router.push('/')">
<FrappeMeetingLogo class="h-8" />
<h4 class="text-gray-900 text-base">Frappe Meet</h4>
</div>
<Button
v-if="!session.isLoggedIn"
variant="ghost"
size="sm"
@click="$router.push({ name: 'Login', query: { next: $route.fullPath } })"
>
Sign In
</Button>
</div>
</div>
<div class="flex-1 flex lg:flex-row flex-col bg-gray-50 text-gray-900">
<div class="max-w-7xl mx-auto w-full flex lg:flex-row flex-col">
<!-- Video Section -->
<div class="lg:flex-[2] flex flex-col justify-center p-6 lg:pr-4">
<div class="max-w-3xl mx-auto w-full">
<div
class="relative bg-black rounded-xl overflow-hidden aspect-video shadow-xl group h-full"
data-testid="preview-video-shell"
>
<video
:ref="(el) => setLocalVideoRef?.(el)"
class="w-full h-full object-cover transform scale-x-[-1]"
autoplay
muted
playsinline
/>
<div
v-if="!isCameraOn"
class="absolute inset-0 bg-gray-800 flex items-center justify-center"
>
<div class="text-center text-white">
<MeetingAvatar
:label="userInitials"
:image="userAvatar"
:tiles="1"
class="mx-auto mb-4 w-20 h-20"
/>
<p class="text-xl font-medium">{{ currentUserName }}</p>
</div>
</div>
<PreviewToolbar
:isMicOn="isMicOn"
:isCameraOn="isCameraOn"
:cameraPermissionGranted="cameraPermissionGranted"
:microphonePermissionGranted="microphonePermissionGranted"
@toggle-microphone="$emit('toggle-microphone')"
@toggle-camera="$emit('toggle-camera')"
@device-changed="$emit('device-changed', $event)"
/>
</div>
</div>
</div>
<!-- Join Section -->
<div
class="lg:flex-[1] flex items-center lg:justify-end justify-center p-6 lg:pl-4"
>
<div class="max-w-md w-full">
<div class="p-8 mb-6 w-full h-full flex flex-col justify-center">
<div class="mb-6 text-center">
<div class="mb-4">
<div
class="w-16 h-16 mx-auto rounded-full flex items-center justify-center mb-4 bg-gradient-to-br from-blue-100 to-indigo-100"
>
<lucide-video class="w-8 h-8 text-blue-600" />
</div>
</div>
<h2 class="text-3xl text-gray-900 mb-3">
<span class="text-gray-900"> Ready to join? </span>
</h2>
<div v-if="meetingTitle" class="bg-gray-50 rounded-lg px-4 py-3 mb-4">
<p class="text-lg font-medium text-gray-700 truncate">
{{ meetingTitle }}
</p>
</div>
<!-- Avatar group for current participants -->
<ParticipantAvatarGroup
v-if="!isGuest"
:participants="participants"
:error="presenceError"
:maxDisplayed="3"
/>
</div>
<form class="space-y-3" @submit.prevent="handleJoin">
<FormControl
v-if="isGuest"
ref="guestNameInputRef"
v-model="guestName"
type="text"
label="Your name"
placeholder="John Doe"
:maxlength="50"
autocomplete="off"
data-testid="guest-name-input"
/>
<Button
type="submit"
variant="solid"
size="lg"
:loading="isConnecting || joinGuestAPI.loading"
:disabled="isGuest && !guestName.trim()"
class="w-full"
data-testid="join-meeting-preview-button"
>
<template #prefix>
<lucide-video class="w-5 h-5" />
</template>
Join Meeting
</Button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script setup>
import { Button, createResource, FormControl, toast } from "frappe-ui";
import { computed, inject, nextTick, onMounted, ref, watch } from "vue";
import ParticipantAvatarGroup from "../components/ParticipantAvatarGroup.vue";
import PreviewToolbar from "../components/PreviewToolbar.vue";
import { useMeetingPreviewPresence } from "../composables/useMeetingPreviewPresence";
import { session } from "../data/session";
import FrappeMeetingLogo from "../icons/FrappeMeetingLogo.vue";
import MeetingAvatar from "./MeetingAvatar.vue";
const props = defineProps({
meetingId: { type: String, required: true },
});
const guestName = ref("");
onMounted(() => {
const savedGuestName = localStorage.getItem("guest_name");
if (savedGuestName && !session.isLoggedIn) {
guestName.value = savedGuestName;
}
});
const guestNameInputRef = ref(null);
const joinGuestAPI = createResource({
url: "meet.api.meeting.join_meeting_as_guest",
makeParams: () => {
return {
meeting_id: props.meetingId,
guest_name: guestName.value.trim(),
};
},
});
const meetingState = inject("meetingState");
const setLocalVideoRef = inject("setLocalVideoRef");
const meetingTitle = inject("meetingTitle");
const isGuest = computed(
() => !session.isLoggedIn && !meetingState.guestAuthToken.value,
);
const { participants, error: presenceError } = useMeetingPreviewPresence(
props.meetingId,
);
const isCameraOn = computed(() => meetingState.isCameraOn.value);
const isMicOn = computed(() => meetingState.isMicOn.value);
const currentUser = computed(() => meetingState.currentUser.value);
const userInitials = computed(() => {
if (isGuest.value && guestName.value.trim()) {
return guestName.value.trim().charAt(0).toUpperCase();
}
return meetingState.userInitials.value;
});
const userAvatar = computed(() => {
if (isGuest.value) {
return null;
}
return meetingState.userAvatar.value;
});
const isConnecting = computed(() => meetingState.isConnecting.value);
const cameraPermissionGranted = computed(
() => meetingState.cameraPermissionGranted.value,
);
const microphonePermissionGranted = computed(
() => meetingState.microphonePermissionGranted.value,
);
const emit = defineEmits([
"toggle-microphone",
"toggle-camera",
"join-from-preview",
"device-changed",
"guest-join-complete",
]);
watch(guestNameInputRef, (inputRef) => {
if (inputRef) {
nextTick(() => {
const input = inputRef.$el?.querySelector("input");
input?.focus();
});
}
});
const handleJoin = async () => {
if (joinGuestAPI.loading || isConnecting.value) {
return;
}
if (isGuest.value) {
if (!guestName.value.trim()) {
return;
}
try {
const result = await joinGuestAPI.submit();
localStorage.setItem("guest_name", guestName.value.trim());
meetingState.guestId.value = result.guest_id;
meetingState.guestSfuUrl.value = result.sfu_url || null;
meetingState.guestSfuPort.value = result.sfu_port || null;
if (result.status === "waiting_for_approval") {
meetingState.isWaitingForApproval.value = true;
meetingState.guestAuthToken.value = null;
} else {
meetingState.guestAuthToken.value = result.auth_token || null;
meetingState.isWaitingForApproval.value = false;
}
emit("guest-join-complete", {
guestName: guestName.value.trim(),
joinResult: result,
});
} catch (error) {
console.error("Failed to join as guest:", error);
toast.error("Failed to join meeting. Please try again.");
}
} else {
emit("join-from-preview");
}
};
const currentUserName = computed(() => {
if (isGuest.value && guestName.value.trim()) {
return guestName.value.trim();
}
return currentUser.value?.full_name || currentUser.value?.name || "You";
});
</script>