diff options
Diffstat (limited to 'lambda-calcul/haskell/public')
| -rw-r--r-- | lambda-calcul/haskell/public/repl.js | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lambda-calcul/haskell/public/repl.js b/lambda-calcul/haskell/public/repl.js index fd1244a..22068f1 100644 --- a/lambda-calcul/haskell/public/repl.js +++ b/lambda-calcul/haskell/public/repl.js @@ -1,10 +1,21 @@ var websocket = undefined; +function generateRandomToken() { + const array = new Uint8Array(16); + window.crypto.getRandomValues(array); + return Array.from(array, dec => ('0' + dec.toString(16)).substr(-2)).join(''); +} + function connect() { websocket = (function() { const host = window.location.host; + const params = new URLSearchParams(window.location.search); + let token = generateRandomToken(); + if (params.has("token")) { + token = params.get("token"); + } const protocol = window.location.protocol === "https:" ? "wss:" : "ws:"; - const ws = new WebSocket(protocol + "//" + host + "/repl/1235"); + const ws = new WebSocket(protocol + "//" + host + "/repl/" + token); ws.binaryType = "arraybuffer"; return ws; })(); |
