Cesar Mendivil 0ca2b36b5c feat: Implement Studio Panel with Left Sidebar, Right Panel, and Video Area
- 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.
2025-11-06 19:09:00 -07:00

106 lines
2.6 KiB
JavaScript

import express from 'express'
import cors from 'cors'
import { AccessToken } from 'livekit-server-sdk'
import * as dotenv from 'dotenv'
// Cargar variables de entorno
dotenv.config({ path: '../../.env' })
const app = express()
const port = 3010
// Middleware
app.use(cors())
app.use(express.json())
// Configuración de LiveKit desde variables de entorno
const LIVEKIT_API_KEY = process.env.LIVEKIT_API_KEY || 'devkey'
const LIVEKIT_API_SECRET = process.env.LIVEKIT_API_SECRET || 'secret'
const LIVEKIT_URL = process.env.LIVEKIT_URL || 'wss://livekit-server.bfzqqk.easypanel.host'
console.log('🚀 Servidor de tokens iniciado')
console.log('📡 LiveKit URL:', LIVEKIT_URL)
console.log('🔑 API Key:', LIVEKIT_API_KEY)
// Endpoint para generar tokens
app.get('/api/token', async (req, res) => {
try {
const { room, username } = req.query
if (!room || !username) {
return res.status(400).json({
error: 'Se requieren los parámetros room y username'
})
}
// Crear token de acceso
const at = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET, {
identity: username,
name: username,
})
// Agregar permisos
at.addGrant({
room: room,
roomJoin: true,
canPublish: true,
canPublishData: true,
canSubscribe: true,
})
// Generar JWT
const token = await at.toJwt()
console.log(`✅ Token generado para usuario: ${username} en sala: ${room}`)
res.json({
token,
serverUrl: LIVEKIT_URL,
})
} catch (error) {
console.error('❌ Error generando token:', error)
res.status(500).json({
error: 'Error al generar token',
details: error.message
})
}
})
// Endpoint de salud
app.get('/health', (req, res) => {
res.json({
status: 'ok',
livekit: {
url: LIVEKIT_URL,
apiKey: LIVEKIT_API_KEY,
},
})
})
const server = app.listen(port, () => {
console.log(`🎙️ Servidor corriendo en http://localhost:${port}`)
console.log(`📋 Endpoint de tokens: http://localhost:${port}/api/token?room=ROOM_NAME&username=USERNAME`)
console.log(`💚 Health check: http://localhost:${port}/health`)
})
server.on('error', (error) => {
console.error('❌ Error del servidor:', error)
process.exit(1)
})
process.on('SIGTERM', () => {
console.log('🛑 SIGTERM recibido, cerrando servidor...')
server.close(() => {
console.log('✅ Servidor cerrado')
process.exit(0)
})
})
process.on('SIGINT', () => {
console.log('🛑 SIGINT recibido, cerrando servidor...')
server.close(() => {
console.log('✅ Servidor cerrado')
process.exit(0)
})
})