react-native-tpstreams 1.0.8 → 1.1.0

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.
@@ -3,4 +3,4 @@ Tpstreams_minSdkVersion=24
3
3
  Tpstreams_targetSdkVersion=34
4
4
  Tpstreams_compileSdkVersion=35
5
5
  Tpstreams_ndkVersion=27.1.12297006
6
- Tpstreams_tpstreamsAndroidPlayerVersion=1.0.17
6
+ Tpstreams_tpstreamsAndroidPlayerVersion=1.1.0
@@ -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 ?: DEFAULT_OFFLINE_LICENSE_EXPIRE_TIME
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
  }
@@ -35,6 +35,11 @@ class TPStreamsDownloadModule: RCTEventEmitter, TPStreamsDownloadDelegate {
35
35
  downloadManager.setTPStreamsDownloadDelegate(tpStreamsDownloadDelegate: self)
36
36
  }
37
37
 
38
+ @objc
39
+ func initializeModule() {
40
+ // no-op to force module initialization for setting up the token expiry delegate chain.
41
+ }
42
+
38
43
  func setAccessTokenDelegate(_ delegate: TokenRequestDelegate) {
39
44
  self.tokenDelegate = delegate
40
45
  }
@@ -116,7 +121,7 @@ class TPStreamsDownloadModule: RCTEventEmitter, TPStreamsDownloadDelegate {
116
121
  }
117
122
 
118
123
  func onRequestNewAccessToken(assetId: String, completion: @escaping (String?) -> Void) {
119
- if let delegate = tokenDelegate {
124
+ if let delegate = tokenDelegate {
120
125
  delegate.requestToken(for: assetId, completion: completion)
121
126
  } else {
122
127
  completion(nil)
@@ -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 = 0
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
- if offlineLicenseExpireTime > 0 {
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,12 +6,23 @@ import AVFoundation
6
6
  @objc(TPStreamsRNPlayerViewManager)
7
7
  class TPStreamsRNPlayerViewManager: RCTViewManager {
8
8
  override func view() -> UIView! {
9
+ ensureDownloadModuleInitialized()
9
10
  return TPStreamsRNPlayerView()
10
11
  }
11
12
 
12
13
  override static func requiresMainQueueSetup() -> Bool {
13
14
  return true
14
15
  }
16
+
17
+ private func ensureDownloadModuleInitialized() {
18
+ guard let bridge = bridge else {
19
+ return
20
+ }
21
+
22
+ if let module = bridge.module(for: TPStreamsDownloadModule.self) as? TPStreamsDownloadModule {
23
+ module.initializeModule()
24
+ }
25
+ }
15
26
 
16
27
  // MARK: - Player Commands - Simply delegate to the view
17
28
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-tpstreams",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "description": "Video component for TPStreams",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",