fixed cosmetic server url not reflecting actual server

This commit is contained in:
ari melody 2024-01-19 04:26:57 +00:00
parent 4296ad20c8
commit a85199c970
Signed by: ari
GPG key ID: CF99829C92678188

View file

@ -91,7 +91,7 @@ to help you feel a little more comfortable, i've prepared some commands for you:
* closes any existing websocket connection and attempts to create a new one. * closes any existing websocket connection and attempts to create a new one.
* @param {string} server_url - the server websocket url to connect to. * @param {string} server_url - the server websocket url to connect to.
*/ */
export async function connect(server_url) { export async function connect(url) {
if (client && client.readyState == 1) { // OPEN if (client && client.readyState == 1) { // OPEN
client.close(); client.close();
@ -140,9 +140,18 @@ export async function connect(server_url) {
*/ */
function add_client_events(client) { function add_client_events(client) {
client.addEventListener('open', async () => { client.addEventListener('open', async () => {
console.log(`Successfully connected to ${client.url}.`); server_url = client.url;
console.log(`Successfully connected to ${server_url}.`);
server_indicator.innerText = function() {
if (client.url.startsWith("ws://"))
return client.url.slice(5, -1);
else if (client.url.startsWith("wss://"))
return client.url.slice(6, -1);
else
return client.url;
}();
server_indicator.innerText = server_url;
add_system_message(`Connection successful.\n\n`); add_system_message(`Connection successful.\n\n`);
add_system_message(`=== BEGIN SESSION ===\n\n`); add_system_message(`=== BEGIN SESSION ===\n\n`);