diff options
author | Adam Hovorka <[email protected]> | 2019-07-17 20:21:01 -0600 |
---|---|---|
committer | Adam Hovorka <[email protected]> | 2019-07-17 20:21:01 -0600 |
commit | 4f858ebf3206431447177c977533d18dbea6dca9 (patch) | |
tree | 0a0e9b32fba397d6f846040ed22c3a0a2bc4434e /public/main.js | |
parent | 138ddfbed3746fe7cb03a1fcdc46fc610c098ec3 (diff) |
Enable automatic SSL/TLS on WebSocket connection
Diffstat (limited to 'public/main.js')
-rw-r--r-- | public/main.js | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/public/main.js b/public/main.js index da4083e..b3c7986 100644 --- a/public/main.js +++ b/public/main.js @@ -1,7 +1,8 @@ document.addEventListener("DOMContentLoaded", async () => { "use strict" const $ = s => document.querySelector(s); -const sock = new WebSocket(`ws://${location.host}/ws`); +const secure = location.protocol === "https:"; +const sock = new WebSocket(`ws${secure?"s":""}://${location.host}/ws`); sock.onmessage = e => console.log("sock", e); sock.onopen = () => sock.send("yay"); |