- Added StudioLeftSidebar component for scene management with add, delete, and duplicate functionalities. - Introduced StudioRightPanel component with tabs for brand settings, multimedia, sounds, video, QR code generation, countdown, and general settings. - Created StudioSidebar component for participant management, chat, and notes. - Developed StudioVideoArea component to handle video display for demo and live modes. - Configured demo data for scenes, participants, overlays, backgrounds, and sounds in demo.ts. - Set up a token server for LiveKit integration to manage participant access. - Updated Vite environment definitions for LiveKit configuration.
86 lines
2.1 KiB
JavaScript
86 lines
2.1 KiB
JavaScript
/**
|
|
* LiveKit Token Generator API
|
|
*
|
|
* Este archivo debe ser ejecutado como servidor backend separado
|
|
* o integrado en tu servidor Express/Fastify existente.
|
|
*
|
|
* Para ejecutar standalone:
|
|
* npm install express cors livekit-server-sdk dotenv
|
|
* node token-server.js
|
|
*/
|
|
|
|
import express from 'express'
|
|
import cors from 'cors'
|
|
import { AccessToken } from 'livekit-server-sdk'
|
|
import dotenv from 'dotenv'
|
|
|
|
// Cargar variables de entorno
|
|
dotenv.config({ path: '../../.env' })
|
|
|
|
const app = express()
|
|
const PORT = process.env.TOKEN_SERVER_PORT || 3002
|
|
|
|
app.use(cors())
|
|
app.use(express.json())
|
|
|
|
// Endpoint para generar tokens
|
|
app.post('/api/token', async (req, res) => {
|
|
try {
|
|
const { roomName, participantName } = req.body
|
|
|
|
if (!roomName || !participantName) {
|
|
return res.status(400).json({
|
|
error: 'roomName y participantName son requeridos'
|
|
})
|
|
}
|
|
|
|
const apiKey = process.env.LIVEKIT_API_KEY
|
|
const apiSecret = process.env.LIVEKIT_API_SECRET
|
|
|
|
if (!apiKey || !apiSecret) {
|
|
console.error('LIVEKIT_API_KEY o LIVEKIT_API_SECRET no están configurados')
|
|
return res.status(500).json({
|
|
error: 'Configuración de LiveKit incompleta'
|
|
})
|
|
}
|
|
|
|
// Crear token de acceso
|
|
const at = new AccessToken(apiKey, apiSecret, {
|
|
identity: participantName,
|
|
name: participantName,
|
|
})
|
|
|
|
// Agregar permisos
|
|
at.addGrant({
|
|
room: roomName,
|
|
roomJoin: true,
|
|
canPublish: true,
|
|
canPublishData: true,
|
|
canSubscribe: true,
|
|
})
|
|
|
|
const token = at.toJwt()
|
|
|
|
res.json({
|
|
token,
|
|
serverUrl: process.env.LIVEKIT_URL
|
|
})
|
|
} catch (error) {
|
|
console.error('Error generando token:', error)
|
|
res.status(500).json({
|
|
error: 'Error al generar token de LiveKit'
|
|
})
|
|
}
|
|
})
|
|
|
|
// Health check
|
|
app.get('/health', (req, res) => {
|
|
res.json({ status: 'ok' })
|
|
})
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`🎬 LiveKit Token Server corriendo en http://localhost:${PORT}`)
|
|
console.log(`📡 LiveKit URL: ${process.env.LIVEKIT_URL}`)
|
|
console.log(`🔑 API Key configurada: ${process.env.LIVEKIT_API_KEY ? 'Sí' : 'No'}`)
|
|
})
|