@takeoffmedia/react-native-penthera 0.1.0 → 0.1.2

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.
Files changed (39) hide show
  1. package/ios/Catalog.swift +61 -4
  2. package/ios/Penthera.m +5 -1
  3. package/ios/Penthera.swift +109 -74
  4. package/ios/Util.swift +72 -0
  5. package/lib/commonjs/hooks/usePenthera.js +18 -19
  6. package/lib/commonjs/hooks/usePenthera.js.map +1 -1
  7. package/lib/commonjs/index.js.map +1 -1
  8. package/lib/commonjs/nativeModules/index.js +4 -0
  9. package/lib/commonjs/nativeModules/index.js.map +1 -1
  10. package/lib/commonjs/utils/Penthera.js +1 -0
  11. package/lib/commonjs/utils/Penthera.js.map +1 -1
  12. package/lib/module/hooks/usePenthera.js +19 -19
  13. package/lib/module/hooks/usePenthera.js.map +1 -1
  14. package/lib/module/index.js.map +1 -1
  15. package/lib/module/nativeModules/index.js +3 -0
  16. package/lib/module/nativeModules/index.js.map +1 -1
  17. package/lib/module/utils/Penthera.js +1 -0
  18. package/lib/module/utils/Penthera.js.map +1 -1
  19. package/lib/typescript/hooks/usePenthera.d.ts +2 -0
  20. package/lib/typescript/hooks/usePenthera.d.ts.map +1 -1
  21. package/lib/typescript/index.d.ts +1 -0
  22. package/lib/typescript/index.d.ts.map +1 -1
  23. package/lib/typescript/interface/Idata.d.ts.map +1 -1
  24. package/lib/typescript/interface/PentheraTypes.d.ts +39 -11
  25. package/lib/typescript/interface/PentheraTypes.d.ts.map +1 -1
  26. package/lib/typescript/nativeModules/index.d.ts +1 -0
  27. package/lib/typescript/nativeModules/index.d.ts.map +1 -1
  28. package/lib/typescript/utils/Penthera.d.ts +2 -1
  29. package/lib/typescript/utils/Penthera.d.ts.map +1 -1
  30. package/package.json +1 -1
  31. package/src/hooks/usePenthera.ts +20 -25
  32. package/src/index.tsx +2 -2
  33. package/src/interface/Idata.ts +21 -21
  34. package/src/interface/PentheraTypes.ts +42 -8
  35. package/src/nativeModules/index.ts +11 -7
  36. package/src/utils/Penthera.ts +1 -0
  37. package/lib/commonjs/data/data.json +0 -58
  38. package/lib/module/data/data.json +0 -58
  39. package/src/data/data.json +0 -58
package/ios/Catalog.swift CHANGED
@@ -2,10 +2,8 @@ struct Catalog: Codable {
2
2
  var id: String = ""
3
3
  var url: String = ""
4
4
  var thumbnail: String = ""
5
-
6
5
  var showId: String = ""
7
6
  var showTitle: String = ""
8
-
9
7
  var title: String = ""
10
8
  var description: String = ""
11
9
  var rate: String = ""
@@ -13,8 +11,9 @@ struct Catalog: Codable {
13
11
 
14
12
  struct OfflineCatalog: Codable {
15
13
  var id: String = ""
16
- var thumbnail: String = ""
17
- var wallpaper: String = ""
14
+ var title: String? = ""
15
+ var data: DataItem?
16
+ var thumbnails: Thumbnails?
18
17
  var subtitle: String = ""
19
18
  var url: String = ""
20
19
  var certificateUrl: String = ""
@@ -23,6 +22,64 @@ struct OfflineCatalog: Codable {
23
22
  var isPaused: Bool
24
23
  }
25
24
 
25
+ struct Thumbnails: Codable {
26
+ var thumbnail: String? = ""
27
+ var season: String? = ""
28
+ var show: String? = ""
29
+ var episode: String? = ""
30
+ }
31
+
32
+ struct DataItem: Codable {
33
+ var type: String?
34
+ var id: String?
35
+ var title: String?
36
+ var contextualTitle: String?
37
+ var shortDescription: String?
38
+ var path: String?
39
+ var watchPath: String?
40
+ var scope: Array<String>?
41
+ var releaseYear: Int?
42
+ var episodeNumber: Int?
43
+ var episodeName: String?
44
+ var showId: String?
45
+ var showTitle: String?
46
+ var seasonId: String?
47
+ var seasonTitle: String?
48
+ var genres: Array<String>?
49
+ var duration: Int?
50
+ var customId: String?
51
+ var offers: Array<Offers>?
52
+ var images: Images?
53
+ var customFields: CustomFields?
54
+ var classification: Classification?
55
+ }
56
+
57
+ struct Offers: Codable {
58
+ var deliveryType: String? = ""
59
+ var resolution: String? = ""
60
+ var ownership: String? = ""
61
+ var availability: String? = ""
62
+ var scope: Array<String>?
63
+ var customFields: Array<Int>?
64
+ }
65
+
66
+ struct Images: Codable {
67
+ var wallpaper: String
68
+ var themes: Array<String> = [""]
69
+ }
70
+
71
+ struct Classification: Codable {
72
+ var code: String = ""
73
+ var name: String = ""
74
+ }
75
+
76
+ struct CustomFields: Codable {
77
+ var CCFlag, DLFlag, DRM, HDFlag: String?
78
+ var IngestionHash, Now, PayloadId, Premiere: String?
79
+ var PrimaryVpid, SubGenre, IsComingSoon: String?
80
+ }
81
+
82
+
26
83
  struct Event: Codable {
27
84
  var code: String = ""
28
85
  var assetId: String = ""
package/ios/Penthera.m CHANGED
@@ -30,7 +30,11 @@ RCT_EXTERN_METHOD(delete:(NSString*)assetID
30
30
 
31
31
  RCT_EXTERN_METHOD(playAsset:(NSString*)assetID
32
32
  withResolver:(RCTPromiseResolveBlock)resolve
33
- withRejecter:(RCTPromiseRejectBlock)reject)
33
+ withRejecter:(RCTPromiseRejectBlock)reject)
34
+
35
+ RCT_EXTERN_METHOD(pauseDownload:(NSString*)user
36
+ withResolver:(RCTPromiseResolveBlock)resolve
37
+ withRejecter:(RCTPromiseRejectBlock)reject)
34
38
 
35
39
  + (BOOL)requiresMainQueueSetup
36
40
  {
@@ -8,7 +8,7 @@ class Penthera: RCTEventEmitter, VirtuosoDownloadEngineNotificationsDelegate {
8
8
  super.init()
9
9
  EventEmitter.sharedInstance.registerEventEmitter(eventEmitter: self)
10
10
  }
11
-
11
+
12
12
  @objc(multiply:withB:withResolver:withRejecter:)
13
13
  func multiply(a: Float, b: Float, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void {
14
14
  resolve(a*b)
@@ -50,37 +50,57 @@ class Penthera: RCTEventEmitter, VirtuosoDownloadEngineNotificationsDelegate {
50
50
  resolve("Error")
51
51
  @unknown default:
52
52
  //EventEmitter.sharedInstance.dispatch(name: "penthera", body: "Virtuoso Default")
53
- resolve("Error Default")
53
+ resolve("Error Default")
54
54
  }
55
55
  }
56
56
  }
57
-
57
+
58
58
  @objc(getDownloads:withResolver:withRejecter:)
59
59
  func getDownloads(blank: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
60
60
  let completedAssets = VirtuosoAsset.completedAssets(withAvailabilityFilter: false)
61
61
  let pendingAssets = VirtuosoAsset.pendingAssets(withAvailabilityFilter: false)
62
62
  var offlineCatalogs: [OfflineCatalog] = []
63
-
63
+
64
64
  for case let va as VirtuosoAsset in completedAssets {
65
65
  let thumbnail = va.findAllAncillaries(withTag: "thumbnail").first
66
- let wallpaper = va.findAllAncillaries(withTag: "wallpaper").first
66
+ let season = va.findAllAncillaries(withTag: "season").first
67
+ let show = va.findAllAncillaries(withTag: "show").first
68
+ let episode = va.findAllAncillaries(withTag: "episode").first
69
+ let thumbnails = Thumbnails(
70
+ thumbnail: thumbnail?.fileDownloadURL ?? "",
71
+ season: season?.fileDownloadURL ?? "",
72
+ show: show?.fileDownloadURL ?? "",
73
+ episode: episode?.fileDownloadURL ?? ""
74
+ )
75
+
76
+ let dataItem = DataItem(
77
+ title: va.userInfo?["title"] as? String,
78
+ seasonId: va.userInfo?["seasonId"] as? String,
79
+ offers: parseOffers(offer: va.userInfo?["offers"] as Any),
80
+ customFields: parseCustomFields( anyElement: va.userInfo?["customFields"] as Any),
81
+ classification: parseClassification( anyElement: va.userInfo?["classification"] as Any)
82
+
83
+ )
67
84
  let catalog = OfflineCatalog(
68
85
  id: va.assetID,
69
- thumbnail: thumbnail?.localFilePath ?? "",
70
- wallpaper: wallpaper?.localFilePath ?? "",
86
+ title: va.description,
87
+ data: dataItem,
88
+ thumbnails: thumbnails,
71
89
  isCompleted: va.isPlayable,
72
90
  isPaused: va.isPaused)
73
91
  offlineCatalogs.append(catalog)
74
92
  }
75
-
93
+
76
94
  for case let va as VirtuosoAsset in pendingAssets {
77
95
  let catalog = OfflineCatalog(
78
96
  id: va.assetID,
97
+ data: DataItem(),
79
98
  isCompleted: false,
80
- isPaused: va.isPaused)
99
+ isPaused: va.isPaused
100
+ )
81
101
  offlineCatalogs.append(catalog)
82
102
  }
83
-
103
+
84
104
  let decoder = JSONEncoder()
85
105
  do {
86
106
  let data = try decoder.encode(offlineCatalogs)
@@ -91,9 +111,8 @@ class Penthera: RCTEventEmitter, VirtuosoDownloadEngineNotificationsDelegate {
91
111
  }
92
112
  //resolve(downloadComplete.map{ ($0 as? VirtuosoAsset)?.assetID })
93
113
  }
94
-
114
+
95
115
  func getDownloadedAsset(assetID: String) -> VirtuosoAsset? {
96
- print("Entra getDownloadedAsset>>>")
97
116
  // assets that have finished downloading
98
117
  let completedAssets = VirtuosoAsset.completedAssets(withAvailabilityFilter: false)
99
118
  guard let asset = completedAssets.filter({ ($0 as! VirtuosoAsset).assetID == assetID }).first as? VirtuosoAsset else {
@@ -101,45 +120,41 @@ class Penthera: RCTEventEmitter, VirtuosoDownloadEngineNotificationsDelegate {
101
120
  }
102
121
  return asset
103
122
  }
104
-
123
+
105
124
  public func downloadEngineDidStartDownloadingAsset(_ asset: VirtuosoAsset) {
106
125
  EventEmitter.sharedInstance.dispatch(name: "penthera", code: PentheraEvent.DID_START_DOWNLOADING, assetId: asset.assetID, body: "")
107
126
  }
108
-
127
+
109
128
  public func downloadEngineProgressUpdated(for asset: VirtuosoAsset) {
110
129
  let percentage: Float = Float(asset.fractionComplete)/Float(asset.estimatedSize)
111
130
  if(percentage.isFinite) {
112
131
  EventEmitter.sharedInstance.dispatch(name: "penthera", code: PentheraEvent.PROGRESS_UPDATED, assetId: asset.assetID, body: "\(Int(asset.fractionComplete*100))")
113
132
  }
114
133
  }
115
-
134
+
116
135
  public func downloadEngineProgressUpdatedProcessing(for asset: VirtuosoAsset) {
117
-
136
+
118
137
  }
119
-
138
+
120
139
  public func downloadEngineDidFinishDownloadingAsset(_ asset: VirtuosoAsset) {
121
140
  EventEmitter.sharedInstance.dispatch(name: "penthera", code: PentheraEvent.DOWNLOAD_COMPLETE, assetId: asset.assetID, body: "")
122
141
  }
123
-
142
+
124
143
  public func downloadEngineDidEncounterError(for asset: VirtuosoAsset, error: Error?, task: URLSessionTask?, data: Data?, statusCode: NSNumber?) {
125
144
  asset.delete()
126
145
  EventEmitter.sharedInstance.dispatch(name: "penthera", code: PentheraEvent.ERROR_DOWNLOAD, assetId: asset.assetID, body: error.debugDescription ?? "Error downloading")
127
146
  /*EventEmitter.sharedInstance.dispatch(name: "penthera", body: "\(asset.assetID): Engine did encounter error \(error?.localizedDescription ?? "-")")*/
128
147
  }
129
-
148
+
130
149
  public func downloadEngineInternalQueueUpdate(asset: VirtuosoAsset) {
131
150
  //EventEmitter.sharedInstance.dispatch(name: "penthera", code: "TEST downloadEngineInternalQueueUpdate", body: "Queue updated", assetId: asset.assetID)
132
151
  EventEmitter.sharedInstance.dispatch(name: "penthera", code: "TEST downloadEngineInternalQueueUpdate", assetId: asset.assetID, body: "Queue updated")
133
152
  }
134
-
153
+
135
154
  public func downloadEngineStartupComplete(_ succeeded: Bool, asset: VirtuosoAsset) {
136
155
  //EventEmitter.sharedInstance.dispatch(name: "penthera", code: "Test downloadEngineStartupComplete", body: "SDK startup complete", assetId: asset.assetID)
137
156
  EventEmitter.sharedInstance.dispatch(name: "penthera", code: "TEST downloadEngineStartupComplete", assetId: asset.assetID, body: "SDK startup complete")
138
157
  }
139
-
140
-
141
-
142
-
143
158
  func getPendingAsset(assetID: String) -> VirtuosoAsset? {
144
159
  let pendingAssets = VirtuosoAsset.pendingAssets(withAvailabilityFilter: false)
145
160
  guard let asset = pendingAssets.filter({ ($0 as! VirtuosoAsset).assetID == assetID }).first as? VirtuosoAsset else {
@@ -147,7 +162,6 @@ class Penthera: RCTEventEmitter, VirtuosoDownloadEngineNotificationsDelegate {
147
162
  }
148
163
  return asset
149
164
  }
150
-
151
165
  func getAncillaryFiles(files: [String: AnyObject]) -> [VirtuosoAncillaryFile] {
152
166
  var ancillaryFiles: [VirtuosoAncillaryFile] = []
153
167
  files.forEach { file in
@@ -166,14 +180,14 @@ class Penthera: RCTEventEmitter, VirtuosoDownloadEngineNotificationsDelegate {
166
180
  func download(catalogString: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
167
181
  let virtuoso = VirtuosoDownloadEngine.instance()
168
182
  var queue = virtuoso.assetsInQueue()
169
-
183
+
170
184
  //let decoder = JSONDecoder()
171
185
 
172
186
  do {
173
187
 
174
-
188
+
175
189
  let data = catalogString.getDictionary()
176
-
190
+
177
191
  guard let item = data!["item"] as! [String: AnyObject]? else {
178
192
  reject("No item", nil, nil)
179
193
  return
@@ -182,36 +196,35 @@ class Penthera: RCTEventEmitter, VirtuosoDownloadEngineNotificationsDelegate {
182
196
  reject("No url", nil, nil)
183
197
  return
184
198
  }
185
-
199
+
186
200
  let assetID = item["id"] as! String? ?? ""
187
201
  let hasDRM = item["drm"] as! Bool? ?? false
188
-
202
+ let title = item["title"] as! String? ?? ""
203
+
189
204
  let downloadAsset = getDownloadedAsset(assetID: assetID)
190
205
  let pendingAsset = getPendingAsset(assetID: assetID)
191
-
206
+
192
207
  if (pendingAsset != nil) {
193
208
  EventEmitter.sharedInstance.dispatch(name: "penthera", code: PentheraEvent.PENDING_ASSET_FOUND, assetId: assetID, body: "")
194
209
  pendingAsset?.delete()
195
210
  return
196
211
  }
197
-
212
+
198
213
  if(downloadAsset == nil && pendingAsset == nil) {
199
-
200
214
  DispatchQueue.global(qos: .background).async {
201
215
  guard let config = VirtuosoAssetConfig(url: url,
202
216
  assetID: assetID,
203
- description: "\(assetID)",
217
+ description: String(describing: title),
204
218
  type: .vde_AssetTypeHLS) else {
205
219
  EventEmitter.sharedInstance.dispatch(name: "penthera", code: PentheraEvent.CONFIG_ASSET_FAILED, assetId: assetID, body: "-")
206
220
  return
207
221
  }
208
-
209
222
  // Ancillary Files
210
223
  let thumbnails = item["thumbnails"] as! [String: AnyObject]? ?? [:]
211
224
  let subtitles = item["subtitles"] as! [String: AnyObject]? ?? [:]
212
225
  config.ancillaries = self.getAncillaryFiles(files: thumbnails) + self.getAncillaryFiles(files: subtitles)
213
-
214
-
226
+
227
+
215
228
  //DRM
216
229
  if(hasDRM) {
217
230
 
@@ -237,33 +250,33 @@ class Penthera: RCTEventEmitter, VirtuosoDownloadEngineNotificationsDelegate {
237
250
  config.protectionType = .vde_AssetProtectionTypeFairPlay
238
251
 
239
252
  }
240
-
253
+
241
254
  let asset = VirtuosoAsset.init(config: config)
242
-
255
+
243
256
  let data = item["data"] as! [String: AnyObject]? ?? [:]
244
-
257
+
245
258
  asset?.userInfo = data
246
-
259
+
247
260
  config.ancillaries?.forEach{ file in
248
261
  asset?.add(file)
249
262
  }
250
-
251
-
263
+
264
+
252
265
  //asset?.add(subtitle!)
253
-
266
+
254
267
  //let calendar = Calendar.current
255
268
  //guard let expiryDate = calendar.date(byAdding: .minute, value: 1, to: Date()) else {
256
269
  // return
257
270
  //}
258
-
271
+
259
272
  //asset?.expiryAfterDownload = expiryDate.timeIntervalSinceNow
260
-
273
+
261
274
  queue.append(asset!)
262
275
  resolve(assetID)
263
276
  //resolve(queue.count)
264
277
  }
265
278
  }
266
-
279
+
267
280
  } catch {
268
281
  reject("penthera", error.localizedDescription, error)
269
282
  }
@@ -272,17 +285,22 @@ class Penthera: RCTEventEmitter, VirtuosoDownloadEngineNotificationsDelegate {
272
285
  @objc(delete:withResolver:withRejecter:)
273
286
  func delete(assetID: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
274
287
  //DispatchQueue.global(qos: .background).async {
275
-
288
+
276
289
  let downloadComplete = VirtuosoAsset.completedAssets(withAvailabilityFilter: false)
277
290
  if(downloadComplete.count > 0) {
278
- (downloadComplete.first as! VirtuosoAsset).delete()
291
+ for case let va as VirtuosoAsset in downloadComplete {
292
+ if(va.assetID == assetID){
293
+ va.delete()
294
+ }
295
+ }
296
+ //(downloadComplete.first as! VirtuosoAsset).delete()
279
297
  }
280
298
  resolve("Delete complete")
281
- DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
299
+ DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
282
300
  EventEmitter.sharedInstance.dispatch(name: "penthera", code: PentheraEvent.ASSET_DELETED, assetId: assetID, body: "")
283
301
  }
284
302
  }
285
-
303
+
286
304
  @objc open override func supportedEvents() -> [String] {
287
305
  return EventEmitter.sharedInstance.allEvents
288
306
  }
@@ -295,43 +313,43 @@ class Penthera: RCTEventEmitter, VirtuosoDownloadEngineNotificationsDelegate {
295
313
  reject("Error streaming asset", "", nil)
296
314
  return
297
315
  }
298
-
316
+
299
317
  let decoder = JSONEncoder()
300
-
318
+
301
319
  do {
302
-
303
-
320
+
321
+
304
322
  // let subtitle = vcHttpServer?.ancillaryURLForAncillary(withTag: "subtitle", usingMime: "text/vtt")
305
323
  // let thumbnailOffline = asset.findAllAncillaries(withTag: "thumbnailOffline").first
306
324
  //let wallpaper = asset.findAllAncillaries(withTag: "wallpaper").first
307
-
325
+
308
326
  let vcHttpServer = VirtuosoClientHTTPServer(asset: asset)
309
-
327
+
310
328
  let licenseURL = vcHttpServer?.fairPlayLicenseServerURL
311
329
  let certificateURL = vcHttpServer?.fairPlayCertificateDataURL(forSubType: nil)
312
-
330
+
313
331
  //let avContentKeySession = VirtuosoLicenseManager.registeredAVContentKeySession()
314
-
332
+
315
333
  //let userInfoData = try encoder.encode(asset.userInfo)
316
334
  //let userInfo = String(data: userInfoData, encoding: .utf8)
317
-
335
+
318
336
  let assetData = [
319
337
  "id": asset.assetID,
320
338
  "url": vcHttpServer?.playbackURL ?? "",
321
339
  "certificate": certificateURL ,
322
340
  "license": licenseURL
323
341
  ]
324
-
342
+
325
343
  let data = try decoder.encode(assetData)
326
344
  let json = String(data: data, encoding: .utf8)!
327
345
  resolve(json)
328
-
346
+
329
347
  // let config = PlayerConfig()
330
348
  // config.styleConfig.userInterfaceType = .system
331
349
  // config.key = "ASSSSSS"
332
-
350
+
333
351
  // let player = PlayerFactory.create(playerConfig: config)
334
-
352
+
335
353
  // guard let streamUrl = URL(string: vcHttpServer!.playbackURL) else {
336
354
  // return
337
355
  // }
@@ -342,23 +360,23 @@ class Penthera: RCTEventEmitter, VirtuosoDownloadEngineNotificationsDelegate {
342
360
 
343
361
  // // Optionally set additional properties
344
362
  // sourceConfig.title = "Art of motion"
345
-
363
+
346
364
  // DispatchQueue.main.async {
347
365
  // let source = SourceFactory.create(from: sourceConfig)
348
-
366
+
349
367
  // player.load(source: source)
350
-
351
-
368
+
369
+
352
370
  // let viewController = UIApplication.shared.windows.first?.rootViewController as? UIViewController
353
-
371
+
354
372
  // let playerView = PlayerView(player: player, frame: (viewController?.view.bounds)!)
355
-
373
+
356
374
  // // Adding the view to the a container View
357
375
  // viewController?.view.addSubview(playerView)
358
376
  // viewController?.view.bringSubviewToFront(playerView)
359
377
  // }
360
-
361
-
378
+
379
+
362
380
  /*
363
381
  let demoPlayer = DemoPlayerViewController()
364
382
  DispatchQueue.main.async {
@@ -366,7 +384,7 @@ class Penthera: RCTEventEmitter, VirtuosoDownloadEngineNotificationsDelegate {
366
384
  andPlayer: demoPlayer as VirtuosoPlayer,
367
385
  onSuccess: {
368
386
  // Present the player
369
-
387
+
370
388
  let viewController = UIApplication.shared.windows.first?.rootViewController as? UIViewController
371
389
  viewController?.present(demoPlayer, animated: true)
372
390
  //self.present(demoPlayer, animated: true, completion: nil)
@@ -375,10 +393,27 @@ class Penthera: RCTEventEmitter, VirtuosoDownloadEngineNotificationsDelegate {
375
393
  //self.error = nil
376
394
  })
377
395
  }*/
378
-
396
+
379
397
  } catch {
380
398
  reject("penthere", error.localizedDescription, error)
381
399
  }
382
400
  }
401
+
402
+
403
+ @objc(pauseDownload:withResolver:withRejecter:)
404
+ func pauseDownload(assetID: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
405
+ let pendingAsset = getPendingAsset(assetID: assetID)
406
+ if (pendingAsset != nil) {
407
+ self.pauseAsset(asset: pendingAsset!)
408
+ return
409
+ }
410
+
411
+ }
412
+
413
+ func pauseAsset(asset: VirtuosoAsset) {
414
+ asset.isPaused = !asset.isPaused
415
+ EventEmitter.sharedInstance.dispatch(name: "penthera", code: PentheraEvent.ASSET_RESUME_DOWNLOAD_UPDATED, assetId: asset.assetID, body: "\(asset.isPaused)")
416
+ }
417
+
383
418
 
384
419
  }
package/ios/Util.swift CHANGED
@@ -14,3 +14,75 @@ extension String {
14
14
  return nil
15
15
  }
16
16
  }
17
+
18
+
19
+ func parseOffers(offer: Any) -> Array<Offers> {
20
+ guard let offersArray = offer as? Array<Any> else {
21
+ // fatalError("Invalid JSON")
22
+ print("invalid offer")
23
+ return []
24
+ }
25
+
26
+ var offers = Array<Offers>()
27
+ for offer in offersArray {
28
+ guard let offerDictionary = offer as? Dictionary<String, Any> else {
29
+ //fatalError("Invalid JSON")
30
+ print("invalid offer")
31
+ return []
32
+ }
33
+
34
+ let deliveryType = offerDictionary["deliveryType"] as! String
35
+ let resolution = offerDictionary["resolution"] as! String
36
+ let ownership = offerDictionary["ownership"] as! String
37
+ let scope = offerDictionary["scope"] as! Array<String>?
38
+ let customFields = offerDictionary["customFields"] as! Array<Int>?
39
+
40
+ let offer = Offers(
41
+ deliveryType: deliveryType,
42
+ resolution: resolution,
43
+ ownership: ownership,
44
+ scope: scope,
45
+ customFields: customFields
46
+
47
+ )
48
+ offers.append(offer)
49
+ }
50
+
51
+ return offers
52
+ }
53
+
54
+ func parseClassification(anyElement: Any) -> Classification? {
55
+ // Check if the element is a dictionary.
56
+ if let dictionary = anyElement as? [String: Any] {
57
+ // Create a new `Classification` object from the dictionary.
58
+ let classification = Classification(
59
+ code: dictionary["code"] as! String,
60
+ name: dictionary["name"] as! String
61
+ )
62
+ return classification
63
+ }
64
+ // The element is not a dictionary, so return nil.
65
+ return nil
66
+ }
67
+
68
+ func parseCustomFields(anyElement: Any) -> CustomFields? {
69
+ if let dictionary = anyElement as? [String: Any] {
70
+ let customFields = CustomFields(
71
+ CCFlag: dictionary["CCFlag"] as? String,
72
+ DLFlag: dictionary["DLFlag"] as? String,
73
+ DRM: dictionary["DRM"] as? String,
74
+ HDFlag: dictionary["HDFlag"] as? String,
75
+ IngestionHash: dictionary["IngestionHash"] as? String,
76
+ Now: dictionary["Now"] as? String,
77
+ PayloadId: dictionary["PayloadId"] as? String,
78
+ Premiere: dictionary["Premiere"] as? String,
79
+ PrimaryVpid: dictionary["PrimaryVpid"] as? String,
80
+ SubGenre: dictionary["SubGenre"] as? String,
81
+ IsComingSoon: dictionary["IsComingSoon"] as? String
82
+ )
83
+ return customFields
84
+ }
85
+
86
+ // The element is not a dictionary, so return nil.
87
+ return nil
88
+ }
@@ -6,19 +6,13 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.usePenthera = void 0;
7
7
  var _react = require("react");
8
8
  var _reactNative = require("react-native");
9
- var _reactNativeConfig = _interopRequireDefault(require("react-native-config"));
10
9
  var _reactNativePenthera = require("@takeoffmedia/react-native-penthera");
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
10
  const usePenthera = _ref => {
13
11
  let {
14
12
  data,
15
13
  sessionConnect
16
14
  } = _ref;
17
15
  const [catalog, setCatalogResult] = (0, _react.useState)(data);
18
- (0, _react.useEffect)(() => {
19
- initializePenthera();
20
- // eslint-disable-next-line react-hooks/exhaustive-deps
21
- }, []);
22
16
  (0, _react.useEffect)(() => {
23
17
  const eventListener = listenerPethera();
24
18
  return () => {
@@ -27,17 +21,6 @@ const usePenthera = _ref => {
27
21
  // eslint-disable-next-line react-hooks/exhaustive-deps
28
22
  }, []);
29
23
 
30
- // Start Penthera SDK
31
- const initializePenthera = async () => {
32
- try {
33
- const response = await (0, _reactNativePenthera.initialize)('123456789329329329392392', _reactNativeConfig.default.BACKPLANE_URL, _reactNativeConfig.default.BACKPLANE_PUBLIC_KEY, _reactNativeConfig.default.BACKPLANE_PRIVATE_KEY);
34
- console.log('Penthera initialization successfully', response);
35
- getAllDownloads();
36
- } catch (error) {
37
- console.error('Error: initializePenthera>>', error);
38
- }
39
- };
40
-
41
24
  // Config Event Listener
42
25
  const listenerPethera = () => {
43
26
  const NEventEmitter = _reactNative.NativeModules.Penthera;
@@ -46,6 +29,7 @@ const usePenthera = _ref => {
46
29
  return eventListener;
47
30
  };
48
31
  const downloadVideo = async _ref2 => {
32
+ var _item$thumbnails;
49
33
  let {
50
34
  item,
51
35
  drm,
@@ -54,7 +38,7 @@ const usePenthera = _ref => {
54
38
  const dataBySO = _reactNative.Platform.OS === 'android' ? {
55
39
  asset_id: item.id,
56
40
  content_url: url,
57
- poster: item.thumbnail,
41
+ poster: (_item$thumbnails = item.thumbnails) === null || _item$thumbnails === void 0 ? void 0 : _item$thumbnails.thumbnail,
58
42
  subtitle: '',
59
43
  ...item
60
44
  } : {
@@ -99,6 +83,8 @@ const usePenthera = _ref => {
99
83
  }
100
84
  newCatalog[index].isCompleted = item.isCompleted;
101
85
  newCatalog[index].isPaused = item.isPaused;
86
+ newCatalog[index].thumbnails.thumbnail = item.thumbnails.thumbnail;
87
+ newCatalog[index].thumbnails.show = item.thumbnails.show;
102
88
  setCatalogResult(newCatalog);
103
89
  }
104
90
  });
@@ -131,6 +117,17 @@ const usePenthera = _ref => {
131
117
  setCatalogResult(newCatalog);
132
118
  }
133
119
  };
120
+ const pauseDownloadHandle = async assetId => {
121
+ await (0, _reactNativePenthera.pauseDownload)(assetId);
122
+ };
123
+ const updateDataWhenIsPaused = (assetId, isPause) => {
124
+ const newCatalog = [...catalog];
125
+ let index = newCatalog.findIndex(i => i.id === assetId);
126
+ if (index >= 0) {
127
+ newCatalog[index].isPaused = isPause;
128
+ setCatalogResult(newCatalog);
129
+ }
130
+ };
134
131
  return {
135
132
  catalog,
136
133
  setCatalogResult,
@@ -139,7 +136,9 @@ const usePenthera = _ref => {
139
136
  downloadVideo,
140
137
  getAllDownloads,
141
138
  updateDownload,
142
- deletedAsset
139
+ deletedAsset,
140
+ pauseDownloadHandle,
141
+ updateDataWhenIsPaused
143
142
  };
144
143
  };
145
144
  exports.usePenthera = usePenthera;