add websocket url fallback as window.location.host (#1374)

This commit is contained in:
Gandharv 2021-11-05 15:11:00 +05:30 committed by GitHub
parent 5055aed8e6
commit 6f1e3c19db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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) {