From 27a4cc8695e54a87d638182faaf8296fba98ce83 Mon Sep 17 00:00:00 2001 From: iamdoubz <4871781+iamdoubz@users.noreply.github.com> Date: Fri, 4 Apr 2025 13:30:15 -0500 Subject: [PATCH] Update coturn.ts Add function for using TURN_CRED --- src/coturn.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/coturn.ts b/src/coturn.ts index 7b56e4b..f1c9369 100644 --- a/src/coturn.ts +++ b/src/coturn.ts @@ -32,3 +32,26 @@ export async function setTurnCredentials( await redis.setex(key, ttl, hmacKey) } + +export async function setTurnCredentials2( + username: string, + password: string, + ttl: number, +): Promise { + if (!process.env.COTURN_ENABLED) { + return + } + + const realm = process.env.TURN_REALM || 'file.pizza' + + if (!realm) { + throw new Error('TURN_REALM environment variable not set') + } + + const redis = getRedisClient() + + const hmacKey = password + const key = `turn/realm/${realm}/user/${username}/key` + + await redis.setex(key, ttl, hmacKey) +}