From e637fe5550d24c5429bfb4e66c6ee1f794e2e313 Mon Sep 17 00:00:00 2001 From: Mia <49593536+mia-pi-git@users.noreply.github.com> Date: Sat, 7 Jan 2023 16:35:05 -0600 Subject: [PATCH] Bypass https on localhost (#2078) --- js/client.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/js/client.js b/js/client.js index 399031b74..1ac606188 100644 --- a/js/client.js +++ b/js/client.js @@ -393,6 +393,8 @@ function toId() { }, focused: true, initialize: function () { + // Gotta cache this since backbone removes it + this.query = window.location.search; window.app = this; this.initializeRooms(); this.initializePopups(); @@ -753,11 +755,15 @@ function toId() { // anyway, this affects SockJS because it makes HTTP requests to localhost // but it turns out that making direct WebSocket connections to localhost is // still supported, so we'll just bypass SockJS and use WebSocket directly. + var possiblePort = new URL(document.location + self.query).searchParams.get('port'); + // We need to bypass the port as well because on most modern browsers, http gets forced + // to https, which means a ws connection is made to port 443 instead of wherever it's actually running, + // thus ensuring a failed connection. + var port = possiblePort || Config.server.port; console.log("Bypassing SockJS for localhost"); - console.log('ws' + protocol.slice('4') + '://' + Config.server.host + ':' + Config.server.port + Config.sockjsprefix + '/websocket'); - return new WebSocket( - 'ws' + protocol.slice('4') + '://' + Config.server.host + ':' + Config.server.port + Config.sockjsprefix + '/websocket' - ); + var url = 'ws://' + Config.server.host + ':' + port + Config.sockjsprefix + '/websocket'; + console.log(url); + return new WebSocket(url); } return new SockJS( protocol + '://' + Config.server.host + ':' + Config.server.port + Config.sockjsprefix,