mirror of
https://github.com/suitenumerique/meet.git
synced 2026-08-11 03:07:43 +00:00
26 lines
808 B
TypeScript
26 lines
808 B
TypeScript
export const roomIdPattern = '[a-z]{3}-[a-z]{4}-[a-z]{3}'
|
|
|
|
// Case-insensitive and with optional hyphens
|
|
export const flexibleRoomIdPattern =
|
|
'(?:[a-zA-Z0-9]{3}-?[a-zA-Z0-9]{4}-?[a-zA-Z0-9]{3})'
|
|
|
|
const roomRegex = new RegExp(`^${roomIdPattern}$`)
|
|
const roomWithoutHyphensRegex = /^[a-z]{10}$/
|
|
|
|
export const isRoomValid = (roomIdOrUrl: string) => {
|
|
const lower = roomIdOrUrl.toLowerCase()
|
|
return (
|
|
roomRegex.test(lower) ||
|
|
roomWithoutHyphensRegex.test(lower) ||
|
|
new RegExp(`^${window.location.origin}/${roomIdPattern}`).test(roomIdOrUrl)
|
|
)
|
|
}
|
|
|
|
export const normalizeRoomId = (roomId: string) => {
|
|
const cleanId = roomId.toLowerCase().replace(/-/g, '')
|
|
if (cleanId.length === 10) {
|
|
return `${cleanId.slice(0, 3)}-${cleanId.slice(3, 7)}-${cleanId.slice(7, 10)}`
|
|
}
|
|
return roomId
|
|
}
|