diff --git a/src/jsMain/kotlin/net/kyori/adventure/webui/js/Main.kt b/src/jsMain/kotlin/net/kyori/adventure/webui/js/Main.kt index 3159b3b..c6abe88 100644 --- a/src/jsMain/kotlin/net/kyori/adventure/webui/js/Main.kt +++ b/src/jsMain/kotlin/net/kyori/adventure/webui/js/Main.kt @@ -136,18 +136,7 @@ public fun mainLoaded() { ) // WEBSOCKET - webSocket = - if (window.location.hostname == "localhost" || - window.location.hostname == "127.0.0.1" - ) { - WebSocket("ws://${window.location.host}$URL_API$URL_MINI_TO_HTML") - } else { - WebSocket("wss://${window.location.host}$URL_API$URL_MINI_TO_HTML") - } - webSocket.onopen = { onWebsocketReady() } - webSocket.onclose = { onWebsocketClose() } - // A closed websocket will be handled by the above, but log the error to console for debugging sake - webSocket.onerror = { err -> console.log("Websocket error: $err") } + startWebsocket() // CORRECT HOME LINK document.element("home-link").href = homeUrl @@ -416,6 +405,18 @@ private fun readPlaceholders(): Placeholders { return Placeholders(stringPlaceholders = stringPlaceholders) } +private fun startWebsocket() { + webSocket = if (window.location.hostname == "localhost" || window.location.hostname == "127.0.0.1") { + WebSocket("ws://${window.location.host}$URL_API$URL_MINI_TO_HTML") + } else { + WebSocket("wss://${window.location.host}$URL_API$URL_MINI_TO_HTML") + } + webSocket.onopen = { onWebsocketReady() } + webSocket.onclose = { startWebsocket() } + // A closed websocket will be handled by the above, but log the error to console for debugging sake + webSocket.onerror = { err -> console.log("Websocket error: $err") } +} + private fun onWebsocketReady() { // SHARING val inputBox = document.element("input") @@ -494,16 +495,6 @@ private fun onWebsocketReady() { } } -private fun onWebsocketClose() { - // We no longer have a working websocket connection, so any input changes would not go through. Display a little - // warning to the user and disable the input box to bring more attention to it, since changing the input would - // have no effect at this point anyway. - val warning = document.element("connection-lost-warning") - val inputBox = document.element("input") - warning.hidden = false - inputBox.disabled = true -} - private fun checkClickEvents(target: EventTarget?, typesToCheck: Collection) { if (target is HTMLSpanElement && target.classList.contains(COMPONENT_CLASS)) { val remainingTypesToCheck = mutableSetOf()