fix: harden booking and meeting flows
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import type { CollectionAfterChangeHook } from "payload";
|
||||
import type { Event } from "@/payload-types";
|
||||
import { meetingAccessVersion } from "./access";
|
||||
import { getLiveKitRoomName, getLiveKitRoomService } from "./livekit";
|
||||
|
||||
/** Disconnect the previous room when its password, schedule or access changes. */
|
||||
export const revokeChangedMeeting: CollectionAfterChangeHook<Event> = async ({ doc, previousDoc, req }) => {
|
||||
if (!previousDoc?.isOnline || !previousDoc.slug || !process.env.LIVEKIT_URL || !process.env.MEETING_SESSION_SECRET) return doc;
|
||||
const previousVersion = meetingAccessVersion(previousDoc);
|
||||
if (previousVersion === meetingAccessVersion(doc)) return doc;
|
||||
try {
|
||||
const service = getLiveKitRoomService();
|
||||
const name = getLiveKitRoomName(previousDoc.slug, previousVersion);
|
||||
if ((await service.listRooms([name])).length) await service.deleteRoom(name);
|
||||
} catch (err) {
|
||||
req.payload.logger.error({ err, msg: "Could not disconnect revoked meeting room" });
|
||||
}
|
||||
return doc;
|
||||
};
|
||||
Reference in New Issue
Block a user