190 lines
5.6 KiB
HTML
190 lines
5.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<title>Filament Remote</title>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1">
|
|
<link href="../favicon.png" rel="icon" type="image/x-icon" />
|
|
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" rel="stylesheet">
|
|
<style>
|
|
html, body {
|
|
height: 100%;
|
|
}
|
|
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.container {
|
|
font-family: "Open Sans";
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: center;
|
|
align-items: center;
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
.status-area {
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
width: 100%;
|
|
height: 100%;
|
|
max-width: 512px;
|
|
max-height: 32px;
|
|
background: burlywood;
|
|
border: solid 2px black;
|
|
border-bottom: none;
|
|
font-size: 12px;
|
|
}
|
|
|
|
.dropbox-area {
|
|
flex-direction: column;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
width: 100%;
|
|
height: 100%;
|
|
max-width: 512px;
|
|
max-height: 512px;
|
|
background: rgb(189, 189, 189);
|
|
border: solid 2px black;
|
|
}
|
|
|
|
.dropbox-area p { text-align: center; }
|
|
|
|
a { text-decoration: none;}
|
|
a:visited { color: rgb(26, 65, 78);}
|
|
.bad { background: lightcoral; }
|
|
.good { background: #45d48d; }
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
<div class="container">
|
|
<div id="status" class="status-area">Disconnected</div>
|
|
<div id="dropbox" class="dropbox-area">
|
|
<div>
|
|
<p>Drop a <b>glb</b> or a <b>zip</b> file here.</p>
|
|
</div>
|
|
</div>
|
|
<div id="instructions" class="instructions-area">
|
|
<p><code>adb forward tcp:8082 tcp:8082</code></p>
|
|
<button id="copyButton">Copy adb command to clipboard</button>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
|
|
document.getElementById("copyButton").addEventListener("click", () => {
|
|
navigator.clipboard.writeText("adb forward tcp:8082 tcp:8082");
|
|
});
|
|
|
|
const dropbox = document.getElementById("dropbox");
|
|
const status = document.getElementById("status");
|
|
|
|
let websocket = null;
|
|
let pollForServer = null;
|
|
let widgetsDb = [];
|
|
let pendingFile = null;
|
|
let fileType = "glb";
|
|
|
|
["dragenter", "dragover", "dragleave", "drop"].forEach(eventName => {
|
|
dropbox.addEventListener(eventName, e => { e.preventDefault(); e.stopPropagation() }, false)
|
|
})
|
|
|
|
dropbox.addEventListener("dragover", dragEvent => {
|
|
dropbox.classList.add("bad");
|
|
if (!event.dataTransfer) return;
|
|
if (event.dataTransfer.items[0].kind !== "file") return;
|
|
dropbox.classList.remove("bad");
|
|
dropbox.classList.add("good");
|
|
}, false);
|
|
|
|
dropbox.addEventListener("dragleave", () => {
|
|
dropbox.classList.remove("good", "bad");
|
|
}, false);
|
|
|
|
dropbox.addEventListener("drop", dragEvent => {
|
|
dropbox.classList.remove("good", "bad");
|
|
if (!event.dataTransfer) return;
|
|
if (event.dataTransfer.items[0].kind !== "file") return;
|
|
const file = event.dataTransfer.items[0].getAsFile();
|
|
const is_glb = file.name.match(/\.(glb)$/i);
|
|
const is_zip = file.name.match(/\.(zip)$/i);
|
|
if (!is_glb && !is_zip) return;
|
|
if (is_zip) fileType = "zip";
|
|
const files = event.dataTransfer.files;
|
|
([...files]).forEach(uploadFile);
|
|
}, false);
|
|
|
|
function uploadFile(file) {
|
|
if (websocket) {
|
|
console.info(`Uploading ${file.name}`);
|
|
websocket.send(file.name);
|
|
websocket.send(file);
|
|
} else {
|
|
pendingFile = file;
|
|
}
|
|
}
|
|
|
|
function updateDom() {
|
|
status.innerHTML = websocket ? "Connected" : "Disconnected";
|
|
status.style.backgroundColor = websocket ? "#45d48d" : "burlywood";
|
|
}
|
|
|
|
function resetWidgetsDb() {
|
|
widgetsDb = [];
|
|
}
|
|
|
|
function startSocket() {
|
|
const ws = new WebSocket("ws://localhost:8082");
|
|
|
|
ws.addEventListener("open", () => {
|
|
clearTimeout(pollForServer);
|
|
resetWidgetsDb();
|
|
updateDom();
|
|
if (pendingFile) {
|
|
uploadFile(pendingFile);
|
|
pendingFile = null;
|
|
}
|
|
});
|
|
|
|
ws.addEventListener("close", (e) => {
|
|
websocket = null;
|
|
pollForServer = setTimeout(() => startSocket(), 3000);
|
|
resetWidgetsDb();
|
|
updateDom();
|
|
});
|
|
|
|
ws.addEventListener("message", event => {
|
|
if (!event.data) {
|
|
return;
|
|
}
|
|
let commands = [];
|
|
try {
|
|
commands = JSON.parse(event.data);
|
|
}
|
|
catch (err) {
|
|
console.error(err, event.data);
|
|
return;
|
|
}
|
|
for (const command of commands) {
|
|
// TODO
|
|
}
|
|
});
|
|
|
|
websocket = ws;
|
|
}
|
|
|
|
startSocket();
|
|
|
|
</script>
|
|
</body>
|
|
|
|
</html> |