From d8c8ac0811da2a77759e77aac3692d43e89f7a29 Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Wed, 17 Jul 2024 21:56:21 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8(frontend)=20generate=20shorter=20r?= =?UTF-8?q?oom=20IDs=20making=20URLs=20easier=20to=20share?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit UUID-v4 room IDs are long and uninviting. Shorter, custom room IDs can enhance UX by making URLs easier to share and remember. While UUID-v4s are typically used in database systems for their low collision probability, for ephemeral room IDs, the collision risk of e+14 combinations is acceptable. This aligns room IDs with Google Meet format. Even if the 'slugify' function is not used anymore, I kept it. Lmk if you prefer removing it @manuhabitela --- .../features/rooms/utils/generateRoomId.ts | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/features/rooms/utils/generateRoomId.ts b/src/frontend/src/features/rooms/utils/generateRoomId.ts index f8be43bb..dc84dcf1 100644 --- a/src/frontend/src/features/rooms/utils/generateRoomId.ts +++ b/src/frontend/src/features/rooms/utils/generateRoomId.ts @@ -1,5 +1,27 @@ -import { slugify } from '@/utils/slugify' + +const getRandomChar = () => { + // Google Meet uses only letters in a room identifier + const characters = 'abcdefghijklmnopqrstuvwxyz'; + const charactersLength = characters.length; + return characters.charAt(Math.floor(Math.random() * charactersLength)) +} + +const generateSegment = (length: number): string => { + let segment = ''; + for (let i = 0; i < length; i++) { + segment += getRandomChar(); + } + return segment; +}; export const generateRoomId = () => { - return slugify(crypto.randomUUID()) + // Generates a unique room identifier following the Google Meet format + const shortLength = 3; + const longLength = 4; + const parts = [ + generateSegment(shortLength), + generateSegment(longLength), + generateSegment(shortLength) + ]; + return parts.join('-'); }