mirror of https://github.com/kern/filepizza
format
parent
9e7d78c755
commit
de881ae4fb
@ -1,30 +1,34 @@
|
||||
import crypto from 'crypto'
|
||||
import { getRedisClient } from './redisClient'
|
||||
|
||||
function generateHMACKey(username: string, realm: string, password: string): string {
|
||||
const str = `${username}:${realm}:${password}`
|
||||
return crypto.createHash('md5').update(str).digest('hex')
|
||||
function generateHMACKey(
|
||||
username: string,
|
||||
realm: string,
|
||||
password: string,
|
||||
): string {
|
||||
const str = `${username}:${realm}:${password}`
|
||||
return crypto.createHash('md5').update(str).digest('hex')
|
||||
}
|
||||
|
||||
export async function setTurnCredentials(
|
||||
username: string,
|
||||
password: string,
|
||||
ttl: number
|
||||
username: string,
|
||||
password: string,
|
||||
ttl: number,
|
||||
): Promise<void> {
|
||||
if (!process.env.COTURN_ENABLED) {
|
||||
return
|
||||
}
|
||||
if (!process.env.COTURN_ENABLED) {
|
||||
return
|
||||
}
|
||||
|
||||
const realm = process.env.TURN_REALM || 'file.pizza'
|
||||
const realm = process.env.TURN_REALM || 'file.pizza'
|
||||
|
||||
if (!realm) {
|
||||
throw new Error('TURN_REALM environment variable not set')
|
||||
}
|
||||
if (!realm) {
|
||||
throw new Error('TURN_REALM environment variable not set')
|
||||
}
|
||||
|
||||
const redis = getRedisClient()
|
||||
const redis = getRedisClient()
|
||||
|
||||
const hmacKey = generateHMACKey(username, realm, password)
|
||||
const key = `turn/realm/${realm}/user/${username}/key`
|
||||
const hmacKey = generateHMACKey(username, realm, password)
|
||||
const key = `turn/realm/${realm}/user/${username}/key`
|
||||
|
||||
await redis.setex(key, ttl, hmacKey)
|
||||
await redis.setex(key, ttl, hmacKey)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue