[web] Support libevent as WS server instead of libwebsockets

If libevent >= 2.2 is detected during configure and "websocket_port" == 0 in the config file, the libwebsocket implementation is disabled and instead the libevent http server offers the websocket connection. The connection to the websocket is then done with the path "/ws".
This commit is contained in:
Christian Meffert
2024-10-03 07:47:34 +02:00
committed by Alain Nussbaumer
parent fd322a2941
commit a3ab301cff
8 changed files with 408 additions and 30 deletions

View File

@@ -153,34 +153,8 @@ export default {
})
},
open_ws() {
if (this.configurationStore.websocket_port <= 0) {
this.notificationsStore.add({
text: this.$t('server.missing-port'),
type: 'danger'
})
return
}
let protocol = 'ws://'
if (window.location.protocol === 'https:') {
protocol = 'wss://'
}
let wsUrl = `${protocol}${window.location.hostname}:${this.configurationStore.websocket_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}:${this.configurationStore.websocket_port}`
}
const socket = new ReconnectingWebSocket(wsUrl, 'notify', {
maxReconnectInterval: 2000,
reconnectInterval: 1000
})
const wsPort = this.configurationStore.websocket_port
const socket = wsPort <= 0 ? this.create_websocket() : this.create_websocket_with_port(wsPort)
const vm = this
socket.onopen = () => {
@@ -280,6 +254,49 @@ 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', {
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) {
document.querySelector('html').classList.add('is-clipped')