fix: harden booking and meeting flows
This commit is contained in:
+10
-4
@@ -17,9 +17,9 @@ function getLiveKitApiUrl(): string {
|
||||
}
|
||||
|
||||
/** Stable opaque room name; the public event slug is never sent to LiveKit logs. */
|
||||
export function getLiveKitRoomName(eventSlug: string): string {
|
||||
export function getLiveKitRoomName(eventSlug: string, accessVersion?: string): string {
|
||||
const secret = requiredEnv("LIVEKIT_API_SECRET");
|
||||
return `anouma-${createHmac("sha256", secret).update(eventSlug).digest("hex").slice(0, 32)}`;
|
||||
return `anouma-${createHmac("sha256", secret).update(JSON.stringify([eventSlug, accessVersion])).digest("hex").slice(0, 32)}`;
|
||||
}
|
||||
|
||||
export async function createLiveKitToken(args: {
|
||||
@@ -28,12 +28,18 @@ export async function createLiveKitToken(args: {
|
||||
name: string;
|
||||
role: MeetingRole;
|
||||
clientId?: string;
|
||||
accessVersion?: string;
|
||||
expiresAt: number;
|
||||
}): Promise<string> {
|
||||
const room = getLiveKitRoomName(args.eventSlug);
|
||||
const room = getLiveKitRoomName(args.eventSlug, args.accessVersion);
|
||||
const remainingSeconds = Math.floor((args.expiresAt - Date.now()) / 1000);
|
||||
if (remainingSeconds <= 0) throw new Error("Meeting access has expired");
|
||||
const token = new AccessToken(requiredEnv("LIVEKIT_API_KEY"), requiredEnv("LIVEKIT_API_SECRET"), {
|
||||
identity: args.participantId,
|
||||
name: args.name,
|
||||
ttl: "2h",
|
||||
// Self-hosted LiveKit cannot revoke already issued JWTs. Keep the
|
||||
// connection credential short-lived; the app re-authorizes reconnects.
|
||||
ttl: Math.min(60, remainingSeconds),
|
||||
metadata: JSON.stringify({ role: args.role, clientId: args.clientId }),
|
||||
});
|
||||
token.addGrant({
|
||||
|
||||
Reference in New Issue
Block a user