Add:Chromecast support in experimental #367, Change:Audio player model for direct play

This commit is contained in:
advplyr 2022-02-22 17:33:55 -06:00
parent 9f133ba98c
commit 89f498f31a
26 changed files with 1113 additions and 672 deletions

View file

@ -178,6 +178,8 @@ class ApiController {
this.router.post('/syncStream', this.syncStream.bind(this))
this.router.post('/syncLocal', this.syncLocal.bind(this))
this.router.post('/streams/:id/close', this.closeStream.bind(this))
}
async findBooks(req, res) {
@ -397,6 +399,7 @@ class ApiController {
data: audiobookProgress || null
})
}
res.sendStatus(200)
}
//
@ -518,5 +521,12 @@ class ApiController {
await this.cacheManager.purgeAll()
res.sendStatus(200)
}
async closeStream(req, res) {
const streamId = req.params.id
const userId = req.user.id
this.streamManager.closeStreamApiRequest(userId, streamId)
res.sendStatus(200)
}
}
module.exports = ApiController

View file

@ -260,7 +260,6 @@ class Server {
// Streaming
socket.on('open_stream', (audiobookId) => this.streamManager.openStreamSocketRequest(socket, audiobookId))
socket.on('close_stream', () => this.streamManager.closeStreamRequest(socket))
socket.on('stream_update', (payload) => this.streamManager.streamUpdate(socket, payload))
socket.on('stream_sync', (syncData) => this.streamManager.streamSync(socket, syncData))
socket.on('progress_update', (payload) => this.audiobookProgressUpdate(socket, payload))

View file

@ -155,6 +155,30 @@ class StreamManager {
this.emitter('user_stream_update', client.user.toJSONForPublic(this.streams))
}
async closeStreamApiRequest(userId, streamId) {
Logger.info('[StreamManager] Close Stream Api Request', streamId)
var stream = this.streams.find(s => s.id === streamId)
if (!stream) {
Logger.warn('[StreamManager] Stream not found', streamId)
return
}
if (!stream.client || !stream.client.user || stream.client.user.id !== userId) {
Logger.warn(`[StreamManager] Stream close request from invalid user ${userId}`, stream.client)
return
}
stream.client.user.stream = null
stream.client.stream = null
this.db.updateUserStream(stream.client.user.id, null)
await stream.close()
this.streams = this.streams.filter(s => s.id !== streamId)
Logger.info(`[StreamManager] Stream ${streamId} closed via API request by ${userId}`)
}
streamSync(socket, syncData) {
const client = socket.sheepClient
if (!client || !client.stream) {
@ -233,35 +257,5 @@ class StreamManager {
res.sendStatus(200)
}
streamUpdate(socket, { currentTime, streamId }) {
var client = socket.sheepClient
if (!client || !client.stream) {
Logger.error('No stream for client', (client && client.user) ? client.user.id : 'No Client')
return
}
if (client.stream.id !== streamId) {
Logger.error('Stream id mismatch on stream update', streamId, client.stream.id)
return
}
client.stream.updateClientCurrentTime(currentTime)
if (!client.user) {
Logger.error('No User for client', client)
return
}
if (!client.user.updateAudiobookProgressFromStream) {
Logger.error('Invalid User for client', client)
return
}
var userAudiobook = client.user.updateAudiobookProgressFromStream(client.stream)
this.db.updateEntity('user', client.user)
if (userAudiobook) {
this.clientEmitter(client.user.id, 'current_user_audiobook_update', {
id: userAudiobook.audiobookId,
data: userAudiobook.toJSON()
})
}
}
}
module.exports = StreamManager

View file

@ -39,7 +39,7 @@ class ServerSettings {
this.bookshelfView = BookshelfView.STANDARD
this.sortingIgnorePrefix = false
this.chromecastEnabled = false
this.logLevel = Logger.logLevel
this.version = null
@ -73,7 +73,7 @@ class ServerSettings {
this.bookshelfView = settings.bookshelfView || BookshelfView.STANDARD
this.sortingIgnorePrefix = !!settings.sortingIgnorePrefix
this.chromecastEnabled = !!settings.chromecastEnabled
this.logLevel = settings.logLevel || Logger.logLevel
this.version = settings.version || null
@ -104,6 +104,7 @@ class ServerSettings {
coverAspectRatio: this.coverAspectRatio,
bookshelfView: this.bookshelfView,
sortingIgnorePrefix: this.sortingIgnorePrefix,
chromecastEnabled: this.chromecastEnabled,
logLevel: this.logLevel,
version: this.version
}

View file

@ -175,11 +175,6 @@ class Stream extends EventEmitter {
return false
}
updateClientCurrentTime(currentTime) {
Logger.debug('[Stream] Updated client current time', secondsToTimestamp(currentTime))
this.clientCurrentTime = currentTime
}
syncStream({ timeListened, currentTime }) {
var syncLog = ''
// Set user current time