Kaynağa Gözat

Используем протокол WSS при необходимости

Book Pauk 5 yıl önce
ebeveyn
işleme
fdbf508bbf
1 değiştirilmiş dosya ile 6 ekleme ve 1 silme
  1. 6 1
      client/api/WebSocketConnection.js

+ 6 - 1
client/api/WebSocketConnection.js

@@ -57,7 +57,12 @@ class WebSocketConnection {
             if (this.ws && this.ws.readyState == WebSocket.OPEN) {
                 resolve(this.ws);
             } else {
-                url = url || `ws://${window.location.host}/ws`;
+                let protocol = 'ws:';
+                if (window.location.protocol == 'https:') {
+                    protocol = 'wss:'
+                }
+
+                url = url || `${protocol}//${window.location.host}/ws`;
                 
                 this.ws = new WebSocket(url);