feat: introduce simpler adapters for liveview

This commit is contained in:
Jonathan Kelley committed 2022-12-19 13:11:49 -08:00
1 parent 260c4f9778
commit aa71c111cd
12 files changed
+409 -1598

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
function main() {
let root = window.document.getElementById("main");
if (root != null) {
// create a new ipc
window.ipc = new IPC(root);
window.ipc.postMessage(serializeIpcMessage("initialize"));
}
}
class IPC {
constructor(root) {
// connect to the websocket
window.interpreter = new Interpreter(root);
this.ws = new WebSocket(WS_ADDR);
this.ws.onopen = () => {
console.log("Connected to the websocket");
};
this.ws.onerror = (err) => {
console.error("Error: ", err);
};
this.ws.onmessage = (event) => {
console.log("Received message: ", event.data);
let edits = JSON.parse(event.data);
window.interpreter.handleEdits(edits);
};
}
postMessage(msg) {
this.ws.send(msg);
}
}