Skip to content

Commit

Permalink
Add OfflinePrivilegeCheck to bootstrap process
Browse files Browse the repository at this point in the history
  • Loading branch information
asendra committed Oct 7, 2024
1 parent 2e91425 commit f37e898
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
12 changes: 10 additions & 2 deletions Sources/Player/PlaybackEngine/Internal/PlayerItemLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ import Foundation

final class PlayerItemLoader {
private let offlineStorage: OfflineStorage?
private let offlinePlaybackPrivilegeCheck: (() -> Bool)?
private let playbackInfoFetcher: PlaybackInfoFetcher
private var playerLoader: PlayerLoader

init(with offlineStorage: OfflineStorage?, _ playbackInfoFetcher: PlaybackInfoFetcher, and playerLoader: PlayerLoader) {
init(
with offlineStorage: OfflineStorage?,
_ offlinePlaybackPrivilegeCheck: (() -> Bool)?,
_ playbackInfoFetcher: PlaybackInfoFetcher,
and playerLoader: PlayerLoader
) {
self.offlineStorage = offlineStorage
self.offlinePlaybackPrivilegeCheck = offlinePlaybackPrivilegeCheck
self.playbackInfoFetcher = playbackInfoFetcher
self.playerLoader = playerLoader
}
Expand Down Expand Up @@ -42,7 +49,8 @@ private extension PlayerItemLoader {

if PlayerWorld.developmentFeatureFlagProvider.isOffliningEnabled,
let offlineEntry = try? offlineStorage?.get(key: mediaProduct.productId),
let offlinedMediaProduct = PlayableOfflinedMediaProduct(from: offlineEntry)
let offlinedMediaProduct = PlayableOfflinedMediaProduct(from: offlineEntry),
offlinePlaybackPrivilegeCheck?() ?? true == true
{
return try await (metadata(of: offlinedMediaProduct), playerLoader.load(offlinedMediaProduct))
}
Expand Down
8 changes: 7 additions & 1 deletion Sources/Player/PlaybackEngine/PlayerEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ final class PlayerEngine {
_ playerEventSender: PlayerEventSender,
_ networkMonitor: NetworkMonitor,
_ offlineStorage: OfflineStorage?,
_ offlinePlaybackPrivilegeCheck: (() -> Bool)?,
_ playerLoader: PlayerLoader,
_ featureFlagProvider: FeatureFlagProvider,
_ notificationsHandler: NotificationsHandler?
Expand All @@ -129,7 +130,12 @@ final class PlayerEngine {
self.notificationsHandler = notificationsHandler
self.featureFlagProvider = featureFlagProvider

playerItemLoader = PlayerItemLoader(with: offlineStorage, playbackInfoFetcher, and: playerLoader)
playerItemLoader = PlayerItemLoader(
with: offlineStorage,
offlinePlaybackPrivilegeCheck,
playbackInfoFetcher,
and: playerLoader
)

state = .IDLE
currentItem = nil
Expand Down
7 changes: 5 additions & 2 deletions Sources/Player/Player.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ public extension Player {
credentialsProvider: CredentialsProvider,
eventSender: EventSender,
userClientIdSupplier: (() -> Int)? = nil,
shouldAddLogging: Bool = false
shouldAddLogging: Bool = false,
offlinePlaybackPrivilegeCheck: (() -> Bool)? = nil
) -> Player? {
if shared != nil {
return nil
Expand Down Expand Up @@ -444,7 +445,8 @@ private extension Player {
_ notificationsHandler: NotificationsHandler?,
_ featureFlagProvider: FeatureFlagProvider,
_ externalPlayers: [GenericMediaPlayer.Type],
_ credentialsProvider: CredentialsProvider
_ credentialsProvider: CredentialsProvider,
_ offlinePlaybackPrivilegeCheck: (() -> Bool)? = nil
) -> PlayerEngine {
let internalPlayerLoader = InternalPlayerLoader(
with: configuration,
Expand All @@ -465,6 +467,7 @@ private extension Player {
playerEventSender,
networkMonitor,
offlineStorage,
offlinePlaybackPrivilegeCheck,
internalPlayerLoader,
featureFlagProvider,
notificationsHandler
Expand Down

0 comments on commit f37e898

Please sign in to comment.