From f37e898056a0127880e3d9cac7dc8091c9807baa Mon Sep 17 00:00:00 2001 From: Alberto Sendra Date: Thu, 19 Sep 2024 12:08:36 +0200 Subject: [PATCH] Add OfflinePrivilegeCheck to bootstrap process --- .../PlaybackEngine/Internal/PlayerItemLoader.swift | 12 ++++++++++-- Sources/Player/PlaybackEngine/PlayerEngine.swift | 8 +++++++- Sources/Player/Player.swift | 7 +++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Sources/Player/PlaybackEngine/Internal/PlayerItemLoader.swift b/Sources/Player/PlaybackEngine/Internal/PlayerItemLoader.swift index 63bf72fc..8a47faf4 100644 --- a/Sources/Player/PlaybackEngine/Internal/PlayerItemLoader.swift +++ b/Sources/Player/PlaybackEngine/Internal/PlayerItemLoader.swift @@ -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 } @@ -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)) } diff --git a/Sources/Player/PlaybackEngine/PlayerEngine.swift b/Sources/Player/PlaybackEngine/PlayerEngine.swift index 695e8ddb..af9aea76 100644 --- a/Sources/Player/PlaybackEngine/PlayerEngine.swift +++ b/Sources/Player/PlaybackEngine/PlayerEngine.swift @@ -108,6 +108,7 @@ final class PlayerEngine { _ playerEventSender: PlayerEventSender, _ networkMonitor: NetworkMonitor, _ offlineStorage: OfflineStorage?, + _ offlinePlaybackPrivilegeCheck: (() -> Bool)?, _ playerLoader: PlayerLoader, _ featureFlagProvider: FeatureFlagProvider, _ notificationsHandler: NotificationsHandler? @@ -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 diff --git a/Sources/Player/Player.swift b/Sources/Player/Player.swift index 52c2d0ea..9763d621 100644 --- a/Sources/Player/Player.swift +++ b/Sources/Player/Player.swift @@ -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 @@ -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, @@ -465,6 +467,7 @@ private extension Player { playerEventSender, networkMonitor, offlineStorage, + offlinePlaybackPrivilegeCheck, internalPlayerLoader, featureFlagProvider, notificationsHandler