Skip to content

Commit

Permalink
Remove monitoring warnings (#1046)
Browse files Browse the repository at this point in the history
  • Loading branch information
waliid authored Oct 15, 2024
1 parent 9ba38be commit 9c156d6
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 86 deletions.
2 changes: 0 additions & 2 deletions Sources/Monitoring/MetricsTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ public final class MetricsTracker: PlayerItemTracker {
}
sendEvent(name: .error, data: errorData(error: error, severity: .fatal))
session.stop()
case let .warning(error):
sendEvent(name: .error, data: errorData(error: error, severity: .warning))
default:
break
}
Expand Down
170 changes: 86 additions & 84 deletions Sources/Player/PlayerItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,62 +28,6 @@ public final class PlayerItem: Equatable {

let id = UUID()

/// Creates an item loaded from an ``Asset`` publisher data source.
///
/// - Parameters:
/// - publisher: The asset publisher.
/// - trackerAdapters: An array of `TrackerAdapter` instances to use for tracking playback events.
public convenience init<P, M>(
publisher: P,
trackerAdapters: [TrackerAdapter<M>] = []
) where P: Publisher, P.Output == Asset<M>, M: AssetMetadata {
self.init(
publisher: publisher,
metadataMapper: { $0.playerMetadata },
trackerAdapters: trackerAdapters
)
}

/// Creates a player item from an ``Asset``.
///
/// - Parameters:
/// - asset: The asset to play.
/// - trackerAdapters: An array of `TrackerAdapter` instances to use for tracking playback events.
public convenience init<M>(
asset: Asset<M>,
trackerAdapters: [TrackerAdapter<M>] = []
) where M: AssetMetadata {
self.init(publisher: Just(asset), trackerAdapters: trackerAdapters)
}

/// Creates an item loaded from an ``Asset`` publisher data source.
///
/// - Parameters:
/// - publisher: The asset publisher.
/// - trackerAdapters: An array of `TrackerAdapter` instances to use for tracking playback events.
public convenience init<P>(
publisher: P,
trackerAdapters: [TrackerAdapter<Void>] = []
) where P: Publisher, P.Output == Asset<Void> {
self.init(
publisher: publisher,
metadataMapper: { _ in .empty },
trackerAdapters: trackerAdapters
)
}

/// Creates a player item from an ``Asset``.
///
/// - Parameters:
/// - asset: The asset to play.
/// - trackerAdapters: An array of `TrackerAdapter` instances to use for tracking playback events.
public convenience init(
asset: Asset<Void>,
trackerAdapters: [TrackerAdapter<Void>] = []
) {
self.init(publisher: Just(asset), trackerAdapters: trackerAdapters)
}

private init<P, M>(
publisher: P,
metadataMapper: @escaping (M) -> PlayerMetadata,
Expand Down Expand Up @@ -145,40 +89,61 @@ public final class PlayerItem: Equatable {
}
}

extension PlayerItem {
private func trackerAdapters(matchingBehavior behavior: TrackingBehavior) -> [PlayerItemTracking] {
trackerAdapters.filter { $0.behavior == behavior }
}

func enableTrackers(matchingBehavior behavior: TrackingBehavior, for player: AVPlayer) {
trackerAdapters(matchingBehavior: behavior).forEach { adapter in
adapter.enable(for: player)
}
}

func updateTrackersProperties(matchingBehavior behavior: TrackingBehavior, to properties: PlayerProperties) {
trackerAdapters(matchingBehavior: behavior).forEach { adapter in
adapter.updateProperties(to: properties)
}
public extension PlayerItem {
/// Creates an item loaded from an ``Asset`` publisher data source.
///
/// - Parameters:
/// - publisher: The asset publisher.
/// - trackerAdapters: An array of `TrackerAdapter` instances to use for tracking playback events.
convenience init<P, M>(
publisher: P,
trackerAdapters: [TrackerAdapter<M>] = []
) where P: Publisher, P.Output == Asset<M>, M: AssetMetadata {
self.init(
publisher: publisher,
metadataMapper: { $0.playerMetadata },
trackerAdapters: trackerAdapters
)
}

func updateTrackersMetricEvents(matchingBehavior behavior: TrackingBehavior, to events: [MetricEvent]) {
trackerAdapters(matchingBehavior: behavior).forEach { adapter in
adapter.updateMetricEvents(to: events)
}
/// Creates a player item from an ``Asset``.
///
/// - Parameters:
/// - asset: The asset to play.
/// - trackerAdapters: An array of `TrackerAdapter` instances to use for tracking playback events.
convenience init<M>(
asset: Asset<M>,
trackerAdapters: [TrackerAdapter<M>] = []
) where M: AssetMetadata {
self.init(publisher: Just(asset), trackerAdapters: trackerAdapters)
}

func disableTrackers(matchingBehavior behavior: TrackingBehavior, with properties: PlayerProperties) {
trackerAdapters(matchingBehavior: behavior).forEach { adapter in
adapter.disable(with: properties)
}
/// Creates an item loaded from an ``Asset`` publisher data source.
///
/// - Parameters:
/// - publisher: The asset publisher.
/// - trackerAdapters: An array of `TrackerAdapter` instances to use for tracking playback events.
convenience init<P>(
publisher: P,
trackerAdapters: [TrackerAdapter<Void>] = []
) where P: Publisher, P.Output == Asset<Void> {
self.init(
publisher: publisher,
metadataMapper: { _ in .empty },
trackerAdapters: trackerAdapters
)
}

func sessionIdentifiers<T>(trackedBy type: T.Type) -> [String] where T: PlayerItemTracker {
trackerAdapters.compactMap(\.registration)
.filter { $0.type == type }
.map(\.sessionIdentifier)
.sorted()
/// Creates a player item from an ``Asset``.
///
/// - Parameters:
/// - asset: The asset to play.
/// - trackerAdapters: An array of `TrackerAdapter` instances to use for tracking playback events.
convenience init(
asset: Asset<Void>,
trackerAdapters: [TrackerAdapter<Void>] = []
) {
self.init(publisher: Just(asset), trackerAdapters: trackerAdapters)
}
}

Expand Down Expand Up @@ -312,6 +277,43 @@ public extension PlayerItem {
}
}

extension PlayerItem {
private func trackerAdapters(matchingBehavior behavior: TrackingBehavior) -> [PlayerItemTracking] {
trackerAdapters.filter { $0.behavior == behavior }
}

func enableTrackers(matchingBehavior behavior: TrackingBehavior, for player: AVPlayer) {
trackerAdapters(matchingBehavior: behavior).forEach { adapter in
adapter.enable(for: player)
}
}

func updateTrackersProperties(matchingBehavior behavior: TrackingBehavior, to properties: PlayerProperties) {
trackerAdapters(matchingBehavior: behavior).forEach { adapter in
adapter.updateProperties(to: properties)
}
}

func updateTrackersMetricEvents(matchingBehavior behavior: TrackingBehavior, to events: [MetricEvent]) {
trackerAdapters(matchingBehavior: behavior).forEach { adapter in
adapter.updateMetricEvents(to: events)
}
}

func disableTrackers(matchingBehavior behavior: TrackingBehavior, with properties: PlayerProperties) {
trackerAdapters(matchingBehavior: behavior).forEach { adapter in
adapter.disable(with: properties)
}
}

func sessionIdentifiers<T>(trackedBy type: T.Type) -> [String] where T: PlayerItemTracker {
trackerAdapters.compactMap(\.registration)
.filter { $0.type == type }
.map(\.sessionIdentifier)
.sorted()
}
}

extension PlayerItem {
func metadataPublisher() -> AnyPublisher<PlayerMetadata, Never> {
$content
Expand Down

0 comments on commit 9c156d6

Please sign in to comment.