2022-08-16 02:38:56 +00:00
|
|
|
export const sleep = (milliseconds: number): Promise<void> =>
|
|
|
|
new Promise<void>(res => {
|
|
|
|
setTimeout(res, milliseconds)
|
|
|
|
})
|
2022-11-13 23:11:09 +00:00
|
|
|
|
|
|
|
export const isRecord = (variable: any): variable is Record<string, any> => {
|
|
|
|
return (
|
|
|
|
typeof variable === 'object' &&
|
|
|
|
!Array.isArray(variable) &&
|
|
|
|
variable !== null
|
|
|
|
)
|
|
|
|
}
|
2022-11-24 06:16:34 +00:00
|
|
|
|
|
|
|
export const isError = (e: any): e is Error => {
|
|
|
|
return e instanceof Error
|
|
|
|
}
|
2023-01-08 20:37:30 +00:00
|
|
|
|
|
|
|
export const encodePassword = async (roomId: string, password: string) => {
|
|
|
|
const data = new TextEncoder().encode(`${roomId}_${password}`)
|
|
|
|
const digest = await window.crypto.subtle.digest('SHA-256', data)
|
|
|
|
const bytes = new Uint8Array(digest)
|
|
|
|
return window.btoa(String.fromCharCode(...bytes))
|
|
|
|
}
|