X-Git-Url: https://git.kengrimes.com/?p=henge%2Fkiak.git;a=blobdiff_plain;f=host.js;h=9981cc9596819d9a267d21ec095b417081956c21;hp=939c8f285971e8fc0c8e0ea56fe627742e47a0be;hb=4818299175c62e9ce3179814b0823e24ecb470a8;hpb=69de98364f738e698acf96e9a4430e702495f87f diff --git a/host.js b/host.js index 939c8f2..9981cc9 100644 --- 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