AvanzaCast/packages/backend-api/scripts/test-token-flow.js
Cesar Mendivil 8b458a3ddf feat: add initial LiveKit Meet integration with utility scripts, configs, and core components
- Add Next.js app structure with base configs, linting, and formatting
- Implement LiveKit Meet page, types, and utility functions
- Add Docker, Compose, and deployment scripts for backend and token server
- Provide E2E and smoke test scaffolding with Puppeteer and Playwright helpers
- Include CSS modules and global styles for UI
- Add postMessage and studio integration utilities
- Update package.json with dependencies and scripts for development and testing
2025-11-20 12:50:38 -07:00

75 lines
2.7 KiB
JavaScript

// Script de prueba para generar una sesión y comprobar la URL en broadcast-panel
// Uso: BACKEND_URL=http://localhost:4000 BROADCAST_BASE=https://avanzacast-broadcastpanel.bfzqqk.easypanel.host node scripts/test-token-flow.js
async function main() {
const backend = process.env.BACKEND_URL || 'http://localhost:4000';
const broadcastBase = process.env.BROADCAST_BASE || 'https://avanzacast-broadcastpanel.bfzqqk.easypanel.host';
console.log('[test] Backend:', backend);
console.log('[test] Broadcast base:', broadcastBase);
const payload = { room: 'test-room-' + Math.random().toString(36).slice(2,8), username: 'tester', ttl: 120 };
try {
const resp = await fetch(`${backend.replace(/\/$/, '')}/api/session`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
});
const text = await resp.text();
let json;
try { json = JSON.parse(text); } catch (e) { console.error('[test] respuesta no-JSON:', text); throw e; }
if (!resp.ok) {
console.error('[test] fallo al crear session', resp.status, json);
process.exit(2);
}
console.log('[test] session created:', JSON.stringify(json, null, 2));
const id = json.id;
if (!id) {
console.error('[test] la respuesta no incluyó id de session; revisa backend');
process.exit(3);
}
const urlToCheck = `${broadcastBase.replace(/\/$/, '')}/${encodeURIComponent(id)}`;
console.log('[test] comprobando URL de broadcast-panel ->', urlToCheck);
// hacen un HEAD primero
try {
const head = await fetch(urlToCheck, { method: 'HEAD' });
console.log(`[test] HEAD ${head.status} ${head.statusText}`);
} catch (e) {
console.warn('[test] HEAD falló, intentando GET', String(e));
}
// luego GET para ver contenido (limitado)
try {
const get = await fetch(urlToCheck, { method: 'GET' });
console.log(`[test] GET ${get.status} ${get.statusText}`);
const ctype = get.headers.get('content-type') || '';
console.log('[test] content-type:', ctype);
const body = await get.text();
console.log('[test] body (first 1000 chars):\n', body.slice(0, 1000));
} catch (e) {
console.error('[test] GET falló:', String(e));
}
console.log('[test] prueba finalizada');
process.exit(0);
} catch (err) {
console.error('[test] error inesperado', err);
process.exit(1);
}
}
// Node 18+ tiene fetch global. Si no, mostrar instrucción al usuario.
if (typeof fetch === 'undefined') {
console.error('fetch no está disponible en este entorno Node. Usa Node 18+ o instala una dependencia como node-fetch.');
process.exit(1);
}
main();