2021-08-18 00:01:11 +02:00
|
|
|
<template>
|
2021-08-27 01:32:05 +02:00
|
|
|
<div v-if="streamAudiobook" id="streamContainer" class="w-full fixed bottom-0 left-0 right-0 h-40 z-40 bg-primary p-4">
|
2021-09-21 23:42:01 +02:00
|
|
|
<nuxt-link :to="`/audiobook/${streamAudiobook.id}`" class="absolute -top-16 left-4 cursor-pointer">
|
2021-08-18 00:01:11 +02:00
|
|
|
<cards-book-cover :audiobook="streamAudiobook" :width="88" />
|
2021-09-21 23:42:01 +02:00
|
|
|
</nuxt-link>
|
2021-08-18 00:01:11 +02:00
|
|
|
<div class="flex items-center pl-24">
|
|
|
|
<div>
|
2021-09-21 23:42:01 +02:00
|
|
|
<nuxt-link :to="`/audiobook/${streamAudiobook.id}`" class="hover:underline cursor-pointer">
|
|
|
|
{{ title }} <span v-if="stream && $isDev" class="text-xs text-gray-400">({{ stream.id }})</span>
|
|
|
|
</nuxt-link>
|
|
|
|
<p class="text-gray-400 text-sm hover:underline cursor-pointer" @click="filterByAuthor">by {{ author }}</p>
|
2021-08-18 00:01:11 +02:00
|
|
|
</div>
|
|
|
|
<div class="flex-grow" />
|
|
|
|
<span v-if="stream" class="material-icons px-4 cursor-pointer" @click="cancelStream">close</span>
|
|
|
|
</div>
|
|
|
|
|
2021-09-08 16:15:54 +02:00
|
|
|
<audio-player ref="audioPlayer" :chapters="chapters" :loading="isLoading" @updateTime="updateTime" @hook:mounted="audioPlayerMounted" />
|
2021-08-18 00:01:11 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2021-08-24 01:31:04 +02:00
|
|
|
audioPlayerReady: false,
|
2021-08-18 00:01:11 +02:00
|
|
|
lastServerUpdateSentSeconds: 0,
|
|
|
|
stream: null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
cover() {
|
|
|
|
if (this.streamAudiobook && this.streamAudiobook.cover) return this.streamAudiobook.cover
|
|
|
|
return 'Logo.png'
|
|
|
|
},
|
|
|
|
user() {
|
2021-08-24 01:31:04 +02:00
|
|
|
return this.$store.state.user.user
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
2021-08-19 01:31:19 +02:00
|
|
|
isLoading() {
|
|
|
|
if (!this.streamAudiobook) return false
|
|
|
|
if (this.stream) {
|
|
|
|
// IF Stream exists, set loading if stream is diff from next stream
|
|
|
|
return this.stream.audiobook.id !== this.streamAudiobook.id
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
streamAudiobook() {
|
|
|
|
return this.$store.state.streamAudiobook
|
|
|
|
},
|
|
|
|
book() {
|
|
|
|
return this.streamAudiobook ? this.streamAudiobook.book || {} : {}
|
|
|
|
},
|
2021-09-08 16:15:54 +02:00
|
|
|
chapters() {
|
|
|
|
return this.streamAudiobook ? this.streamAudiobook.chapters || [] : []
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
title() {
|
|
|
|
return this.book.title || 'No Title'
|
|
|
|
},
|
|
|
|
author() {
|
|
|
|
return this.book.author || 'Unknown'
|
|
|
|
},
|
|
|
|
streamId() {
|
|
|
|
return this.stream ? this.stream.id : null
|
|
|
|
},
|
|
|
|
playlistUrl() {
|
|
|
|
return this.stream ? this.stream.clientPlaylistUri : null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2021-09-21 23:42:01 +02:00
|
|
|
filterByAuthor() {
|
|
|
|
if (this.$route.name !== 'index') {
|
|
|
|
this.$router.push('/')
|
|
|
|
}
|
|
|
|
var settingsUpdate = {
|
|
|
|
filterBy: `authors.${this.$encode(this.author)}`
|
|
|
|
}
|
|
|
|
this.$store.dispatch('user/updateUserSettings', settingsUpdate)
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
audioPlayerMounted() {
|
2021-08-24 01:31:04 +02:00
|
|
|
this.audioPlayerReady = true
|
2021-08-18 00:01:11 +02:00
|
|
|
if (this.stream) {
|
2021-08-19 01:31:19 +02:00
|
|
|
console.log('[STREAM-CONTAINER] audioPlayerMounted w/ Stream', this.stream)
|
2021-08-18 00:01:11 +02:00
|
|
|
this.openStream()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
cancelStream() {
|
|
|
|
this.$root.socket.emit('close_stream')
|
|
|
|
},
|
|
|
|
terminateStream() {
|
|
|
|
if (this.$refs.audioPlayer) {
|
|
|
|
this.$refs.audioPlayer.terminateStream()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
openStream() {
|
|
|
|
var playOnLoad = this.$store.state.playOnLoad
|
|
|
|
console.log(`[StreamContainer] openStream PlayOnLoad`, playOnLoad)
|
|
|
|
if (!this.$refs.audioPlayer) {
|
|
|
|
console.error('NO Audio Player')
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var currentTime = this.stream.clientCurrentTime || 0
|
|
|
|
this.$refs.audioPlayer.set(this.playlistUrl, currentTime, playOnLoad)
|
2021-08-19 01:31:19 +02:00
|
|
|
if (this.stream.isTranscodeComplete) {
|
|
|
|
this.$refs.audioPlayer.setStreamReady()
|
|
|
|
}
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
|
|
|
streamProgress(data) {
|
|
|
|
if (!data.numSegments) return
|
|
|
|
var chunks = data.chunks
|
2021-09-08 16:15:54 +02:00
|
|
|
console.log(`[StreamContainer] Stream Progress ${data.percent}`)
|
2021-08-18 00:01:11 +02:00
|
|
|
if (this.$refs.audioPlayer) {
|
|
|
|
this.$refs.audioPlayer.setChunksReady(chunks, data.numSegments)
|
2021-08-21 01:29:10 +02:00
|
|
|
} else {
|
|
|
|
console.error('No Audio Ref')
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
streamOpen(stream) {
|
|
|
|
this.stream = stream
|
2021-08-19 01:31:19 +02:00
|
|
|
if (this.$refs.audioPlayer) {
|
2021-09-08 16:15:54 +02:00
|
|
|
console.log('[StreamContainer] streamOpen', stream)
|
2021-08-18 00:01:11 +02:00
|
|
|
this.openStream()
|
2021-08-24 01:31:04 +02:00
|
|
|
} else if (this.audioPlayerReady) {
|
2021-08-21 01:29:10 +02:00
|
|
|
console.error('No Audio Ref')
|
2021-08-19 01:31:19 +02:00
|
|
|
}
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
|
|
|
streamClosed(streamId) {
|
2021-09-02 02:50:18 +02:00
|
|
|
if (this.stream && (this.stream.id === streamId || streamId === 'n/a')) {
|
2021-08-18 00:01:11 +02:00
|
|
|
this.terminateStream()
|
|
|
|
this.$store.commit('clearStreamAudiobook', this.stream.audiobook.id)
|
2021-08-19 01:31:19 +02:00
|
|
|
this.stream = null
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
streamReady() {
|
2021-08-21 01:29:10 +02:00
|
|
|
console.log(`[STREAM-CONTAINER] Stream Ready`)
|
2021-08-18 00:01:11 +02:00
|
|
|
if (this.$refs.audioPlayer) {
|
|
|
|
this.$refs.audioPlayer.setStreamReady()
|
2021-08-21 01:29:10 +02:00
|
|
|
} else {
|
|
|
|
console.error('No Audio Ref')
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
updateTime(currentTime) {
|
|
|
|
var diff = currentTime - this.lastServerUpdateSentSeconds
|
|
|
|
if (diff > 4 || diff < 0) {
|
|
|
|
this.lastServerUpdateSentSeconds = currentTime
|
|
|
|
var updatePayload = {
|
|
|
|
currentTime,
|
|
|
|
streamId: this.streamId
|
|
|
|
}
|
|
|
|
this.$root.socket.emit('stream_update', updatePayload)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
streamReset({ startTime, streamId }) {
|
|
|
|
if (streamId !== this.streamId) {
|
|
|
|
console.error('resetStream StreamId Mismatch', streamId, this.streamId)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (this.$refs.audioPlayer) {
|
|
|
|
console.log(`[STREAM-CONTAINER] streamReset Received for time ${startTime}`)
|
|
|
|
this.$refs.audioPlayer.resetStream(startTime)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
#streamContainer {
|
|
|
|
box-shadow: 0px -6px 8px #1111113f;
|
|
|
|
}
|
|
|
|
</style>
|