Fix:iOS 0 second listening sessions #970 and include device info with offline sessions

This commit is contained in:
advplyr 2024-02-05 19:04:11 -06:00
parent 2327bc1705
commit 0da6fca727
5 changed files with 17 additions and 13 deletions

View file

@ -147,14 +147,15 @@ public class AbsDatabase: CAPPlugin {
}
@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 {
call.reject("syncLocalSessionsWithServer not connected to server")
return call.resolve()
}
Task {
await ApiClient.syncLocalSessionsWithServer()
await ApiClient.syncLocalSessionsWithServer(isFirstSync: isFirstSync)
call.resolve()
}
}

View file

@ -190,10 +190,10 @@ class ApiClient {
}
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 {
// Sync server progress with local media progress
let localMediaProgressList = Database.shared.getAllLocalMediaProgress().filter {
@ -232,13 +232,15 @@ class ApiClient {
let playbackSessions = Database.shared.getAllPlaybackSessions().filter {
$0.serverConnectionConfigId == Store.serverConfig?.id
}.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) {
let success = await ApiClient.reportAllLocalPlaybackSessions(playbackSessions)
if (success) {
// Remove sessions from db
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() {
try session.delete()
}
@ -327,6 +329,7 @@ struct LocalMediaProgressSyncResultsPayload: Codable {
struct LocalPlaybackSessionSyncAllPayload: Codable {
var sessions: [PlaybackSession]
var deviceInfo: [String: String?]?
}
struct Connectivity {

View file

@ -45,7 +45,7 @@ export default {
if (timeSinceDisconnect > 5000) {
console.log('Time since disconnect was', timeSinceDisconnect, 'sync with server')
setTimeout(() => {
this.syncLocalSessions()
this.syncLocalSessions(false)
}, 4000)
}
}
@ -195,14 +195,14 @@ export default {
this.$eventBus.$emit('library-changed')
this.inittingLibraries = false
},
async syncLocalSessions() {
async syncLocalSessions(isFirstSync) {
if (!this.user) {
console.log('[default] No need to sync local sessions - not connected to server')
return
}
console.log('[default] Calling syncLocalSessions')
const response = await this.$db.syncLocalSessionsWithServer()
const response = await this.$db.syncLocalSessionsWithServer(isFirstSync)
if (response?.error) {
console.error('[default] Failed to sync local sessions', response.error)
} else {
@ -335,7 +335,7 @@ export default {
}
console.log(`[default] finished connection attempt or already connected ${!!this.user}`)
await this.syncLocalSessions()
await this.syncLocalSessions(true)
this.hasMounted = true

View file

@ -196,7 +196,7 @@ class AbsDatabaseWeb extends WebPlugin {
return null
}
async syncLocalSessionsWithServer() {
async syncLocalSessionsWithServer({ isFirstSync }) {
return null
}

View file

@ -70,8 +70,8 @@ class DbService {
return AbsDatabase.removeLocalMediaProgress({ localMediaProgressId })
}
syncLocalSessionsWithServer() {
return AbsDatabase.syncLocalSessionsWithServer()
syncLocalSessionsWithServer(isFirstSync) {
return AbsDatabase.syncLocalSessionsWithServer({ isFirstSync })
}
syncServerMediaProgressWithLocalMediaProgress(payload) {