From 6f1e3c19dbbde97816c73b4b95f7f9b5fa675eb9 Mon Sep 17 00:00:00 2001 From: Gandharv Date: Fri, 5 Nov 2021 15:11:00 +0530 Subject: [PATCH] add websocket url fallback as window.location.host (#1374) --- frontend/src/Editor/Editor.jsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/src/Editor/Editor.jsx b/frontend/src/Editor/Editor.jsx index 867fcc632a..0474eaead7 100644 --- a/frontend/src/Editor/Editor.jsx +++ b/frontend/src/Editor/Editor.jsx @@ -107,9 +107,16 @@ class Editor extends React.Component { } } + getWebsocketUrl = () => { + const re = /https?:\/\//g; + if (re.test(config.apiUrl)) return config.apiUrl.replace(/(^\w+:|^)\/\//, '').replace('/api', ''); + + return window.location.host; + }; + initWebSocket = () => { // TODO: add retry policy - const socket = new WebSocket(`ws://${config.apiUrl.replace(/(^\w+:|^)\/\//, '').replace('/api', '')}`); + const socket = new WebSocket(`ws://${this.getWebsocketUrl()}`); // Connection opened socket.addEventListener('open', function (event) {