diff --git a/ios/App/App/plugins/AbsAudioPlayer.swift b/ios/App/App/plugins/AbsAudioPlayer.swift index c376d66a..2b4197fc 100644 --- a/ios/App/App/plugins/AbsAudioPlayer.swift +++ b/ios/App/App/plugins/AbsAudioPlayer.swift @@ -38,7 +38,9 @@ public class AbsAudioPlayer: CAPPlugin { do { // Fetch the most recent active session - let activeSession = try await Realm().objects(PlaybackSession.self).where({ $0.isActiveSession == true }).last?.freeze() + let activeSession = try await Realm().objects(PlaybackSession.self).where({ + $0.isActiveSession == true && $0.serverConnectionConfigId == Store.serverConfig?.id + }).last?.freeze() if let activeSession = activeSession { await PlayerProgress.shared.syncFromServer() try self.startPlaybackSession(activeSession, playWhenReady: false, playbackRate: PlayerSettings.main().playbackRate) diff --git a/ios/App/Shared/player/PlayerHandler.swift b/ios/App/Shared/player/PlayerHandler.swift index ab4ea126..0a330f61 100644 --- a/ios/App/Shared/player/PlayerHandler.swift +++ b/ios/App/Shared/player/PlayerHandler.swift @@ -159,7 +159,9 @@ class PlayerHandler { private static func cleanupOldSessions(currentSessionId: String?) { let realm = try! Realm() - let oldSessions = realm.objects(PlaybackSession.self) .where({ $0.isActiveSession == true }) + let oldSessions = realm.objects(PlaybackSession.self) .where({ + $0.isActiveSession == true && $0.serverConnectionConfigId == Store.serverConfig?.id + }) try! realm.write { for s in oldSessions { if s.id != currentSessionId { diff --git a/ios/App/Shared/player/PlayerProgress.swift b/ios/App/Shared/player/PlayerProgress.swift index fd81da0b..1a8ed23c 100644 --- a/ios/App/Shared/player/PlayerProgress.swift +++ b/ios/App/Shared/player/PlayerProgress.swift @@ -148,7 +148,9 @@ class PlayerProgress { private func updateLocalSessionFromServerMediaProgress() async { NSLog("updateLocalSessionFromServerMediaProgress: Checking if local media progress was updated on server") - guard let session = try! await Realm().objects(PlaybackSession.self).last(where: { $0.isActiveSession == true })?.freeze() else { + guard let session = try! await Realm().objects(PlaybackSession.self).last(where: { + $0.isActiveSession == true && $0.serverConnectionConfigId == Store.serverConfig?.id + })?.freeze() else { NSLog("updateLocalSessionFromServerMediaProgress: Failed to get session") return }