Files
epess-web-backend/src/LiveKit/livekit.service.ts
Ly Tuan Kiet 10e20092ab chore: update configuration and improve schema imports
- Updated biome.json to include "graphql.d.ts" in the ignored files list.
- Updated subproject commit reference in epess-database to the latest version.
- Removed unused script from package.json and streamlined module file extensions in tsconfig.json.
- Consolidated exclude patterns in tsconfig.build.json for clarity.
- Refactored imports across multiple schema files for consistency and improved readability.
- Enhanced various schema files by ensuring proper import order and removing redundant code.
- Improved error handling and data integrity checks in several service and schema files.
2024-12-08 20:49:52 +07:00

33 lines
895 B
TypeScript

import { Injectable, Logger } from '@nestjs/common'
import { User } from '@prisma/client'
// @ts-expect-error
import { AccessToken, RoomServiceClient } from 'livekit-server-sdk'
@Injectable()
export class LiveKitService {
constructor() {}
async createToken(me: User, roomName: string) {
if (!process.env.LIVEKIT_API_KEY || !process.env.LIVEKIT_API_SECRET) {
throw new Error('LIVEKIT_API_KEY and LIVEKIT_API_SECRET must be set')
}
if (!me.name) {
throw new Error('User must have a name')
}
const token = new AccessToken(process.env.LIVEKIT_API_KEY as string, process.env.LIVEKIT_API_SECRET as string, {
identity: me.id,
name: me.name,
metadata: me.avatarUrl ?? '',
})
token.addGrant({
roomJoin: true,
room: roomName,
})
return await token.toJwt()
}
getServerUrl() {
return process.env.LIVEKIT_URL
}
}