- 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
70 lines
3.3 KiB
JavaScript
70 lines
3.3 KiB
JavaScript
#!/usr/bin/env node
|
|
// E2E test: create session on backend-api, connect to browserless, open Broadcast Panel, postMessage token and wait for Studio overlay
|
|
const fs = require('fs')
|
|
const fetch = global.fetch || require('node-fetch')
|
|
const puppeteer = require('puppeteer-core')
|
|
|
|
(async () => {
|
|
try {
|
|
const BACKEND = process.env.TOKEN_SERVER || 'http://localhost:4000'
|
|
const BROADCAST_URL = process.env.BROADCAST_URL || 'https://avanzacast-broadcastpanel.bfzqqk.easypanel.host'
|
|
const BROWSERLESS_TOKEN = process.env.BROWSERLESS_TOKEN || process.env.BROWSERLESS || process.env.TOKEN || ''
|
|
if (!BROWSERLESS_TOKEN) {
|
|
console.error('BROWSERLESS_TOKEN not set in env (use BROWSERLESS_TOKEN=...)')
|
|
process.exit(1)
|
|
}
|
|
|
|
console.log('Creating session on backend:', BACKEND)
|
|
const res = await fetch(`${BACKEND.replace(/\/$/, '')}/api/session`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ room: 'e2e-room', username: 'e2e-runner' })
|
|
})
|
|
if (!res.ok) {
|
|
const t = await res.text().catch(() => '')
|
|
throw new Error('Failed to create session: ' + res.status + ' ' + t)
|
|
}
|
|
const j = await res.json()
|
|
const livekitToken = j.token
|
|
const livekitUrl = j.url || j.studioUrl || j.redirectUrl || ''
|
|
console.log('Got session token (trunc):', livekitToken ? livekitToken.slice(0, 40) + '...' : '(none)')
|
|
|
|
const wsEndpoint = `wss://browserless.bfzqqk.easypanel.host?token=${BROWSERLESS_TOKEN}`
|
|
console.log('Connecting to browserless WS endpoint:', wsEndpoint)
|
|
const browser = await puppeteer.connect({ browserWSEndpoint: wsEndpoint, defaultViewport: { width: 1280, height: 800 } })
|
|
const page = await browser.newPage()
|
|
console.log('Opening Broadcast Panel page:', BROADCAST_URL)
|
|
await page.goto(BROADCAST_URL, { waitUntil: 'networkidle2', timeout: 60000 })
|
|
console.log('Page loaded, posting LIVEKIT_TOKEN via window.postMessage')
|
|
const payload = { type: 'LIVEKIT_TOKEN', token: livekitToken, url: livekitUrl, room: j.room || 'e2e-room' }
|
|
await page.evaluate((p) => window.postMessage(p, window.location.origin), payload)
|
|
|
|
// Wait for overlay .studio-portal or validation overlay
|
|
console.log('Waiting for studio overlay or token indicator...')
|
|
try {
|
|
await page.waitForSelector('.studio-portal, .studioOverlay, .studio-portal__center, .studio-overlay', { timeout: 15000 })
|
|
console.log('Studio overlay appeared!')
|
|
} catch (err) {
|
|
console.warn('Studio overlay not detected within timeout. Will check for StudioPortal token indicator text')
|
|
// Check for text 'Token recibido' in page
|
|
const found = await page.evaluate(() => !!document.querySelector('.studio-portal') || !![...document.querySelectorAll('*')].some(el => el.textContent && el.textContent.includes('Token recibido')))
|
|
if (!found) {
|
|
console.error('Studio overlay/token not found')
|
|
} else {
|
|
console.log('Found token indicator text')
|
|
}
|
|
}
|
|
|
|
const screenshotPath = '/tmp/avanzacast_studio_e2e.png'
|
|
await page.screenshot({ path: screenshotPath, fullPage: false })
|
|
console.log('Screenshot saved to', screenshotPath)
|
|
|
|
await browser.close()
|
|
console.log('E2E run finished')
|
|
} catch (err) {
|
|
console.error('E2E failed:', err)
|
|
process.exit(2)
|
|
}
|
|
})()
|
|
|