Skip to content

Commit

Permalink
🚸(frontend) generate shorter room IDs making URLs easier to share
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lebaudantoine authored and manuhabitela committed Jul 21, 2024
1 parent 9fd1af2 commit d8c8ac0
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/frontend/src/features/rooms/utils/generateRoomId.ts
Original file line number Diff line number Diff line change
@@ -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('-');
}

0 comments on commit d8c8ac0

Please sign in to comment.