108 lines
4.1 KiB
JavaScript
Raw Normal View History

2022-01-20 02:27:49 +08:00
import "./style.css";
import "./connection";
2022-01-20 18:02:20 +08:00
import * as globals from "./globals";
2022-01-20 02:27:49 +08:00
2022-01-20 12:49:57 +08:00
const app = document.querySelector('#app');
2022-01-20 01:55:57 +08:00
if (app) {
app.innerHTML = `
<div id="connect" style="text-align: center"><table style="display: inline-block">
<tr><td><span>Host: </span></td><td><input id="host" /></td></tr>
2022-01-20 02:27:49 +08:00
<tr><td><span>Key: </span></td><td><input id="key" /></td></tr>
2022-01-20 01:55:57 +08:00
<tr><td><span>Id: </span></td><td><input id="id" /></td></tr>
<tr><td></td><td><button onclick="connect();">Connect</button></td></tr>
</table></div>
<div id="password" style="display: none;">
<input type="password" id="password" />
2022-01-20 18:41:35 +08:00
<button id="confirm" onclick="confirm()">Confirm</button>
2022-01-20 01:55:57 +08:00
<button id="cancel" onclick="cancel();">Cancel</button>
</div>
2022-01-20 18:02:20 +08:00
<div id="status" style="display: none;">
<div id="text" style="line-height: 2em"></div>
<button id="cancel" onclick="cancel();">Cancel</button>
</div>
2022-01-21 00:41:02 +08:00
<div id="canvas" style="display: none;">
<button id="cancel" onclick="cancel();">Cancel</button>
<canvas id="player"></canvas>
2022-04-06 23:26:49 +08:00
<canvas id="test-yuv-decoder-canvas"></canvas>
2022-01-21 00:41:02 +08:00
</div>
2022-01-20 01:55:57 +08:00
`;
2022-01-20 21:58:28 +08:00
let player;
2022-01-27 13:24:40 +08:00
window.init();
2022-01-20 21:58:28 +08:00
2022-01-20 01:55:57 +08:00
document.body.onload = () => {
const host = document.querySelector('#host');
2022-01-27 01:30:29 +08:00
host.value = localStorage.getItem('custom-rendezvous-server');
2022-01-20 01:55:57 +08:00
const id = document.querySelector('#id');
id.value = localStorage.getItem('id');
2022-01-20 02:27:49 +08:00
const key = document.querySelector('#key');
key.value = localStorage.getItem('key');
player = YUVCanvas.attach(document.getElementById('player'));
// globals.sendOffCanvas(document.getElementById('player'));
2022-01-20 01:55:57 +08:00
};
window.connect = () => {
const host = document.querySelector('#host');
2022-01-27 01:30:29 +08:00
localStorage.setItem('custom-rendezvous-server', host.value);
2022-01-20 01:55:57 +08:00
const id = document.querySelector('#id');
localStorage.setItem('id', id.value);
2022-01-20 02:27:49 +08:00
const key = document.querySelector('#key');
localStorage.setItem('key', key.value);
2022-01-20 18:02:20 +08:00
const func = async () => {
const conn = globals.newConn();
conn.setMsgbox(msgbox);
2022-01-20 21:58:28 +08:00
conn.setDraw((f) => {
/*
if (!(document.getElementById('player').width > 0)) {
document.getElementById('player').width = f.format.displayWidth;
document.getElementById('player').height = f.format.displayHeight;
}
*/
2022-02-05 01:55:23 +08:00
globals.draw(f);
2022-01-20 21:58:28 +08:00
player.drawFrame(f);
});
2022-01-20 18:02:20 +08:00
document.querySelector('div#status').style.display = 'block';
document.querySelector('div#connect').style.display = 'none';
document.querySelector('div#text').innerHTML = 'Connecting ...';
2022-01-27 13:24:40 +08:00
await conn.start(id.value);
2022-01-20 18:02:20 +08:00
};
func();
}
2022-01-20 18:41:35 +08:00
2022-01-20 18:02:20 +08:00
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) {
2022-01-21 00:41:02 +08:00
document.querySelector('div#canvas').style.display = 'block';
document.querySelector('div#password').style.display = 'none';
2022-01-20 18:02:20 +08:00
document.querySelector('div#status').style.display = 'none';
2022-01-20 18:41:35 +08:00
} else if (type == 'error') {
2022-01-20 18:02:20 +08:00
document.querySelector('div#status').style.display = 'block';
2022-01-21 00:41:02 +08:00
document.querySelector('div#canvas').style.display = 'none';
2022-01-20 18:02:20 +08:00
document.querySelector('div#text').innerHTML = '<div style="color: red; font-weight: bold;">' + text + '</div>';
2022-01-20 18:41:35 +08:00
} else {
2022-01-21 00:41:02 +08:00
document.querySelector('div#password').style.display = 'none';
2022-01-20 18:41:35 +08:00
document.querySelector('div#status').style.display = 'block';
document.querySelector('div#text').innerHTML = '<div style="font-weight: bold;">' + text + '</div>';
2022-01-20 18:02:20 +08:00
}
2022-01-20 01:55:57 +08:00
}
window.cancel = () => {
2022-01-20 18:02:20 +08:00
globals.close();
2022-01-20 01:55:57 +08:00
document.querySelector('div#connect').style.display = 'block';
document.querySelector('div#password').style.display = 'none';
2022-01-20 18:02:20 +08:00
document.querySelector('div#status').style.display = 'none';
2022-01-21 00:41:02 +08:00
document.querySelector('div#canvas').style.display = 'none';
2022-01-20 01:55:57 +08:00
}
window.confirm = () => {
2022-01-20 18:41:35 +08:00
const password = document.querySelector('input#password').value;
if (password) {
document.querySelector('div#password').style.display = 'none';
globals.getConn().login(password);
}
2022-01-20 01:55:57 +08:00
}
}