Re-pick Plex server address on network change, foreground, and stream failure (dev 36)
The address chosen at sign-in (LAN first) was kept forever, so away from home streams hit a dead LAN address (TLS error) or the relay (503). Store every address plex.tv lists, probe them all bypassing the offline cache, and keep the best one that answers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9f68aa588b
commit
e02428ab70
7 files changed
+100
-17
No files matched your search
@@ -722,9 +722,19 @@ final class PlaybackManager: StemEngineListener, @unchecked Sendable {
|
||||
|
||||
private func openDetached(_ track: Track, _ startMs: Int64) async throws -> (TrackSession, StemEntry?) {
|
||||
// Plain Plex files need a playback session first, or a Remote Access upload limit fails them.
|
||||
var stream: URL?
|
||||
if stems.find(track) == nil, !cache.isComplete(Self.plexKey(track)) { stream = await plex.streamUrl(track) }
|
||||
return try await withCheckedThrowingContinuation { [stream] cont in
|
||||
let plain = stems.find(track) == nil && !cache.isComplete(Self.plexKey(track))
|
||||
let stream = plain ? await plex.streamUrl(track) : nil
|
||||
do {
|
||||
return try await openOn(track, startMs, stream)
|
||||
} catch {
|
||||
// A dead saved address (left home, network changed): pick a working one and try once more.
|
||||
guard plain, !Task.isCancelled, await plex.reroute("stream failed") else { throw error }
|
||||
return try await openOn(track, startMs, await plex.streamUrl(track))
|
||||
}
|
||||
}
|
||||
|
||||
private func openOn(_ track: Track, _ startMs: Int64, _ stream: URL?) async throws -> (TrackSession, StemEntry?) {
|
||||
try await withCheckedThrowingContinuation { cont in
|
||||
DispatchQueue.global(qos: .userInitiated).async { [self] in
|
||||
cont.resume(with: Result { try open(track, startMs, stream: stream) })
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user