mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-07-15 08:24:50 +02:00
Fix:iOS 0 second listening sessions #970 and include device info with offline sessions
This commit is contained in:
parent
2327bc1705
commit
0da6fca727
5 changed files with 17 additions and 13 deletions
|
@ -147,14 +147,15 @@ public class AbsDatabase: CAPPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func syncLocalSessionsWithServer(_ call: CAPPluginCall) {
|
@objc func syncLocalSessionsWithServer(_ call: CAPPluginCall) {
|
||||||
logger.log("syncLocalSessionsWithServer: Starting")
|
let isFirstSync = call.getBool("isFirstSync", false)
|
||||||
|
logger.log("syncLocalSessionsWithServer: Starting (First sync: \(isFirstSync))")
|
||||||
guard Store.serverConfig != nil else {
|
guard Store.serverConfig != nil else {
|
||||||
call.reject("syncLocalSessionsWithServer not connected to server")
|
call.reject("syncLocalSessionsWithServer not connected to server")
|
||||||
return call.resolve()
|
return call.resolve()
|
||||||
}
|
}
|
||||||
|
|
||||||
Task {
|
Task {
|
||||||
await ApiClient.syncLocalSessionsWithServer()
|
await ApiClient.syncLocalSessionsWithServer(isFirstSync: isFirstSync)
|
||||||
call.resolve()
|
call.resolve()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,10 +190,10 @@ class ApiClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func reportAllLocalPlaybackSessions(_ sessions: [PlaybackSession]) async -> Bool {
|
public static func reportAllLocalPlaybackSessions(_ sessions: [PlaybackSession]) async -> Bool {
|
||||||
return await postResource(endpoint: "api/session/local-all", parameters: LocalPlaybackSessionSyncAllPayload(sessions: sessions))
|
return await postResource(endpoint: "api/session/local-all", parameters: LocalPlaybackSessionSyncAllPayload(sessions: sessions, deviceInfo: sessions.first?.deviceInfo))
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func syncLocalSessionsWithServer() async {
|
public static func syncLocalSessionsWithServer(isFirstSync: Bool) async {
|
||||||
do {
|
do {
|
||||||
// Sync server progress with local media progress
|
// Sync server progress with local media progress
|
||||||
let localMediaProgressList = Database.shared.getAllLocalMediaProgress().filter {
|
let localMediaProgressList = Database.shared.getAllLocalMediaProgress().filter {
|
||||||
|
@ -232,13 +232,15 @@ class ApiClient {
|
||||||
let playbackSessions = Database.shared.getAllPlaybackSessions().filter {
|
let playbackSessions = Database.shared.getAllPlaybackSessions().filter {
|
||||||
$0.serverConnectionConfigId == Store.serverConfig?.id
|
$0.serverConnectionConfigId == Store.serverConfig?.id
|
||||||
}.map { $0.freeze() }
|
}.map { $0.freeze() }
|
||||||
logger.log("syncLocalSessionsWithServer: Found \(playbackSessions.count) playback sessions for server")
|
logger.log("syncLocalSessionsWithServer: Found \(playbackSessions.count) playback sessions for server (first sync: \(isFirstSync))")
|
||||||
if (!playbackSessions.isEmpty) {
|
if (!playbackSessions.isEmpty) {
|
||||||
let success = await ApiClient.reportAllLocalPlaybackSessions(playbackSessions)
|
let success = await ApiClient.reportAllLocalPlaybackSessions(playbackSessions)
|
||||||
if (success) {
|
if (success) {
|
||||||
// Remove sessions from db
|
// Remove sessions from db
|
||||||
try playbackSessions.forEach { session in
|
try playbackSessions.forEach { session in
|
||||||
if (!session.isActiveSession) {
|
logger.log("syncLocalSessionsWithServer: Handling \(session.displayTitle ?? "") (\(session.id)) \(session.isActiveSession)")
|
||||||
|
// On first sync then remove all sessions
|
||||||
|
if (!session.isActiveSession || isFirstSync) {
|
||||||
if let session = session.thaw() {
|
if let session = session.thaw() {
|
||||||
try session.delete()
|
try session.delete()
|
||||||
}
|
}
|
||||||
|
@ -327,6 +329,7 @@ struct LocalMediaProgressSyncResultsPayload: Codable {
|
||||||
|
|
||||||
struct LocalPlaybackSessionSyncAllPayload: Codable {
|
struct LocalPlaybackSessionSyncAllPayload: Codable {
|
||||||
var sessions: [PlaybackSession]
|
var sessions: [PlaybackSession]
|
||||||
|
var deviceInfo: [String: String?]?
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Connectivity {
|
struct Connectivity {
|
||||||
|
|
|
@ -45,7 +45,7 @@ export default {
|
||||||
if (timeSinceDisconnect > 5000) {
|
if (timeSinceDisconnect > 5000) {
|
||||||
console.log('Time since disconnect was', timeSinceDisconnect, 'sync with server')
|
console.log('Time since disconnect was', timeSinceDisconnect, 'sync with server')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.syncLocalSessions()
|
this.syncLocalSessions(false)
|
||||||
}, 4000)
|
}, 4000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -195,14 +195,14 @@ export default {
|
||||||
this.$eventBus.$emit('library-changed')
|
this.$eventBus.$emit('library-changed')
|
||||||
this.inittingLibraries = false
|
this.inittingLibraries = false
|
||||||
},
|
},
|
||||||
async syncLocalSessions() {
|
async syncLocalSessions(isFirstSync) {
|
||||||
if (!this.user) {
|
if (!this.user) {
|
||||||
console.log('[default] No need to sync local sessions - not connected to server')
|
console.log('[default] No need to sync local sessions - not connected to server')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[default] Calling syncLocalSessions')
|
console.log('[default] Calling syncLocalSessions')
|
||||||
const response = await this.$db.syncLocalSessionsWithServer()
|
const response = await this.$db.syncLocalSessionsWithServer(isFirstSync)
|
||||||
if (response?.error) {
|
if (response?.error) {
|
||||||
console.error('[default] Failed to sync local sessions', response.error)
|
console.error('[default] Failed to sync local sessions', response.error)
|
||||||
} else {
|
} else {
|
||||||
|
@ -335,7 +335,7 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[default] finished connection attempt or already connected ${!!this.user}`)
|
console.log(`[default] finished connection attempt or already connected ${!!this.user}`)
|
||||||
await this.syncLocalSessions()
|
await this.syncLocalSessions(true)
|
||||||
|
|
||||||
this.hasMounted = true
|
this.hasMounted = true
|
||||||
|
|
||||||
|
|
|
@ -196,7 +196,7 @@ class AbsDatabaseWeb extends WebPlugin {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
async syncLocalSessionsWithServer() {
|
async syncLocalSessionsWithServer({ isFirstSync }) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,8 +70,8 @@ class DbService {
|
||||||
return AbsDatabase.removeLocalMediaProgress({ localMediaProgressId })
|
return AbsDatabase.removeLocalMediaProgress({ localMediaProgressId })
|
||||||
}
|
}
|
||||||
|
|
||||||
syncLocalSessionsWithServer() {
|
syncLocalSessionsWithServer(isFirstSync) {
|
||||||
return AbsDatabase.syncLocalSessionsWithServer()
|
return AbsDatabase.syncLocalSessionsWithServer({ isFirstSync })
|
||||||
}
|
}
|
||||||
|
|
||||||
syncServerMediaProgressWithLocalMediaProgress(payload) {
|
syncServerMediaProgressWithLocalMediaProgress(payload) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue