71 lines
3.1 KiB
HTML
71 lines
3.1 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
<title>Studio Receiver (Test)</title>
|
|
<style>body{font-family:Arial;background:#0f172a;color:#fff;padding:20px} .box{padding:12px;background:#111827;border-radius:8px}</style>
|
|
</head>
|
|
<body>
|
|
<h3>Studio Receiver - listens for LIVEKIT_TOKEN</h3>
|
|
<div class="box" id="status">Esperando token...</div>
|
|
<script>
|
|
function setStatusText(text){
|
|
try{ document.getElementById('status').textContent = text }catch(e){}
|
|
}
|
|
|
|
// helper to try to auto-fill parent opener (if studio UI is in opener)
|
|
function tryFillOpener(token, room, username){
|
|
try{
|
|
const op = window.opener;
|
|
if (!op) return false;
|
|
// try common fields used in studio Panel (ws url, room, token)
|
|
try{ if (op.document && op.document.querySelector) {
|
|
const tokenInput = op.document.querySelector('input[placeholder*="Paste your LiveKit token"], input[name*="token"], input[id*="token"]');
|
|
if (tokenInput) { tokenInput.value = token; tokenInput.dispatchEvent(new Event('input',{bubbles:true})); }
|
|
const roomInput = op.document.querySelector('input[placeholder*="Room Name"], input[name*="room"], input[id*="room"]');
|
|
if (roomInput && room) { roomInput.value = room; roomInput.dispatchEvent(new Event('input',{bubbles:true})); }
|
|
const connectBtn = op.document.querySelector('button:enabled');
|
|
if (connectBtn) { try { connectBtn.click(); } catch(e){} }
|
|
return true;
|
|
}}catch(e){}
|
|
}catch(e){}
|
|
return false;
|
|
}
|
|
|
|
// If token is provided via query param, show it and attempt auto actions
|
|
try{
|
|
const params = new URLSearchParams(window.location.search);
|
|
const qtoken = params.get('token');
|
|
const qroom = params.get('room') || '';
|
|
const quser = params.get('username') || '';
|
|
if (qtoken){
|
|
setStatusText('Token recibido (query): ' + qtoken);
|
|
// try to fill opener's form and trigger connect
|
|
const filled = tryFillOpener(qtoken, qroom, quser);
|
|
// also post ACK to opener if available
|
|
try{ if (window.opener) window.opener.postMessage({ type: 'LIVEKIT_ACK', status: 'received', via: 'query', filled: filled }, '*'); }catch(e){}
|
|
}
|
|
}catch(e){ console.warn('query token error', e) }
|
|
|
|
window.addEventListener('message', (e)=>{
|
|
try{
|
|
const data = e.data || {};
|
|
if (data?.type === 'LIVEKIT_TOKEN'){
|
|
const token = data.token || '';
|
|
const room = data.room || '';
|
|
setStatusText('Token recibido: ' + (token || '(empty)'));
|
|
// try to autofill opener
|
|
const filled = tryFillOpener(token, room, data.user || '');
|
|
// send ack back to opener
|
|
try{ e.source.postMessage({ type: 'LIVEKIT_ACK', status: 'received', filled: filled }, e.origin || '*') }catch(err){}
|
|
}
|
|
}catch(err){ console.error(err) }
|
|
});
|
|
|
|
// heartbeat for debugging
|
|
setInterval(()=>{ console.log('studio_receiver alive'); }, 5000);
|
|
</script>
|
|
</body>
|
|
</html>
|