import "./style.css"; import "./connection"; import * as globals from "./globals"; const app = document.querySelector('#app'); if (app) { app.innerHTML = `
Host:
Key:
Id:
`; let player; document.body.onload = () => { const host = document.querySelector('#host'); host.value = localStorage.getItem('host'); const id = document.querySelector('#id'); id.value = localStorage.getItem('id'); const key = document.querySelector('#key'); key.value = localStorage.getItem('key'); player = YUVCanvas.attach(document.getElementById("player")) }; window.connect = () => { const host = document.querySelector('#host'); localStorage.setItem('host', host.value); const id = document.querySelector('#id'); localStorage.setItem('id', id.value); const key = document.querySelector('#key'); localStorage.setItem('key', key.value); const func = async () => { const conn = globals.newConn(); conn.setMsgbox(msgbox); conn.setDraw((f) => { player.drawFrame(f); }); document.querySelector('div#status').style.display = 'block'; document.querySelector('div#connect').style.display = 'none'; document.querySelector('div#text').innerHTML = 'Connecting ...'; try { await conn.start(id.value); } catch (e) { msgbox('error', 'Error', e); } }; func(); } function msgbox(type, title, text) { if (!globals.getConn()) return; if (type == 'input-password') { document.querySelector('div#status').style.display = 'none'; document.querySelector('div#password').style.display = 'block'; } else if (!type) { document.querySelector('div#status').style.display = 'none'; } else if (type == 'error') { document.querySelector('div#status').style.display = 'block'; document.querySelector('div#text').innerHTML = '
' + text + '
'; } else { document.querySelector('div#status').style.display = 'block'; document.querySelector('div#text').innerHTML = '
' + text + '
'; } } window.cancel = () => { globals.close(); document.querySelector('div#connect').style.display = 'block'; document.querySelector('div#password').style.display = 'none'; document.querySelector('div#status').style.display = 'none'; } window.confirm = () => { const password = document.querySelector('input#password').value; if (password) { document.querySelector('div#password').style.display = 'none'; globals.getConn().login(password); } } }