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