Merge pull request #673 from DioxusLabs/jk/liveview-on-load

fix: dont send initialize until WS is connected
This commit is contained in:
Jon Kelley 2022-12-22 11:34:54 -05:00 committed by GitHub
commit 3824f386f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,10 +1,7 @@
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"));
}
}
@ -13,21 +10,22 @@ class IPC {
// connect to the websocket
window.interpreter = new Interpreter(root);
this.ws = new WebSocket(WS_ADDR);
let ws = new WebSocket(WS_ADDR);
this.ws.onopen = () => {
console.log("Connected to the websocket");
ws.onopen = () => {
ws.send(serializeIpcMessage("initialize"));
};
this.ws.onerror = (err) => {
console.error("Error: ", err);
ws.onerror = (err) => {
// todo: retry the connection
};
this.ws.onmessage = (event) => {
console.log("Received message: ", event.data);
ws.onmessage = (event) => {
let edits = JSON.parse(event.data);
window.interpreter.handleEdits(edits);
};
this.ws = ws;
}
postMessage(msg) {