vdocipher-rn-bridge 1.22.4 → 1.22.7

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.
@@ -17,8 +17,8 @@ apply plugin: 'com.android.library'
17
17
  // TODO read from package.json
18
18
  // "releaseVersionName" must be the same as "version" in package.json
19
19
  // "releaseVersionCode" must increment by 1 with every release
20
- def releaseVersionName = "1.22.4"
21
- def releaseVersionCode = 54
20
+ def releaseVersionName = "1.22.7"
21
+ def releaseVersionCode = 57
22
22
 
23
23
  android {
24
24
  namespace = "com.vdocipher.rnbridge"
@@ -0,0 +1,27 @@
1
+ // AssetList.swift
2
+
3
+ import UIKit
4
+
5
+ class AssetList {
6
+ static let shared = AssetList()
7
+ private var assets: [VdoAsset] = []
8
+ private init() {
9
+ }
10
+ func getAssetFor(videoId: String,
11
+ playerId: String? = nil,
12
+ completionHandler: @escaping (VdoAsset?, VdoError?) -> Void) {
13
+ if let asset = self.assets.first(where: { $0.videoId == videoId }) {
14
+ completionHandler(asset, nil)
15
+ return
16
+ }
17
+ VdoAsset.createAsset(videoId: videoId, playerId: playerId) { asset, error in
18
+ guard let asset = asset else {
19
+ print("Error while fetching VdoAsset Error \(String(describing: error))")
20
+ completionHandler(nil, error)
21
+ return
22
+ }
23
+ self.assets.append(asset)
24
+ completionHandler(asset, error)
25
+ }
26
+ }
27
+ }
@@ -77,7 +77,7 @@ class CreateMap {
77
77
  downloadStatus["status"] = CreateMap.sharedInstance.mapDownloadStateToRNText(downloadState: asset.downloadState)
78
78
  downloadStatus["aspectRatio"] = asset.aspectRatio
79
79
  if (asset.posters?.isEmpty == false) {
80
- downloadStatus["poster"] = asset.posters?[0].url ?? ""
80
+ downloadStatus["poster"] = asset.posters?[0] ?? ""
81
81
  }
82
82
  else{
83
83
  downloadStatus["poster"] = ""
@@ -193,7 +193,7 @@ class VdoCipherRNView: UIView {
193
193
  userDefaults?.set(assetsLastPlaybackTimeSet, forKey: "assetsLastPlaybackTimeSet")
194
194
  }
195
195
  }
196
- VdoAsset.createAsset(videoId: videoId, playerId: customPlayerId, onLoad: { asset, err in
196
+ AssetList.shared.getAssetFor(videoId: videoId, playerId: customPlayerId, completionHandler: { asset, err in
197
197
  DispatchQueue.main.async {
198
198
  guard let asset = asset else {
199
199
  if let error = err {
@@ -63,7 +63,7 @@ enum DownloadEventName: String, CaseIterable {
63
63
  @objc(VdoDownload)
64
64
  class VdoDownload: RCTEventEmitter {
65
65
 
66
- var asset: VdoAsset?
66
+ var assets: [VdoAsset] = []
67
67
  var availableTracksMap: [[String: Any]]?
68
68
  var optionParams: [String: Any]?
69
69
 
@@ -184,7 +184,7 @@ class VdoDownload: RCTEventEmitter {
184
184
  return
185
185
  }
186
186
  let customPlayerId = optionParams["customPlayerId"] as? String
187
- VdoAsset.createAsset(videoId: videoId, playerId: customPlayerId, onLoad: { asset, err in
187
+ AssetList.shared.getAssetFor(videoId: videoId, playerId: customPlayerId, completionHandler: { asset, err in
188
188
  guard let asset = asset else {
189
189
  if let error = err {
190
190
  errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: error.code,
@@ -203,7 +203,6 @@ class VdoDownload: RCTEventEmitter {
203
203
  }
204
204
  let availableTracks = CreateMap.sharedInstance.createTracksMap(with: qualities, forDownload: true)
205
205
  self.availableTracksMap = availableTracks
206
- self.asset = asset
207
206
  self.optionParams = optionParams
208
207
  let mediaInfo = CreateMap.sharedInstance.createMediaInfoMap(with: asset)
209
208
  let downloadOptions = CreateMap.sharedInstance.createDownloadOptionsMap(with: availableTracks, mediaInfo: mediaInfo)
@@ -226,53 +225,72 @@ class VdoDownload: RCTEventEmitter {
226
225
  Error_Keys.EVENT_PROP_ERROR_MSG.rawValue: "Call getDownloadOptions before calling enqueue"]])
227
226
  return
228
227
  }
229
- guard let asset = asset else {
230
- errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: "-1",
231
- Error_Keys.EVENT_PROP_ERROR_MSG.rawValue: "Unknown error occured"]])
232
- return
233
- }
234
- VdoDownload.saveCustomPlayerIdForMediaId(asset.videoId, playerId: optionParams["customPlayerId"] as? String)
235
- if let selections = requestOptions["selections"] as? [Int],
236
- let index = selections.first,
237
- asset.getVideoQualities().count > index {
238
- // assuming index from 'availableTracksMap' is equivalent to index of 'asset.getVideoQualities()' as both are ordered pairs
239
- // asset.percentDownload = 0
240
- successCallback([])
241
-
242
-
243
- asset.startDownload(token: token)
244
- } else {
245
- errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: "-1",
228
+
229
+ let customPlayerId = optionParams["customPlayerId"] as? String
230
+ AssetList.shared.getAssetFor(videoId: mediaId, playerId: customPlayerId, completionHandler: { asset, err in
231
+ guard let asset = asset else {
232
+ if let error = err {
233
+ errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: error.code,
234
+ Error_Keys.EVENT_PROP_ERROR_MSG.rawValue: error.message] as [String : Any]])
235
+ } else {
236
+ errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: "-1",
237
+ Error_Keys.EVENT_PROP_ERROR_MSG.rawValue: "Unknown error occured"]])
238
+ }
239
+ return
240
+ }
241
+ VdoDownload.saveCustomPlayerIdForMediaId(asset.videoId, playerId: optionParams["customPlayerId"] as? String)
242
+ if let selections = requestOptions["selections"] as? [Int],
243
+ let index = selections.first,
244
+ asset.getVideoQualities().count > index {
245
+ // assuming index from 'availableTracksMap' is equivalent to index of 'asset.getVideoQualities()' as both are ordered pairs
246
+ // asset.percentDownload = 0
247
+ successCallback([])
248
+
249
+
250
+ asset.startDownload(token: token)
251
+ } else {
252
+ errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: "-1",
246
253
  Error_Keys.EVENT_PROP_ERROR_MSG.rawValue: "Invalid selection"]])
247
- }
254
+ }
255
+ })
248
256
  }
249
- else if let otp = optionParams["otp"] as? String, let playbackInfo = optionParams["playbackInfo"] as? String {
257
+ else if let otp = optionParams["otp"] as? String,
258
+ let playbackInfo = optionParams["playbackInfo"] as? String,
259
+ let decoded = Data(base64Encoded: playbackInfo),
260
+ let parsed = try? JSONDecoder().decode(PlaybackInfo.self, from: decoded) {
250
261
  if nativeId != playbackInfo {
251
262
  // This is to overcome a condition if last 'getDownloadOptions' api was called for a different mediaId. Since, otp is passed with 'getDownloadOptions' and not with 'enqueue' we need to rely on 'getDownloadOptions'. Also, ReactNative apis are designed in a way that 'enqueue' func is returned on calling 'getDownloadOptions' but 'enqueue' cannot be called indvidually.
252
263
  errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: "-1",
253
264
  Error_Keys.EVENT_PROP_ERROR_MSG.rawValue: "Call getDownloadOptions before calling enqueue"]])
254
265
  return
255
266
  }
256
- guard let asset = asset else {
257
- errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: "-1",
258
- Error_Keys.EVENT_PROP_ERROR_MSG.rawValue: "Unknown error occured"]])
259
- return
260
- }
261
- VdoDownload.saveCustomPlayerIdForMediaId(asset.videoId, playerId: optionParams["customPlayerId"] as? String)
262
- if let selections = requestOptions["selections"] as? [Int],
263
- let index = selections.first,
264
- asset.getVideoQualities().count > index {
265
- // assuming index from 'availableTracksMap' is equivalent to index of 'asset.getVideoQualities()' as both are ordered pairs
266
- // asset.percentDownload = 0
267
- successCallback([])
268
-
269
-
270
- asset.startDownload(otp: otp, playbackInfo: playbackInfo, videoQuality: asset.getVideoQualities()[index])
271
- } else {
272
- errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: "-1",
267
+ let customPlayerId = optionParams["customPlayerId"] as? String
268
+ AssetList.shared.getAssetFor(videoId: parsed.videoId, playerId: customPlayerId, completionHandler: { asset, err in
269
+ guard let asset = asset else {
270
+ if let error = err {
271
+ errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: error.code,
272
+ Error_Keys.EVENT_PROP_ERROR_MSG.rawValue: error.message] as [String : Any]])
273
+ } else {
274
+ errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: "-1",
275
+ Error_Keys.EVENT_PROP_ERROR_MSG.rawValue: "Unknown error occured"]])
276
+ }
277
+ return
278
+ }
279
+ VdoDownload.saveCustomPlayerIdForMediaId(asset.videoId, playerId: optionParams["customPlayerId"] as? String)
280
+ if let selections = requestOptions["selections"] as? [Int],
281
+ let index = selections.first,
282
+ asset.getVideoQualities().count > index {
283
+ // assuming index from 'availableTracksMap' is equivalent to index of 'asset.getVideoQualities()' as both are ordered pairs
284
+ // asset.percentDownload = 0
285
+ successCallback([])
286
+
287
+
288
+ asset.startDownload(otp: otp, playbackInfo: playbackInfo, videoQuality: asset.getVideoQualities()[index])
289
+ } else {
290
+ errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: "-1",
273
291
  Error_Keys.EVENT_PROP_ERROR_MSG.rawValue: "Invalid selection"]])
274
- }
275
-
292
+ }
293
+ })
276
294
  } else {
277
295
  errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: "-1",
278
296
  Error_Keys.EVENT_PROP_ERROR_MSG.rawValue: "PlaybackInfo or OTP not found"]])
@@ -283,7 +301,7 @@ class VdoDownload: RCTEventEmitter {
283
301
  @objc func stop(_ mediaIds: [String], errorCallback: @escaping RCTResponseSenderBlock, successCallback: @escaping RCTResponseSenderBlock) {
284
302
  for mediaId in mediaIds {
285
303
  let customPlayerId = VdoDownload.getCustomPlayerIdForMediaId(mediaId)
286
- VdoAsset.createAsset(videoId: mediaId, playerId: customPlayerId) { asset, error in
304
+ AssetList.shared.getAssetFor(videoId: mediaId, playerId: customPlayerId) { asset, error in
287
305
  if let asset = asset {
288
306
  asset.pauseDownload()
289
307
  }
@@ -295,7 +313,7 @@ class VdoDownload: RCTEventEmitter {
295
313
  @objc func resume(_ mediaIds: [String], errorCallback: @escaping RCTResponseSenderBlock, successCallback: @escaping RCTResponseSenderBlock) {
296
314
  for mediaId in mediaIds {
297
315
  let customPlayerId = VdoDownload.getCustomPlayerIdForMediaId(mediaId)
298
- VdoAsset.createAsset(videoId: mediaId, playerId: customPlayerId) { asset, error in
316
+ AssetList.shared.getAssetFor(videoId: mediaId, playerId: customPlayerId) { asset, error in
299
317
  if let asset = asset {
300
318
  asset.resumeDownload()
301
319
  }
@@ -308,7 +326,7 @@ class VdoDownload: RCTEventEmitter {
308
326
  @objc func remove(_ mediaIds: [String], errorCallback: @escaping RCTResponseSenderBlock, successCallback: @escaping RCTResponseSenderBlock ) {
309
327
  for mediaId in mediaIds {
310
328
  let customPlayerId = VdoDownload.getCustomPlayerIdForMediaId(mediaId)
311
- VdoAsset.createAsset(videoId: mediaId, playerId: customPlayerId) { asset, error in
329
+ AssetList.shared.getAssetFor(videoId: mediaId, playerId: customPlayerId) { asset, error in
312
330
  if let asset = asset {
313
331
  if asset.downloadState == .downloading || asset.downloadState == .paused {
314
332
  asset.cancelDownload()
@@ -348,7 +366,9 @@ class VdoDownload: RCTEventEmitter {
348
366
  return
349
367
  }
350
368
  if let videoId = notice[VdoAsset.Keys.videoId] as? String {
351
- if videoId == self.asset?.videoId, let asset = asset {
369
+ let customPlayerId = VdoDownload.getCustomPlayerIdForMediaId(videoId)
370
+ AssetList.shared.getAssetFor(videoId: videoId, playerId: customPlayerId) { asset, _ in
371
+ guard let asset = asset else { return }
352
372
  if newState == .downloaded {
353
373
  DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_COMPLETED, params: ["mediaId": asset.videoId, "downloadStatus": CreateMap.sharedInstance.createVdoAssetMap(with: asset)])
354
374
  } else if newState == .downloading {
@@ -356,18 +376,6 @@ class VdoDownload: RCTEventEmitter {
356
376
  } else {
357
377
  DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_CHANGED, params: ["mediaId": asset.videoId, "downloadStatus": CreateMap.sharedInstance.createVdoAssetMap(with: asset)])
358
378
  }
359
- } else {
360
- let customPlayerId = VdoDownload.getCustomPlayerIdForMediaId(videoId)
361
- VdoAsset.createAsset(videoId: videoId, playerId: customPlayerId) { asset, _ in
362
- guard let asset = asset else { return }
363
- if newState == .downloaded {
364
- DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_COMPLETED, params: ["mediaId": asset.videoId, "downloadStatus": CreateMap.sharedInstance.createVdoAssetMap(with: asset)])
365
- } else if newState == .downloading {
366
- DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_QUEUED, params: ["mediaId": asset.videoId, "downloadStatus": CreateMap.sharedInstance.createVdoAssetMap(with: asset)])
367
- } else {
368
- DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_CHANGED, params: ["mediaId": asset.videoId, "downloadStatus": CreateMap.sharedInstance.createVdoAssetMap(with: asset)])
369
- }
370
- }
371
379
  }
372
380
  }
373
381
  }
@@ -378,16 +386,13 @@ class VdoDownload: RCTEventEmitter {
378
386
  return
379
387
  }
380
388
  if let videoId = notice[VdoAsset.Keys.videoId] as? String {
381
- if videoId == self.asset?.videoId, let asset = asset {
382
- // asset.percentDownload = percentDownload
383
- DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_CHANGED, params: ["mediaId": asset.videoId, "downloadStatus": CreateMap.sharedInstance.createVdoAssetMap(with: asset)])
384
- } else {
385
- let customPlayerId = VdoDownload.getCustomPlayerIdForMediaId(videoId)
386
- VdoAsset.createAsset(videoId: videoId, playerId: customPlayerId) { asset, _ in
387
- guard let asset = asset else { return }
388
- // asset.percentDownload = percentDownload
389
- DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_CHANGED, params: ["mediaId": asset.videoId, "downloadStatus": CreateMap.sharedInstance.createVdoAssetMap(with: asset)])
389
+ let customPlayerId = VdoDownload.getCustomPlayerIdForMediaId(videoId)
390
+ AssetList.shared.getAssetFor(videoId: videoId, playerId: customPlayerId) { asset, _ in
391
+ guard let asset = asset else { return }
392
+ if asset.downloadState == .downloaded {
393
+ return
390
394
  }
395
+ DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_CHANGED, params: ["mediaId": asset.videoId, "downloadStatus": CreateMap.sharedInstance.createVdoAssetMap(with: asset)])
391
396
  }
392
397
  }
393
398
  }
@@ -396,20 +401,13 @@ class VdoDownload: RCTEventEmitter {
396
401
  let notice = notification.userInfo!
397
402
  guard let message = notice[VdoAsset.Keys.message] as? String, let code = notice[VdoAsset.Keys.code] else {return}
398
403
  if let videoId = notice[VdoAsset.Keys.videoId] as? String {
399
- if videoId == self.asset?.videoId, let asset = asset {
404
+ let customPlayerId = VdoDownload.getCustomPlayerIdForMediaId(videoId)
405
+ AssetList.shared.getAssetFor(videoId: videoId, playerId: customPlayerId) { asset, _ in
406
+ guard let asset = asset else { return }
400
407
  var assetMap = CreateMap.sharedInstance.createVdoAssetMap(with: asset)
401
408
  assetMap["reasonDescription"] = message
402
409
  assetMap["reason"] = code
403
410
  DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_FAILED, params: ["mediaId": asset.videoId, "downloadStatus": assetMap])
404
- } else {
405
- let customPlayerId = VdoDownload.getCustomPlayerIdForMediaId(videoId)
406
- VdoAsset.createAsset(videoId: videoId, playerId: customPlayerId) { asset, _ in
407
- guard let asset = asset else { return }
408
- var assetMap = CreateMap.sharedInstance.createVdoAssetMap(with: asset)
409
- assetMap["reasonDescription"] = message
410
- assetMap["reason"] = code
411
- DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_FAILED, params: ["mediaId": asset.videoId, "downloadStatus": assetMap])
412
- }
413
411
  }
414
412
  }
415
413
  }
@@ -5,7 +5,7 @@ import VdoFramework
5
5
  @objc(VdocipherRnBridge)
6
6
  class VdocipherRnBridge: RCTViewManager {
7
7
 
8
- static let vdocipherRnBridgeVersionString = "1.22.4"
8
+ static let vdocipherRnBridgeVersionString = "1.22.7"
9
9
 
10
10
  @objc override static func requiresMainQueueSetup() -> Bool {
11
11
  return true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vdocipher-rn-bridge",
3
- "version": "1.22.4",
3
+ "version": "1.22.7",
4
4
  "description": "React native bridge library that delegates to vdocipher native android SDK",
5
5
  "homepage": "https://www.vdocipher.com/docs/mobile/react-native/getting-started/",
6
6
  "scripts": {
@@ -17,7 +17,7 @@ Pod::Spec.new do |s|
17
17
  s.source_files = "ios/**/*.{h,m,mm,swift}"
18
18
 
19
19
  s.dependency "React-Core"
20
- s.dependency "VdoFramework", "2.8.1"
20
+ s.dependency "VdoFramework", "2.9.3"
21
21
 
22
22
  # Don't install the dependencies when we run `pod install` in the old architecture.
23
23
  if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then