[web] Simplify WebSocket creation and remove unused translation

This commit is contained in:
Alain Nussbaumer 2025-01-18 16:54:02 +01:00
parent 9420c52bf7
commit 386ad61bc8
6 changed files with 12 additions and 48 deletions

View File

@ -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) {

View File

@ -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",

View File

@ -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",

View File

@ -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 dattente enregistrée dans la liste de lecture {name}",
"appended-tracks": "{count} piste ajoutée à la file dattente|{count} pistes ajoutées à la file dattente",

View File

@ -573,7 +573,6 @@
},
"server": {
"connection-failed": "无法连接到 OwnTone 服务器",
"missing-port": "缺少 websocket 端口",
"request-failed": "请求失败 (状态:{status} {cause} {url})",
"queue-saved": "清单以添加到播放列表 {name}",
"appended-tracks": "已附加到队列的 {count} 只曲目|已附加到队列的 {count} 只曲目",

View File

@ -573,7 +573,6 @@
},
"server": {
"connection-failed": "無法連接到 OwnTone 伺服器",
"missing-port": "缺少 websocket 端口",
"request-failed": "請求失敗 (狀態:{status} {cause} {url})",
"queue-saved": "清單以新增到播放列表 {name}",
"appended-tracks": "已附加到隊列的 {count} 首曲目|已附加到隊列的 {count} 首曲目",