🚸(frontend) generate shorter room IDs making URLs easier to share
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
This commit is contained in:
committed by
Emmanuel Pelletier
parent
9fd1af2302
commit
d8c8ac0811
@@ -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('-');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user