From 4f858ebf3206431447177c977533d18dbea6dca9 Mon Sep 17 00:00:00 2001 From: Adam Hovorka Date: Wed, 17 Jul 2019 20:21:01 -0600 Subject: Enable automatic SSL/TLS on WebSocket connection --- public/main.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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"); -- cgit v1.2.3-54-g00ecf