failover for certs and keys
[henge/kiak.git] / host.js
diff --git a/host.js b/host.js
index 939c8f2..9981cc9 100644 (file)
--- a/host.js
+++ b/host.js
@@ -1,17 +1,24 @@
-const body = document.createElement('body')
-const root = document.createElement('div')
 document.title = "Strapp.io Host"
+const clients = []
 if ("WebSocket" in window) {
-  const wsock = new WebSocket("wss://" + window.location.host + ":" +  _strapp_port)
-  wsock.onopen = () => {
-    console.log("Strapped to wss://" + window.location.host + ":" +  _strapp_port)
-  }
-  wsock.onmessage = (evt) => {
-    console.log("Incoming connection from " + evt.data)
-    console.log("TODO: Open a socket to this client")
-  }
-} else {
-  root.appendChild(document.createTextNode("Your browser does not support Strapp"))
+  document.addEventListener('DOMContentLoaded', (event) => {
+    const wsock = new WebSocket("wss://" + window.location.host + ":" +  _strapp_port)
+    wsock.onopen = () => {
+      console.log("Strapped to wss://" + window.location.host + ":" +  _strapp_port)
+    }
+    wsock.onmessage = (evt) => {
+      console.log("Incoming connection from " + evt.data)
+      console.log("TODO: Open a socket to this client")
+      wsock.send("Got " + evt.data)
+      clients.push({
+       ip: evt.data,
+       dataChannel: undefined
+      })
+    }
+  })
+}
+else {
+  document.addEventListener('DOMContentLoaded', () => {
+    document.body.innerHTML = 'Websockets not supported in your browser'
+  })
 }
-body.appendChild(root)
-document.body = body