client done
[henge/kiak.git] / host.js
diff --git a/host.js b/host.js
index 2700506..45ea63f 100644 (file)
--- a/host.js
+++ b/host.js
@@ -1,17 +1,22 @@
-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://" + _strapp_host + ":" +  _strapp_port)
+  const wsock = new WebSocket(`${_strapp_protocol}://${window.location.hostname}:${_strapp_port}`)
   wsock.onopen = () => {
-    console.log("Strapped to wss://" + _strapp_host + ":" +  _strapp_port)
+    console.log(`Strapped to ${_strapp_protocol}://${window.location.hostname}:${_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 {
-  root.appendChild(document.createTextNode("Your browser does not support Strapp"))
 }
-body.appendChild(root)
-document.body = body
+else {
+  document.addEventListener('DOMContentLoaded', () => {
+    document.body.innerHTML = 'Websockets not supported in your browser'
+  })
+}