-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update metrics tracker to most recent specifications (#967)
Co-authored-by: Walid Kayhal <[email protected]>
- Loading branch information
Showing
51 changed files
with
783 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// Copyright (c) SRG SSR. All rights reserved. | ||
// | ||
// License information is available from the LICENSE file. | ||
// | ||
|
||
import Combine | ||
import Foundation | ||
|
||
/// A tool that intercepts metric requests and turns them into a hit stream. | ||
enum MetricHitInterceptor { | ||
static func publisher(for identifier: String) -> AnyPublisher<Encodable, Never> { | ||
NotificationCenter.default.publisher(for: .didSendMetricRequest) | ||
.compactMap { payload(from: $0, for: identifier) } | ||
.eraseToAnyPublisher() | ||
} | ||
|
||
private static func payload(from notification: Notification, for identifier: String) -> Encodable? { | ||
guard let userInfo = notification.userInfo, | ||
let requestIdentifier = userInfo[MetricRequestInfoKey.identifier] as? String, requestIdentifier == identifier else { | ||
return nil | ||
} | ||
return userInfo[MetricRequestInfoKey.payload] as? Encodable | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// Copyright (c) SRG SSR. All rights reserved. | ||
// | ||
// License information is available from the LICENSE file. | ||
// | ||
|
||
import Combine | ||
import Foundation | ||
|
||
enum MetricHitListener { | ||
private static var sessionIdentifier: String? | ||
|
||
static func captureMetricHits(perform: (AnyPublisher<Encodable, Never>) -> Void) { | ||
captureHits(perform: perform) { identifier in | ||
MetricHitInterceptor.publisher(for: identifier) | ||
} | ||
} | ||
|
||
private static func captureHits<P>(perform: (P) -> Void, using publisher: (String) -> P) where P: Publisher, P.Failure == Never { | ||
assert(sessionIdentifier == nil, "Multiple captures are not supported") | ||
|
||
let identifier = UUID().uuidString | ||
sessionIdentifier = identifier | ||
defer { | ||
sessionIdentifier = nil | ||
} | ||
|
||
perform(publisher(identifier)) | ||
} | ||
|
||
static func capture(_ payload: Encodable) { | ||
guard let sessionIdentifier else { return } | ||
NotificationCenter.default.post(name: .didSendMetricRequest, object: self, userInfo: [ | ||
MetricRequestInfoKey.identifier: sessionIdentifier, | ||
MetricRequestInfoKey.payload: payload | ||
]) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// Copyright (c) SRG SSR. All rights reserved. | ||
// | ||
// License information is available from the LICENSE file. | ||
// | ||
|
||
import CoreMedia | ||
import PillarboxPlayer | ||
|
||
extension PlayerProperties { | ||
func endOffset() -> CMTime { | ||
max(seekableTimeRange.end - time(), .zero) | ||
} | ||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.