From 6d99951fe71525a5ad7ff29b24d7ff128fa98903 Mon Sep 17 00:00:00 2001 From: hippoz Date: Mon, 22 Mar 2021 21:08:52 +0200 Subject: [PATCH] frontend: store gateway url as localstorage value --- brainlet/app/gatewaytest/app.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/brainlet/app/gatewaytest/app.js b/brainlet/app/gatewaytest/app.js index a62ee0e..446c77b 100644 --- a/brainlet/app/gatewaytest/app.js +++ b/brainlet/app/gatewaytest/app.js @@ -41,8 +41,8 @@ const getOpcodeByName = (name) => { class GatewayConnection { - constructor(token) { - this.ws = new WebSocket(`ws://${window.location.hostname}/gateway?v=2`); + constructor(token, gatewayUrl) { + this.ws = new WebSocket(gatewayUrl); this.handshakeCompleted = false; this.sessionInformation = null; @@ -116,8 +116,8 @@ GatewayConnection.prototype.fire = function(eventName, ...args) { class AppState { - constructor(token) { - this.connection = new GatewayConnection(token); + constructor(token, gatewayUrl) { + this.connection = new GatewayConnection(token, gatewayUrl); this.tc = new Tricarbon(); this.elements = { @@ -201,5 +201,6 @@ AppState.prototype.renderSidebar = function(channels) { let app; document.addEventListener("DOMContentLoaded", () => { - app = new AppState(localStorage.getItem("token")); + if (!localStorage.getItem("gatewayUrl")) localStorage.setItem("gatewayUrl", `ws://${window.location.hostname}/gateway?v=2`); + app = new AppState(localStorage.getItem("token"), localStorage.getItem("gatewayUrl")); }); \ No newline at end of file