diff options
Diffstat (limited to 'templates/index.html')
| -rw-r--r-- | templates/index.html | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/templates/index.html b/templates/index.html index d0b0630..ef53d74 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,9 +3,19 @@ <title>snekboxweb</title> <script language="javascript" type="text/javascript"> + let _ready = false +let snekbox_id var output; +snekbox_id = sessionStorage.getItem("snekbox_id"); +console.log(snekbox_id) +if (snekbox_id == null) { + snekbox_id = generate_id() + sessionStorage.setItem("snekbox_id", snekbox_id) + console.log(snekbox_id) +} + function init(){ output = document.getElementById("output"); websocketHandler(); @@ -13,7 +23,7 @@ function init(){ function websocketHandler(){ var here = window.location.host; - var wsUri = `ws://${here}/ws`; + var wsUri = `ws://${here}/ws/`+snekbox_id; websocket = new WebSocket(wsUri); websocket.onopen = function(evt) { onOpen(evt) }; websocket.onclose = function(evt) { onClose(evt) }; @@ -77,6 +87,13 @@ function sendFromInput(){ sendMessage(msg) } +function generate_id(){ + return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); +} + + + + window.addEventListener("load", init, false); </script> |