diff --git a/web-src/src/App.vue b/web-src/src/App.vue index 7bc4e372..f2bb5196 100644 --- a/web-src/src/App.vue +++ b/web-src/src/App.vue @@ -141,7 +141,7 @@ export default { this.configurationStore.$state = data this.uiStore.hide_singles = data.hide_singles document.title = data.library_name - this.open_ws() + this.open_websocket() this.$Progress.finish() }) .catch(() => { @@ -152,10 +152,8 @@ export default { }) }) }, - open_ws() { - const wsPort = this.configurationStore.websocket_port - const socket = wsPort <= 0 ? this.create_websocket() : this.create_websocket_with_port(wsPort) - + open_websocket() { + const socket = this.create_websocket() const vm = this socket.onopen = () => { vm.reconnect_attempts = 0 @@ -255,47 +253,18 @@ export default { } }, create_websocket() { - // Create websocket connection on the same http connection - const wsHost = window.location.hostname - const wsPath = '/ws' - const wsPort = window.location.port - - let wsProtocol = 'ws://' - if (window.location.protocol === 'https:') { - wsProtocol = 'wss://' - } - - const wsUrl = `${wsProtocol}${wsHost}:${wsPort}${wsPath}` - - const socket = new ReconnectingWebSocket(wsUrl, 'notify', { + const protocol = window.location.protocol.replace('http', 'ws') + const hostname = + (import.meta.env.DEV && + URL.parse(import.meta.env.VITE_OWNTONE_URL)?.hostname) || + window.location.hostname + const suffix = + this.configurationStore.websocket_port || `${window.location.port}/ws` + const url = `${protocol}${hostname}:${suffix}` + return new ReconnectingWebSocket(url, 'notify', { maxReconnectInterval: 2000, reconnectInterval: 1000 }) - return socket - }, - create_websocket_with_port(port) { - // Create websocket connection on a separate http port - let protocol = 'ws://' - if (window.location.protocol === 'https:') { - protocol = 'wss://' - } - - let wsUrl = `${protocol}${window.location.hostname}:${port}` - - if (import.meta.env.DEV && import.meta.env.VITE_OWNTONE_URL) { - /* - * If we are running in development mode, construct the websocket - * url from the host of the environment variable VITE_OWNTONE_URL - */ - const url = new URL(import.meta.env.VITE_OWNTONE_URL) - wsUrl = `${protocol}${url.hostname}:${port}` - } - - const socket = new ReconnectingWebSocket(wsUrl, 'notify', { - maxReconnectInterval: 2000, - reconnectInterval: 1000 - }) - return socket }, update_is_clipped() { if (this.show_burger_menu || this.show_player_menu) { diff --git a/web-src/src/i18n/de.json b/web-src/src/i18n/de.json index 2ffa21d3..f3d01e17 100644 --- a/web-src/src/i18n/de.json +++ b/web-src/src/i18n/de.json @@ -574,7 +574,6 @@ }, "server": { "connection-failed": "Fehler bei Verbindung zum OwnTone-Server", - "missing-port": "Fehlender Websocket-Port", "request-failed": "Anfrage gescheitert (Status: {status} {cause} {url})", "queue-saved": "Warteschlange zu Playlist {name} gesichert", "appended-tracks": "{count} Track an die Abspielliste angehängt|{count} Tracks an die Abspielliste angehängt", diff --git a/web-src/src/i18n/en.json b/web-src/src/i18n/en.json index aad0333a..282d1d64 100644 --- a/web-src/src/i18n/en.json +++ b/web-src/src/i18n/en.json @@ -573,7 +573,6 @@ }, "server": { "connection-failed": "Failed to connect to OwnTone server", - "missing-port": "Missing websocket port", "request-failed": "Request failed (status: {status} {cause} {url})", "queue-saved": "Queue saved to playlist {name}", "appended-tracks": "{count} track appended to the queue|{count} tracks appended to the queue", diff --git a/web-src/src/i18n/fr.json b/web-src/src/i18n/fr.json index b31aa317..54e3971b 100644 --- a/web-src/src/i18n/fr.json +++ b/web-src/src/i18n/fr.json @@ -573,7 +573,6 @@ }, "server": { "connection-failed": "Échec de connexion au serveur", - "missing-port": "Port websocket manquant", "request-failed": "La requête a échoué (status: {status} {cause} {url})", "queue-saved": "La file d’attente enregistrée dans la liste de lecture {name}", "appended-tracks": "{count} piste ajoutée à la file d’attente|{count} pistes ajoutées à la file d’attente", diff --git a/web-src/src/i18n/zh-CN.json b/web-src/src/i18n/zh-CN.json index 5b6d0588..2bd7b07f 100644 --- a/web-src/src/i18n/zh-CN.json +++ b/web-src/src/i18n/zh-CN.json @@ -573,7 +573,6 @@ }, "server": { "connection-failed": "无法连接到 OwnTone 服务器", - "missing-port": "缺少 websocket 端口", "request-failed": "请求失败 (状态:{status} {cause} {url})", "queue-saved": "清单以添加到播放列表 {name}", "appended-tracks": "已附加到队列的 {count} 只曲目|已附加到队列的 {count} 只曲目", diff --git a/web-src/src/i18n/zh-TW.json b/web-src/src/i18n/zh-TW.json index 9e5a9cdc..6d8f664a 100644 --- a/web-src/src/i18n/zh-TW.json +++ b/web-src/src/i18n/zh-TW.json @@ -573,7 +573,6 @@ }, "server": { "connection-failed": "無法連接到 OwnTone 伺服器", - "missing-port": "缺少 websocket 端口", "request-failed": "請求失敗 (狀態:{status} {cause} {url})", "queue-saved": "清單以新增到播放列表 {name}", "appended-tracks": "已附加到隊列的 {count} 首曲目|已附加到隊列的 {count} 首曲目",