Smarter server URL auto-detection

This commit is contained in:
Simon Ser 2020-06-07 13:46:46 +02:00
parent 1a1c3f9052
commit 73723f6696
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
2 changed files with 11 additions and 2 deletions

View file

@ -410,10 +410,19 @@ if (localStorage && localStorage.getItem("server")) {
connect(); connect();
} else { } else {
var params = parseQueryString(); var params = parseQueryString();
if (params.server) { if (params.server) {
connectFormElt.elements.url.value = params.server;
document.querySelector("#connect-url-container").style.display = "none"; document.querySelector("#connect-url-container").style.display = "none";
connectFormElt.elements.url.value = params.server;
} else if (!connectFormElt.elements.url.value) {
var host = window.location.host || "localhost:8080";
var proto = "wss:";
if (window.location.protocol != "https:") {
proto = "ws:";
}
connectFormElt.elements.url.value = proto + "//" + host + "/socket";
} }
if (params.channels) { if (params.channels) {
connectFormElt.elements.autojoin.value = params.channels; connectFormElt.elements.autojoin.value = params.channels;
} }

View file

@ -28,7 +28,7 @@
<div id="connect-url-container"> <div id="connect-url-container">
<label for="connect-url">Server URL:</label><br/> <label for="connect-url">Server URL:</label><br/>
<input type="url" name="url" id="connect-url" value="ws://localhost:8080"/> <input type="url" name="url" id="connect-url"/>
<br/><br/> <br/><br/>
</div> </div>