mirror of
https://github.com/owntone/owntone-server.git
synced 2025-11-26 04:26:14 -05:00
[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:
committed by
Alain Nussbaumer
parent
fd322a2941
commit
a3ab301cff
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user