From ba650456aaecef6651e598bbd20cc7d53d7d3f97 Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Sat, 11 Aug 2018 03:46:42 +0300 Subject: Workaround for Safari + Websockets + basic auth https://bugs.webkit.org/show_bug.cgi?id=80362 --- kvmd/web/js/session.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'kvmd/web/js/session.js') diff --git a/kvmd/web/js/session.js b/kvmd/web/js/session.js index d3bbf91c..5e4a491b 100644 --- a/kvmd/web/js/session.js +++ b/kvmd/web/js/session.js @@ -20,11 +20,19 @@ var session = new function() { }; this.startPoller = function() { - __ws = new WebSocket((location.protocol == "https:" ? "wss" : "ws") + "://" + location.host + "/kvmd/ws"); - __ws.onopen = __wsOpenHandler; - __ws.onmessage = __wsMessageHandler; - __ws.onerror = __wsErrorHandler; - __ws.onclose = __wsCloseHandler; + var http = tools.makeRequest("GET", "/wsauth", function() { + if (http.readyState === 4) { + if (http.status === 200) { + __ws = new WebSocket((location.protocol == "https:" ? "wss" : "ws") + "://" + location.host + "/kvmd/ws"); + __ws.onopen = __wsOpenHandler; + __ws.onmessage = __wsMessageHandler; + __ws.onerror = __wsErrorHandler; + __ws.onclose = __wsCloseHandler; + } else { + __wsCloseHandler(null); + } + } + }); }; var __wsOpenHandler = function(event) { -- cgit v1.2.3