@takeoffmedia/react-native-penthera 0.8.9 → 0.9.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.
@@ -338,40 +338,58 @@ class OfflineVideoEngine(private val context: ReactApplicationContext) {
338
338
  }
339
339
 
340
340
 
341
+ private fun buildGetByAssetIdPayload(asset: VirtuosoSegmentedFile): String {
342
+ val keyValueMap = HashMap<String, Any>()
343
+ keyValueMap["offlineUrl"] = asset.playbackURL?.toString() ?: ""
344
+ keyValueMap["metadata"] = asset.metadata.toString()
345
+
346
+ val ancillaryFiles = try {
347
+ (asset as ISegmentedAsset).getAncillaryFiles(context)
348
+ } catch (e: Exception) {
349
+ Log.w("Penthera", "getByAssetId: ancillary files unavailable for ${asset.assetId}", e)
350
+ emptyList<Any>()
351
+ }
352
+ keyValueMap["ancillary"] = ancillaryFiles
353
+
354
+ return gson.toJson(keyValueMap)
355
+ }
356
+
341
357
  fun getByAssetId(assetId: String): String? {
342
358
  return Util.retryWithDelay(maxRetries = 5, delayMillis = 1000) {
343
359
  val list: MutableList<IIdentifier> = virtuoso.assetManager.getByAssetId(assetId)
344
360
  if (list.isNotEmpty()) {
345
361
  val asset = list[0] as VirtuosoSegmentedFile
362
+ val payload = buildGetByAssetIdPayload(asset)
346
363
 
347
- // This is a workaround to handle ancillary files
348
- val offlineUrl = asset.playbackURL
349
- if (offlineUrl != null) {
364
+ // Optional local manifest probe: this must not block offline playback
365
+ val offlineUrl = asset.playbackURL?.toString()
366
+ if (!offlineUrl.isNullOrBlank()) {
350
367
  val request = Request.Builder()
351
- .url(offlineUrl.toString())
368
+ .url(offlineUrl)
352
369
  .build()
353
370
 
354
371
  try {
355
372
  client.newCall(request).execute().use { response ->
356
- if (!response.isSuccessful) throw IOException("Unexpected code $response")
373
+ if (!response.isSuccessful) {
374
+ Log.w(
375
+ "Penthera",
376
+ "getByAssetId: offlineUrl probe failed (${response.code}) for assetId=$assetId"
377
+ )
378
+ }
357
379
  }
358
-
359
- val keyValueMap = HashMap<String, Any>()
360
- keyValueMap["offlineUrl"] = offlineUrl.toString()
361
- keyValueMap["metadata"] = asset.metadata.toString()
362
-
363
- val ancillaryFiles = (asset as ISegmentedAsset).getAncillaryFiles(context)
364
-
365
- // HERE THE ASSET MANIFEST IS REQUESTED
366
- keyValueMap["ancillary"] = ancillaryFiles
367
- return@retryWithDelay gson.toJson(keyValueMap)
368
380
  } catch (e: IOException) {
369
- println("Error: ${e.message}")
381
+ Log.w(
382
+ "Penthera",
383
+ "getByAssetId: offlineUrl probe failed, continuing with local payload",
384
+ e
385
+ )
370
386
  }
371
387
  } else {
372
- // Handle the case where offlineUrl is null
373
- println("Error: offlineUrl is null")
388
+ Log.w("Penthera", "getByAssetId: offlineUrl is null/blank for assetId=$assetId")
374
389
  }
390
+
391
+ // Always return local payload even when the probe fails without internet
392
+ return@retryWithDelay payload
375
393
  }
376
394
  null
377
395
  }
@@ -412,6 +412,30 @@ class Penthera: RCTEventEmitter, VirtuosoDownloadEngineNotificationsDelegate {
412
412
  }
413
413
  }
414
414
 
415
+ @objc(delete:withResolver:withRejecter:)
416
+ func deleteAsset(assetID: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
417
+ let downloadComplete = VirtuosoAsset.completedAssets(withAvailabilityFilter: false)
418
+ let downloadPendings = VirtuosoAsset.pendingAssets(withAvailabilityFilter: false)
419
+ let allAssets = downloadComplete + downloadPendings
420
+
421
+ guard let assetToDelete = allAssets.first(where: {
422
+ guard let va = $0 as? VirtuosoAsset else {
423
+ return false
424
+ }
425
+ return va.assetID == assetID
426
+ }) as? VirtuosoAsset else {
427
+ let errorMessage = "delete: asset not found"
428
+ let userInfo = [NSLocalizedDescriptionKey: errorMessage]
429
+ let error = NSError(domain: "takeoffmedia-react-native-penthera", code: 0, userInfo: userInfo)
430
+ reject("ASSET_DELETE_ERROR", errorMessage, error)
431
+ return
432
+ }
433
+
434
+ VirtuosoAsset.delete([assetToDelete]) {
435
+ resolve(assetID)
436
+ }
437
+ }
438
+
415
439
  @objc(deleteMany:withResolver:withRejecter:)
416
440
  func deleteMany(assetIDS: [String], resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
417
441
  // initialize assetResponse {}. Ex {"123":false, "543":false}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takeoffmedia/react-native-penthera",
3
- "version": "0.8.9",
3
+ "version": "0.9.1",
4
4
  "description": "test",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",