From 04932317f68a969e9ade623714bbf893d3655978 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 31 May 2021 18:11:33 +0200 Subject: [PATCH] Populate server URL in fillConnectParams --- components/app.js | 36 ++++++++++++++++++------------------ components/connect-form.js | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/components/app.js b/components/app.js index 8876b9e..0f55d68 100644 --- a/components/app.js +++ b/components/app.js @@ -51,7 +51,23 @@ function parseQueryString() { } function fillConnectParams(params) { + var host = window.location.host || "localhost:8080"; + var proto = "wss:"; + if (window.location.protocol != "https:") { + proto = "ws:"; + } + var path = window.location.pathname || "/"; + if (!window.location.host) { + path = "/"; + } + params = { ...params }; + if (!params.url) { + params.url = proto + "//" + host + path + "socket"; + } + if (params.url.startsWith("/")) { + params.url = proto + "//" + host + params.url; + } if (!params.username) { params.username = params.nick; } @@ -241,19 +257,7 @@ export default class App extends Component { handleConfig(config) { this.config = config; - var host = window.location.host || "localhost:8080"; - var proto = "wss:"; - if (window.location.protocol != "https:") { - proto = "ws:"; - } - var path = window.location.pathname || "/"; - if (!window.location.host) { - path = "/"; - } - - var connectParams = { - url: proto + "//" + host + path + "socket", - }; + var connectParams = {}; if (config.server) { connectParams.url = config.server.url; @@ -275,11 +279,7 @@ export default class App extends Component { var queryParams = parseQueryString(); if (queryParams.server) { - if (queryParams.server.startsWith("/")) { - connectParams.url = proto + "//" + host + queryParams.server; - } else { - connectParams.url = queryParams.server; - } + connectParams.url = queryParams.server; } if (queryParams.nick) { connectParams.nick = queryParams.nick; diff --git a/components/connect-form.js b/components/connect-form.js index c83cca4..f8c9b04 100644 --- a/components/connect-form.js +++ b/components/connect-form.js @@ -103,7 +103,7 @@ export default class ConnectForm extends Component {