Support servers with subdirectory

This commit is contained in:
mikiher 2024-12-23 20:26:23 +02:00
parent 2452f09714
commit 16de3fdb97
4 changed files with 22 additions and 12 deletions

View file

@ -486,9 +486,8 @@ export default {
validateServerUrl(url, protocolOverride = null) { validateServerUrl(url, protocolOverride = null) {
try { try {
var urlObject = new URL(url) var urlObject = new URL(url)
var address = `${protocolOverride ? protocolOverride : urlObject.protocol}//${urlObject.hostname}` if (protocolOverride) urlObject.protocol = protocolOverride
if (urlObject.port) address += ':' + urlObject.port return urlObject.href
return address
} catch (error) { } catch (error) {
console.error('Invalid URL', error) console.error('Invalid URL', error)
return null return null

View file

@ -21,7 +21,10 @@ class AbsAudioPlayerWeb extends WebPlugin {
// Use startTime to find current track index // Use startTime to find current track index
get currentTrackIndex() { get currentTrackIndex() {
return Math.max(0, this.audioTracks.findIndex(t => Math.floor(t.startOffset) <= this.startTime && Math.floor(t.startOffset + t.duration) > this.startTime)) return Math.max(
0,
this.audioTracks.findIndex((t) => Math.floor(t.startOffset) <= this.startTime && Math.floor(t.startOffset + t.duration) > this.startTime)
)
} }
get currentTrack() { get currentTrack() {
return this.audioTracks[this.currentTrackIndex] return this.audioTracks[this.currentTrackIndex]
@ -37,7 +40,7 @@ class AbsAudioPlayerWeb extends WebPlugin {
} }
get totalDuration() { get totalDuration() {
var total = 0 var total = 0
this.audioTracks.forEach(at => total += at.duration) this.audioTracks.forEach((at) => (total += at.duration))
return total return total
} }
get playerPlaying() { get playerPlaying() {
@ -194,7 +197,8 @@ class AbsAudioPlayerWeb extends WebPlugin {
// var lastBufferTime = this.getLastBufferedTime() // var lastBufferTime = this.getLastBufferedTime()
} }
evtEnded() { evtEnded() {
if (this.currentTrackIndex < this.audioTracks.length - 1) { // Has next track if (this.currentTrackIndex < this.audioTracks.length - 1) {
// Has next track
console.log(`[AbsAudioPlayer] Track ended - loading next track ${this.currentTrackIndex + 1}`) console.log(`[AbsAudioPlayer] Track ended - loading next track ${this.currentTrackIndex + 1}`)
var nextTrack = this.audioTracks[this.currentTrackIndex + 1] var nextTrack = this.audioTracks[this.currentTrackIndex + 1]
this.playWhenReady = true this.playWhenReady = true
@ -235,7 +239,9 @@ class AbsAudioPlayerWeb extends WebPlugin {
if (!this.currentTrack) return if (!this.currentTrack) return
// When direct play track is loaded current time needs to be set // When direct play track is loaded current time needs to be set
this.trackStartTime = Math.max(0, this.startTime - (this.currentTrack.startOffset || 0)) this.trackStartTime = Math.max(0, this.startTime - (this.currentTrack.startOffset || 0))
this.player.src = `${vuexStore.getters['user/getServerAddress']}${this.currentTrack.contentUrl}?token=${vuexStore.getters['user/getToken']}` const serverAddressUrl = new URL(vuexStore.getters['user/getServerAddress'])
const serverHost = `${serverAddressUrl.protocol}//${serverAddressUrl.host}`
this.player.src = `${serverHost}${this.currentTrack.contentUrl}?token=${vuexStore.getters['user/getToken']}`
console.log(`[AbsAudioPlayer] Loading track src ${this.player.src}`) console.log(`[AbsAudioPlayer] Loading track src ${this.player.src}`)
this.player.load() this.player.load()
this.player.playbackRate = this.playbackRate this.player.playbackRate = this.playbackRate

View file

@ -26,14 +26,19 @@ class ServerSocket extends EventEmitter {
this.serverAddress = serverAddress this.serverAddress = serverAddress
this.token = token this.token = token
console.log('[SOCKET] Connect Socket', this.serverAddress) const serverUrl = new URL(serverAddress)
const serverHost = `${serverUrl.protocol}//${serverUrl.host}`
const serverPath = serverUrl.pathname === '/' ? '' : serverUrl.pathname
console.log(`[SOCKET] Connecting to ${serverHost} with path ${serverPath}/socket.io`)
const socketOptions = { const socketOptions = {
transports: ['websocket'], transports: ['websocket'],
upgrade: false, upgrade: false,
path: `${serverPath}/socket.io`
// reconnectionAttempts: 3 // reconnectionAttempts: 3
} }
this.socket = io(this.serverAddress, socketOptions) this.socket = io(serverHost, socketOptions)
this.setSocketListeners() this.setSocketListeners()
} }

View file

@ -69,7 +69,7 @@ export const getters = {
// return `http://localhost:3333/api/items/${libraryItem.id}/cover?token=${userToken}&ts=${lastUpdate}` // return `http://localhost:3333/api/items/${libraryItem.id}/cover?token=${userToken}&ts=${lastUpdate}`
} }
const url = new URL(`/api/items/${libraryItem.id}/cover`, serverAddress) const url = new URL(`${serverAddress}/api/items/${libraryItem.id}/cover`)
return `${url}?token=${userToken}&ts=${lastUpdate}${raw ? '&raw=1' : ''}` return `${url}?token=${userToken}&ts=${lastUpdate}${raw ? '&raw=1' : ''}`
}, },
getLibraryItemCoverSrcById: (state, getters, rootState, rootGetters) => (libraryItemId, placeholder = null) => { getLibraryItemCoverSrcById: (state, getters, rootState, rootGetters) => (libraryItemId, placeholder = null) => {
@ -79,7 +79,7 @@ export const getters = {
const serverAddress = rootGetters['user/getServerAddress'] const serverAddress = rootGetters['user/getServerAddress']
if (!userToken || !serverAddress) return placeholder if (!userToken || !serverAddress) return placeholder
const url = new URL(`/api/items/${libraryItemId}/cover`, serverAddress) const url = new URL(`${serverAddress}/api/items/${libraryItemId}/cover`)
return `${url}?token=${userToken}` return `${url}?token=${userToken}`
}, },
getLocalMediaProgressById: (state) => (localLibraryItemId, episodeId = null) => { getLocalMediaProgressById: (state) => (localLibraryItemId, episodeId = null) => {