Skip to content

Commit

Permalink
invert mapping to simplify routing error to the right player
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjl-mux committed Sep 6, 2024
1 parent d156dbc commit 9724a90
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions Sources/MuxPlayerSwift/Monitoring/Monitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Monitor: ErrorDispatcher {

var bindings: [ObjectIdentifier: MonitoredPlayer] = [:]

var playersToPlaybackIDs: [ObjectIdentifier: String] = [:]
var playbackIDsToPlayers: [String: ObjectIdentifier] = [:]

var playersToObservedObjectIdentifier: [ObjectIdentifier: ObjectIdentifier] = [:]

Expand Down Expand Up @@ -328,7 +328,11 @@ class Monitor: ErrorDispatcher {
for player: AVPlayer
) {
if let updatedPlaybackID = updatedPlayerItem?.playbackID {
self.playersToPlaybackIDs[ObjectIdentifier(player)] = updatedPlaybackID
playbackIDsToPlayers[updatedPlaybackID] = ObjectIdentifier(player)
}

if let previousPlaybackID = previousPlayerItem?.playbackID {
playbackIDsToPlayers[previousPlaybackID] = ObjectIdentifier(player)
}
}

Expand All @@ -339,12 +343,29 @@ class Monitor: ErrorDispatcher {
playbackID: String
) {

if let playerObjectIdentifier = playbackIDsToPlayers[playbackID],
let bindingReferenceIdentifier = playersToObservedObjectIdentifier[playerObjectIdentifier],
let monitoredPlayer = bindings[bindingReferenceIdentifier] {
monitoredPlayer.binding.dispatchError(
"",
withMessage: ""
)
}
}

func dispatchLicenseRequestError(
error: FairPlaySessionError,
playbackID: String
) {
if let playerObjectIdentifier = playbackIDsToPlayers[playbackID],
let bindingReferenceIdentifier = playersToObservedObjectIdentifier[playerObjectIdentifier],
let monitoredPlayer = bindings[bindingReferenceIdentifier] {
monitoredPlayer.binding.dispatchError(
"",
withMessage: ""
)
}
}

class KeyValueObservation {
var observations: [ObjectIdentifier: Set<NSKeyValueObservation>] = [:]
Expand Down

0 comments on commit 9724a90

Please sign in to comment.