Merge branch 'advplyr:master' into seekback-support

This commit is contained in:
svdztn 2021-10-26 10:53:01 +08:00 committed by GitHub
commit 28b1132171
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 14 deletions

View File

@ -178,6 +178,7 @@ export default {
this.$store.commit('users/updateUser', user)
},
currentUserAudiobookUpdate(payload) {
// console.log('Received user audiobook update', payload)
this.$store.commit('user/updateUserAudiobook', payload)
},
downloadToastClick(download) {

View File

@ -1,6 +1,6 @@
{
"name": "audiobookshelf-client",
"version": "1.5.2",
"version": "1.5.3",
"description": "Audiobook manager and player",
"main": "index.js",
"scripts": {

View File

@ -1,6 +1,6 @@
{
"name": "audiobookshelf",
"version": "1.5.2",
"version": "1.5.3",
"description": "Self-hosted audiobook server for managing and playing audiobooks",
"main": "index.js",
"scripts": {

View File

@ -46,7 +46,7 @@ class Server {
this.watcher = new Watcher(this.AudiobookPath)
this.coverController = new CoverController(this.db, this.MetadataPath, this.AudiobookPath)
this.scanner = new Scanner(this.AudiobookPath, this.MetadataPath, this.db, this.coverController, this.emitter.bind(this))
this.streamManager = new StreamManager(this.db, this.MetadataPath, this.emitter.bind(this))
this.streamManager = new StreamManager(this.db, this.MetadataPath, this.emitter.bind(this), this.clientEmitter.bind(this))
this.rssFeeds = new RssFeeds(this.Port, this.db)
this.downloadManager = new DownloadManager(this.db, this.MetadataPath, this.AudiobookPath, this.emitter.bind(this))
this.apiController = new ApiController(this.MetadataPath, this.db, this.scanner, this.auth, this.streamManager, this.rssFeeds, this.downloadManager, this.coverController, this.backupManager, this.watcher, this.emitter.bind(this), this.clientEmitter.bind(this))
@ -453,18 +453,23 @@ class Server {
res.sendStatus(200)
}
audiobookProgressUpdate(socket, progressPayload) {
async audiobookProgressUpdate(socket, progressPayload) {
var client = socket.sheepClient
if (!client || !client.user) {
Logger.error('[Server] audiobookProgressUpdate invalid socket client')
return
}
var hasUpdates = client.user.updateAudiobookProgress(progressPayload.audiobookId, progressPayload)
if (hasUpdates) {
var userAudiobook = client.user.getAudiobookJSON(progressPayload.audiobookId)
socket.emit('current_user_audiobook_update', {
var audiobookProgress = client.user.updateAudiobookProgress(progressPayload.audiobookId, progressPayload)
if (audiobookProgress) {
await this.db.updateEntity('user', client.user)
// This audiobook progress is out of date, why?
// var userAudiobook = client.user.getAudiobookJSON(progressPayload.audiobookId)
// Logger.debug(`[Server] Emitting audiobook progress update to clients ${this.getClientsForUser(client.user.id).length}: ${JSON.stringify(userAudiobook)}`)
this.clientEmitter(client.user.id, 'current_user_audiobook_update', {
id: progressPayload.audiobookId,
data: userAudiobook || null
data: audiobookProgress || null
})
}
}
@ -478,8 +483,9 @@ class Server {
var userAudiobook = client.user.createBookmark(payload)
if (userAudiobook) {
await this.db.updateEntity('user', client.user)
socket.emit('bookmark_created', payload.time)
socket.emit('current_user_audiobook_update', {
this.clientEmitter(client.user.id, 'bookmark_created', payload.time)
this.clientEmitter(client.user.id, 'current_user_audiobook_update', {
id: userAudiobook.audiobookId,
data: userAudiobook || null
})

View File

@ -5,10 +5,11 @@ const fs = require('fs-extra')
const Path = require('path')
class StreamManager {
constructor(db, MetadataPath, emitter) {
constructor(db, MetadataPath, emitter, clientEmitter) {
this.db = db
this.emitter = emitter
this.clientEmitter = clientEmitter
this.MetadataPath = MetadataPath
this.streams = []
@ -157,7 +158,7 @@ class StreamManager {
this.db.updateEntity('user', client.user)
if (userAudiobook) {
socket.emit('current_user_audiobook_update', {
this.clientEmitter(client.user.id, 'current_user_audiobook_update', {
id: userAudiobook.audiobookId,
data: userAudiobook.toJSON()
})

View File

@ -1,3 +1,4 @@
const Logger = require('../Logger')
const AudioBookmark = require('./AudioBookmark')
class AudiobookProgress {
@ -79,6 +80,7 @@ class AudiobookProgress {
update(payload) {
var hasUpdates = false
Logger.debug(`[AudiobookProgress] Update called ${JSON.stringify(payload)}`)
for (const key in payload) {
if (payload[key] !== this[key]) {
if (key === 'isRead') {

View File

@ -1,3 +1,4 @@
const Logger = require('../Logger')
const AudiobookProgress = require('./AudiobookProgress')
class User {
@ -212,7 +213,12 @@ class User {
this.audiobooks[audiobook.id] = new AudiobookProgress()
this.audiobooks[audiobook.id].audiobookId = audiobook.id
}
return this.audiobooks[audiobook.id].update(updatePayload)
var wasUpdated = this.audiobooks[audiobook.id].update(updatePayload)
if (wasUpdated) {
Logger.debug(`[User] Audiobook progress was updated ${JSON.stringify(this.audiobooks[audiobook.id])}`)
return this.audiobooks[audiobook.id]
}
return false
}
// Returns Boolean If update was made