Ver Fonte

feature: Websocket URL is now relocatable (#322)

* feature: Websocket URL is now relocatable

* feature: Websocket URL is now relocatable
James Read há 2 anos atrás
pai
commit
c70cc864ee
1 ficheiros alterados com 9 adições e 4 exclusões
  1. 9 4
      webui.dev/js/websocket.js

+ 9 - 4
webui.dev/js/websocket.js

@@ -9,14 +9,19 @@ export function checkWebsocketConnection () {
 function reconnectWebsocket () {
 function reconnectWebsocket () {
   window.websocketAvailable = false
   window.websocketAvailable = false
 
 
-  let proto = 'ws:'
+  const websocketConnectionUrl = new URL(window.location.toString())
+  websocketConnectionUrl.hash = ''
+  websocketConnectionUrl.pathname += 'websocket'
 
 
   if (window.location.protocol === 'https:') {
   if (window.location.protocol === 'https:') {
-    proto = 'wss:'
+    websocketConnectionUrl.protocol = 'wss'
+  } else {
+    websocketConnectionUrl.protocol = 'ws'
   }
   }
 
 
-  const websocketConnectionUrl = proto + window.location.host + '/websocket'
-  const ws = window.ws = new WebSocket(websocketConnectionUrl)
+  window.websocketConnectionUrl = websocketConnectionUrl
+
+  const ws = window.ws = new WebSocket(websocketConnectionUrl.toString())
 
 
   ws.addEventListener('open', websocketOnOpen)
   ws.addEventListener('open', websocketOnOpen)
   ws.addEventListener('message', websocketOnMessage)
   ws.addEventListener('message', websocketOnMessage)