From 27f8fdc117cb294dfd0aed67e7214fb130f0f30e Mon Sep 17 00:00:00 2001 From: sergystepanov Date: Sat, 13 Jun 2020 09:23:01 +0300 Subject: [PATCH] Make it choose ws/wss protocol based on URL's protocol. (#196) When you open the app with https: protocol it will chose wss secured socket connection instead of hardcoded addresses / domains. --- web/js/network/socket.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/web/js/network/socket.js b/web/js/network/socket.js index f5741c7f..caf79a34 100644 --- a/web/js/network/socket.js +++ b/web/js/network/socket.js @@ -30,15 +30,10 @@ const socket = (() => { let curPacketId = ''; const init = (roomId, zone) => { - const paramString = new URLSearchParams({room_id: roomId, zone: zone}) - - // if localhost, local LAN connection - if (location.hostname === "localhost" || location.hostname === "127.0.0.1" || location.hostname.startsWith("192.168")) { - scheme = "ws" - } else { - scheme = "wss" - } - conn = new WebSocket(`${scheme}://${location.host}/ws?${paramString.toString()}`); + const params = new URLSearchParams({room_id: roomId, zone: zone}).toString() + const address = `${location.protocol !== 'https:' ? 'ws' : 'wss'}://${location.host}/ws?${params}`; + console.info(`[ws] connecting to ${address}`); + conn = new WebSocket(address); // Clear old roomID conn.onopen = () => {