Remote page now has UI and pushes settings.

This commit is contained in:
Philip Rideout
2021-03-04 18:33:44 -08:00
parent b7ad20249d
commit b554a68186
2 changed files with 38 additions and 22 deletions

View File

@@ -223,6 +223,28 @@ class MainActivity : Activity() {
choreographer.removeFrameCallback(frameScheduler)
}
fun loadModelData(message: RemoteServer.ReceivedMessage) {
Log.i(TAG, "Downloaded model ${message.label} (${message.buffer.capacity()} bytes)")
clearStatusText()
titlebarHint.text = message.label
CoroutineScope(Dispatchers.IO).launch {
try {
if (message.label.endsWith(".zip")) {
loadZip(message)
} else {
loadGlb(message)
}
} catch (exc: IOException) {
setStatusText("URL fetch failed.")
Log.e(TAG, "URL fetch failed", exc)
}
}
}
fun loadSettings(message: RemoteServer.ReceivedMessage) {
Log.i(TAG, "Downloaded settings JSON (${message.buffer.capacity()} bytes)")
}
inner class FrameCallback : Choreographer.FrameCallback {
private val startTime = System.nanoTime()
override fun doFrame(frameTimeNanos: Long) {
@@ -239,30 +261,18 @@ class MainActivity : Activity() {
modelViewer.render(frameTimeNanos)
val label = remoteServer?.peekIncomingLabel()
if (label != null) {
if (label != null && !label.endsWith(".json")) {
Log.i(TAG, "Downloading $label")
setStatusText("Downloading $label")
}
val message = remoteServer?.acquireReceivedMessage()
if (message != null) {
Log.i(TAG, "Downloaded ${message.label} ${message.buffer.capacity()}")
clearStatusText()
titlebarHint.text = message.label
CoroutineScope(Dispatchers.IO).launch {
try {
if (message.label.endsWith(".zip")) {
loadZip(message)
} else {
loadGlb(message)
}
} catch (exc: IOException) {
setStatusText("URL fetch failed.")
Log.e(TAG, "URL fetch failed", exc)
}
if (message.label.endsWith(".json")) {
loadSettings(message)
} else {
loadModelData(message)
}
}
}
}

View File

@@ -170,6 +170,7 @@ class App {
resize();
const dropbox = this.dropbox;
const upload = this.uploadFile.bind(this);
dropbox.addEventListener("dragover", dragEvent => {
dropbox.classList.add("bad");
@@ -193,7 +194,7 @@ class App {
if (!is_glb && !is_zip) return;
if (is_zip) fileType = "zip";
const files = event.dataTransfer.files;
([...files]).forEach(this.uploadFile);
([...files]).forEach(upload);
}, false);
this.startSocket();
@@ -201,10 +202,11 @@ class App {
}
uploadFile(file) {
if (websocket) {
const connection = this.websocket;
if (connection && connection.readyState == connection.OPEN) {
console.info(`Uploading ${file.name}`);
this.websocket.send(file.name);
this.websocket.send(file);
connection.send(file.name);
connection.send(file);
} else {
this.pendingFile = file;
}
@@ -273,7 +275,11 @@ class App {
const settingsJson = this.serializer.writeJson(this.simpleViewer.getSettings()).slice();
if (this.previousSettingsJson != settingsJson) {
console.info("Settings have changed.");
const connection = this.websocket;
if (connection && connection.readyState == connection.OPEN) {
connection.send("setttings.json");
connection.send(settingsJson);
}
this.previousSettingsJson = settingsJson;
}