Download streaming-react-app/src/generateNewRoomID.ts from facebook/seamless-streaming: direct link, hf CLI and curl.
- Browser
- Download file 1.38 kB
-
https://huggingface.co/spaces/facebook/seamless-streaming/resolve/refs%2Fpr%2F21/streaming-react-app/src/generateNewRoomID.ts
- Command line
-
hf download hf://spaces/facebook/seamless-streaming@refs/pr/21/streaming-react-app/src/generateNewRoomID.ts
-
curl -L -o generateNewRoomID.ts https://huggingface.co/spaces/facebook/seamless-streaming/resolve/refs%2Fpr%2F21/streaming-react-app/src/generateNewRoomID.ts
1.38 kB
| import {random} from 'lodash'; | |
| // const USABLE_CHARACTERS = 'BCDFGHJKMPQRTVWXY2346789'; | |
| const USABLE_CHARACTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
| const ID_LENGTH = 4; | |
| export function isValidRoomID(id: string | null | undefined): boolean { | |
| if (id == null) { | |
| return false; | |
| } | |
| if (id.length !== ID_LENGTH) { | |
| return false; | |
| } | |
| return isValidPartialRoomID(id); | |
| } | |
| export function isValidPartialRoomID(roomID: string): boolean { | |
| return ( | |
| roomID.length <= ID_LENGTH && | |
| roomID.split('').every((char) => USABLE_CHARACTERS.includes(char)) | |
| ); | |
| } | |
| export default function generateNewRoomID(): string { | |
| return Array.from( | |
| {length: ID_LENGTH}, | |
| () => USABLE_CHARACTERS[random(USABLE_CHARACTERS.length - 1)], | |
| ).join(''); | |
| } | |
| export function getSequentialRoomIDForTestingGenerator(): () => string { | |
| let counter = 0; | |
| return function generateNextRoomID(): string { | |
| const counterInBase: string = Number(counter) | |
| .toString(USABLE_CHARACTERS.length) | |
| .padStart(ID_LENGTH, '0'); | |
| if (counterInBase.length > ID_LENGTH) { | |
| throw new Error( | |
| 'Ran out of unique room IDs from the sequential generator', | |
| ); | |
| } | |
| const result = counterInBase | |
| .split('') | |
| .map( | |
| (digit) => USABLE_CHARACTERS[parseInt(digit, USABLE_CHARACTERS.length)], | |
| ) | |
| .join(''); | |
| counter++; | |
| return result; | |
| }; | |
| } | |