chore: send message when websocket is open
This commit is contained in:
1 parent
651ab3e7e3
commit
19d0a9af28
1 file changed
+8
-10
@@ -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 = () => {
|
||||
window.ipc.postMessage(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) {
|
||||
|
||||
Reference in new issue
Block a user