react-native-tpstreams 1.0.8-debug.1 → 1.1.0-debug.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/gradle.properties +1 -1
- package/android/src/main/java/com/tpstreams/TPStreamsRNPlayerView.kt +15 -1
- package/ios/TPStreamsDownloadModule.swift +14 -1
- package/ios/TPStreamsModule.swift +14 -0
- package/ios/TPStreamsRNPlayerView.swift +13 -4
- package/ios/TPStreamsRNPlayerViewManager.swift +0 -11
- package/package.json +1 -1
|
@@ -8,6 +8,7 @@ import com.facebook.react.uimanager.ThemedReactContext
|
|
|
8
8
|
import com.facebook.react.uimanager.events.RCTEventEmitter
|
|
9
9
|
import com.tpstreams.player.TPStreamsPlayer
|
|
10
10
|
import com.tpstreams.player.TPStreamsPlayerView
|
|
11
|
+
import com.tpstreams.player.constants.PlaybackError
|
|
11
12
|
import androidx.media3.common.Player
|
|
12
13
|
import androidx.media3.common.PlaybackParameters
|
|
13
14
|
import androidx.media3.common.PlaybackException
|
|
@@ -92,7 +93,7 @@ class TPStreamsRNPlayerView(context: ThemedReactContext) : FrameLayout(context)
|
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
fun setOfflineLicenseExpireTime(expireTime: Long?) {
|
|
95
|
-
this.offlineLicenseExpireTime = expireTime
|
|
96
|
+
this.offlineLicenseExpireTime = sanitizeLicenseDuration(expireTime)
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
fun setNewAccessToken(newToken: String) {
|
|
@@ -129,6 +130,12 @@ class TPStreamsRNPlayerView(context: ThemedReactContext) : FrameLayout(context)
|
|
|
129
130
|
accessTokenCallback = callback
|
|
130
131
|
emitEvent("onAccessTokenExpired", mapOf("videoId" to videoId))
|
|
131
132
|
}
|
|
133
|
+
|
|
134
|
+
override fun onError(error: PlaybackError, message: String) {
|
|
135
|
+
Log.e("TPStreamsRN", "TPStreamsPlayer error: $error - $message")
|
|
136
|
+
val errorCode = ERROR_CODE_PLAYER_CREATION_FAILED + error.ordinal
|
|
137
|
+
sendErrorEvent("Player error", errorCode, message)
|
|
138
|
+
}
|
|
132
139
|
}
|
|
133
140
|
|
|
134
141
|
// Add player event listeners
|
|
@@ -240,4 +247,11 @@ class TPStreamsRNPlayerView(context: ThemedReactContext) : FrameLayout(context)
|
|
|
240
247
|
player = null
|
|
241
248
|
accessTokenCallback = null
|
|
242
249
|
}
|
|
250
|
+
|
|
251
|
+
private fun sanitizeLicenseDuration(value: Long?): Long {
|
|
252
|
+
if (value == null || value <= 0L) {
|
|
253
|
+
return DEFAULT_OFFLINE_LICENSE_EXPIRE_TIME
|
|
254
|
+
}
|
|
255
|
+
return minOf(value, DEFAULT_OFFLINE_LICENSE_EXPIRE_TIME)
|
|
256
|
+
}
|
|
243
257
|
}
|
|
@@ -37,9 +37,22 @@ class TPStreamsDownloadModule: RCTEventEmitter, TPStreamsDownloadDelegate {
|
|
|
37
37
|
|
|
38
38
|
@objc
|
|
39
39
|
func initializeModule() {
|
|
40
|
-
//no-op
|
|
40
|
+
// no-op to force module initialization for setting up the token expiry delegate chain.
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
@objc
|
|
44
|
+
public func deletePartiallyDownloadedVideos() {
|
|
45
|
+
debugPrint("Deleting partially downloaded videos")
|
|
46
|
+
let downloads = downloadManager.getAllOfflineAssets()
|
|
47
|
+
print("Downloads: \(downloads)")
|
|
48
|
+
for download in downloads {
|
|
49
|
+
if download.status != Status.finished.rawValue {
|
|
50
|
+
print("Deleting download: \(download.assetId)")
|
|
51
|
+
downloadManager.cancelDownload(download.assetId)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
}
|
|
43
56
|
func setAccessTokenDelegate(_ delegate: TokenRequestDelegate) {
|
|
44
57
|
self.tokenDelegate = delegate
|
|
45
58
|
}
|
|
@@ -19,7 +19,21 @@ class TPStreamsModule: NSObject {
|
|
|
19
19
|
|
|
20
20
|
private func initializeDownloadModule() {
|
|
21
21
|
_ = TPStreamsDownloadModule.shared
|
|
22
|
+
print("Initializing download module")
|
|
23
|
+
ensureDownloadModuleInitialized()
|
|
24
|
+
print("Shared is not none", TPStreamsDownloadModule.shared)
|
|
25
|
+
TPStreamsDownloadModule.shared?.deletePartiallyDownloadedVideos()
|
|
22
26
|
}
|
|
27
|
+
|
|
28
|
+
private func ensureDownloadModuleInitialized() {
|
|
29
|
+
guard let bridge = RCTBridge.current() else {
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if let module = bridge.module(for: TPStreamsDownloadModule.self) as? TPStreamsDownloadModule {
|
|
34
|
+
module.initializeModule()
|
|
35
|
+
}
|
|
36
|
+
}
|
|
23
37
|
|
|
24
38
|
@objc
|
|
25
39
|
static func requiresMainQueueSetup() -> Bool {
|
|
@@ -16,6 +16,8 @@ class TPStreamsRNPlayerView: UIView {
|
|
|
16
16
|
case ended = 4
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
private static let maxOfflineLicenseDuration: Double = 15 * 24 * 60 * 60
|
|
20
|
+
|
|
19
21
|
private var player: TPAVPlayer?
|
|
20
22
|
private var playerViewController: TPStreamPlayerViewController?
|
|
21
23
|
private var playerStatusObserver: NSKeyValueObservation?
|
|
@@ -24,13 +26,17 @@ class TPStreamsRNPlayerView: UIView {
|
|
|
24
26
|
private var playerStateObserver: NSKeyValueObservation?
|
|
25
27
|
private var setupScheduled = false
|
|
26
28
|
private var pendingOfflineCredentialsCompletion: ((String?, Double) -> Void)?
|
|
29
|
+
private var _offlineLicenseExpireTime: Double = TPStreamsRNPlayerView.maxOfflineLicenseDuration
|
|
27
30
|
|
|
28
31
|
@objc var videoId: NSString = ""
|
|
29
32
|
@objc var accessToken: NSString = ""
|
|
30
33
|
@objc var shouldAutoPlay: Bool = true
|
|
31
34
|
@objc var startAt: Double = 0
|
|
32
35
|
@objc var enableDownload: Bool = false
|
|
33
|
-
@objc var offlineLicenseExpireTime: Double
|
|
36
|
+
@objc var offlineLicenseExpireTime: Double {
|
|
37
|
+
get { _offlineLicenseExpireTime }
|
|
38
|
+
set { _offlineLicenseExpireTime = TPStreamsRNPlayerView.sanitizeLicenseDuration(newValue) }
|
|
39
|
+
}
|
|
34
40
|
@objc var showDefaultCaptions: Bool = false
|
|
35
41
|
@objc var downloadMetadata: NSString?
|
|
36
42
|
|
|
@@ -175,9 +181,7 @@ class TPStreamsRNPlayerView: UIView {
|
|
|
175
181
|
.setwatchedProgressTrackColor(.systemBlue)
|
|
176
182
|
.setDownloadMetadata(metadataDict)
|
|
177
183
|
|
|
178
|
-
|
|
179
|
-
configBuilder.setLicenseDurationSeconds(offlineLicenseExpireTime)
|
|
180
|
-
}
|
|
184
|
+
configBuilder.setLicenseDurationSeconds(offlineLicenseExpireTime)
|
|
181
185
|
|
|
182
186
|
if enableDownload {
|
|
183
187
|
configBuilder.showDownloadOption()
|
|
@@ -283,6 +287,11 @@ class TPStreamsRNPlayerView: UIView {
|
|
|
283
287
|
TPStreamsDownloadModule.shared?.setAccessTokenDelegate(self)
|
|
284
288
|
}
|
|
285
289
|
|
|
290
|
+
private static func sanitizeLicenseDuration(_ value: Double) -> Double {
|
|
291
|
+
guard value > 0 else { return maxOfflineLicenseDuration }
|
|
292
|
+
return min(value, maxOfflineLicenseDuration)
|
|
293
|
+
}
|
|
294
|
+
|
|
286
295
|
private func parseMetadataJSON(from jsonString: NSString?) -> [String: Any]? {
|
|
287
296
|
guard let metadataString = jsonString as String? else { return nil }
|
|
288
297
|
|
|
@@ -6,23 +6,12 @@ import AVFoundation
|
|
|
6
6
|
@objc(TPStreamsRNPlayerViewManager)
|
|
7
7
|
class TPStreamsRNPlayerViewManager: RCTViewManager {
|
|
8
8
|
override func view() -> UIView! {
|
|
9
|
-
ensureDownloadModuleInitialized()
|
|
10
9
|
return TPStreamsRNPlayerView()
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
override static func requiresMainQueueSetup() -> Bool {
|
|
14
13
|
return true
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
private func ensureDownloadModuleInitialized() {
|
|
18
|
-
guard let bridge = self.bridge else {
|
|
19
|
-
return
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if let module = bridge.module(for: TPStreamsDownloadModule.self) as? TPStreamsDownloadModule {
|
|
23
|
-
module.initializeModule()
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
15
|
|
|
27
16
|
// MARK: - Player Commands - Simply delegate to the view
|
|
28
17
|
|