From 77895fe51ce58a36bba015628e2bb20d986f64a4 Mon Sep 17 00:00:00 2001 From: Bagas Aulia Rezki Date: Mon, 9 Sep 2024 21:46:56 +0700 Subject: [PATCH] Fix WebSocket protocol handling based on page protocol --- public/main.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/main.js b/public/main.js index cbd2f63..2bc9ef3 100644 --- a/public/main.js +++ b/public/main.js @@ -1,5 +1,6 @@ if (!window.mySocket) { - window.mySocket = new WebSocket(`ws://${window.location.host}/user`); + const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; + window.mySocket = new WebSocket(`${wsProtocol}://${window.location.host}/user`); window.mySocket.onopen = function(event) { console.log('WebSocket is open now.');