mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-11 07:04:13 +00:00
Merge pull request #673 from DioxusLabs/jk/liveview-on-load
fix: dont send initialize until WS is connected
This commit is contained in:
commit
3824f386f7
1 changed files with 8 additions and 10 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue