From fb87fc0bcf0187cfb84e505077d0b76fff487c39 Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Sat, 6 Jun 2020 10:47:48 -0600 Subject: [PATCH] Connect to websocket from server --- frontend/src/app.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/frontend/src/app.ts b/frontend/src/app.ts index a295f7a..456c261 100644 --- a/frontend/src/app.ts +++ b/frontend/src/app.ts @@ -10,3 +10,20 @@ term.open(document.getElementById("terminal")); fitAddon.fit(); window.addEventListener("resize", () => fitAddon.fit()); + +const socket = new WebSocket( + (document.location.protocol === "http:" ? "ws://" : "wss://") + + document.location.host + + "/api/v1/ws" +); + +socket.onopen = () => console.log("Successfully connected to server"); +socket.onmessage = (event) => console.log(event); +socket.onclose = (event) => { + if (event.wasClean) { + console.log("Connection closed cleanly"); + } else { + console.error("Connection died"); + } +}; +socket.onerror = (event) => console.error("Connection error:", event);