/** * LiveKit token generation service */ import { AccessToken } from 'livekit-server-sdk'; export interface TokenOptions { roomName: string; participantName: string; participantIdentity?: string; } /** * Generate a LiveKit access token for screenshare bot */ export async function generateLiveKitToken(options: TokenOptions): Promise { const apiKey = process.env.LIVEKIT_API_KEY; const apiSecret = process.env.LIVEKIT_API_SECRET; if (!apiKey || !apiSecret) { throw new Error('LiveKit API credentials not configured'); } const identity = options.participantIdentity || `bot-${Date.now()}`; const token = new AccessToken(apiKey, apiSecret, { identity, name: options.participantName }); // Grant permissions for screenshare bot token.addGrant({ roomJoin: true, room: options.roomName, canPublish: true, canSubscribe: true, canPublishData: true }); return await token.toJwt(); }