react-native-compressor 1.6.4 → 1.7.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.
Files changed (192) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +41 -27
  3. package/android/build.gradle +95 -42
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +0 -1
  6. package/android/src/main/AndroidManifestNew.xml +2 -0
  7. package/android/src/main/java/com/reactnativecompressor/CompressorModule.java +107 -43
  8. package/android/src/main/java/com/reactnativecompressor/CompressorPackage.java +47 -19
  9. package/android/src/main/java/com/reactnativecompressor/Image/ImageCompressor.java +28 -16
  10. package/android/src/main/java/com/reactnativecompressor/Image/utils/ImageCompressorOptions.java +5 -1
  11. package/android/src/main/java/com/reactnativecompressor/Utils/MediaCache.java +65 -0
  12. package/android/src/main/java/com/reactnativecompressor/Utils/Utils.java +162 -3
  13. package/android/src/main/java/com/reactnativecompressor/Video/VideoCompressorHelper.java +7 -4
  14. package/android/src/main/java/com/reactnativecompressor/Video/VideoModule.java +11 -22
  15. package/android/src/newarch/CompressorSpec.java +9 -0
  16. package/android/src/newarch/VideoCompressorSpec.java +9 -0
  17. package/android/src/oldarch/CompressorSpec.java +34 -0
  18. package/android/src/oldarch/VideoCompressorSpec.java +26 -0
  19. package/ios/Compressor-Bridging-Header.h +1 -0
  20. package/ios/Compressor.h +9 -1
  21. package/ios/Compressor.mm +427 -0
  22. package/ios/Compressor.xcodeproj/project.pbxproj +6 -36
  23. package/ios/Image/ImageCompressor.h +12 -7
  24. package/ios/Image/ImageCompressor.m +164 -67
  25. package/ios/Image/ImageCompressorOptions.h +1 -0
  26. package/ios/Image/ImageCompressorOptions.m +5 -1
  27. package/ios/Utils/Downloader.h +16 -0
  28. package/ios/Utils/Downloader.m +150 -0
  29. package/ios/Utils/MediaCache.h +11 -0
  30. package/ios/Utils/MediaCache.m +51 -0
  31. package/ios/Video/VideoCompressor.swift +14 -5
  32. package/lib/commonjs/Audio/index.js +13 -14
  33. package/lib/commonjs/Audio/index.js.map +1 -1
  34. package/lib/commonjs/Image/index.js +26 -7
  35. package/lib/commonjs/Image/index.js.map +1 -1
  36. package/lib/commonjs/Main.js +29 -0
  37. package/lib/commonjs/Main.js.map +1 -0
  38. package/lib/commonjs/Spec/NativeCompressor.js +10 -0
  39. package/lib/commonjs/Spec/NativeCompressor.js.map +1 -0
  40. package/lib/commonjs/Spec/NativeVideoCompressor.js +10 -0
  41. package/lib/commonjs/Spec/NativeVideoCompressor.js.map +1 -0
  42. package/lib/commonjs/Video/index.js +17 -25
  43. package/lib/commonjs/Video/index.js.map +1 -1
  44. package/lib/commonjs/expo-plugin/compressor.js +1 -4
  45. package/lib/commonjs/expo-plugin/compressor.js.map +1 -1
  46. package/lib/commonjs/index.js +21 -28
  47. package/lib/commonjs/index.js.map +1 -1
  48. package/lib/commonjs/utils/index.js +32 -51
  49. package/lib/commonjs/utils/index.js.map +1 -1
  50. package/lib/module/Audio/index.js +13 -11
  51. package/lib/module/Audio/index.js.map +1 -1
  52. package/lib/module/Image/index.js +27 -6
  53. package/lib/module/Image/index.js.map +1 -1
  54. package/lib/module/Main.js +22 -0
  55. package/lib/module/Main.js.map +1 -0
  56. package/lib/module/Spec/NativeCompressor.js +3 -0
  57. package/lib/module/Spec/NativeCompressor.js.map +1 -0
  58. package/lib/module/Spec/NativeVideoCompressor.js +3 -0
  59. package/lib/module/Spec/NativeVideoCompressor.js.map +1 -0
  60. package/lib/module/Video/index.js +18 -19
  61. package/lib/module/Video/index.js.map +1 -1
  62. package/lib/module/expo-plugin/compressor.js +1 -3
  63. package/lib/module/expo-plugin/compressor.js.map +1 -1
  64. package/lib/module/index.js +8 -5
  65. package/lib/module/index.js.map +1 -1
  66. package/lib/module/utils/index.js +26 -34
  67. package/lib/module/utils/index.js.map +1 -1
  68. package/lib/typescript/Audio/index.d.ts +2 -1
  69. package/lib/typescript/Audio/index.d.ts.map +1 -0
  70. package/lib/typescript/Image/index.d.ts +11 -6
  71. package/lib/typescript/Image/index.d.ts.map +1 -0
  72. package/lib/typescript/Main.d.ts +4 -0
  73. package/lib/typescript/Main.d.ts.map +1 -0
  74. package/lib/typescript/Spec/NativeCompressor.d.ts +14 -0
  75. package/lib/typescript/Spec/NativeCompressor.d.ts.map +1 -0
  76. package/lib/typescript/Spec/NativeVideoCompressor.d.ts +13 -0
  77. package/lib/typescript/Spec/NativeVideoCompressor.d.ts.map +1 -0
  78. package/lib/typescript/Video/index.d.ts +5 -3
  79. package/lib/typescript/Video/index.d.ts.map +1 -0
  80. package/lib/typescript/expo-plugin/compressor.d.ts +2 -3
  81. package/lib/typescript/expo-plugin/compressor.d.ts.map +1 -0
  82. package/lib/typescript/index.d.ts +7 -3
  83. package/lib/typescript/index.d.ts.map +1 -0
  84. package/lib/typescript/utils/index.d.ts +6 -4
  85. package/lib/typescript/utils/index.d.ts.map +1 -0
  86. package/package.json +62 -38
  87. package/react-native-compressor.podspec +24 -1
  88. package/src/Audio/index.tsx +6 -4
  89. package/src/Image/index.tsx +38 -5
  90. package/src/Main.tsx +41 -0
  91. package/src/Spec/NativeCompressor.ts +15 -0
  92. package/src/Spec/NativeVideoCompressor.ts +14 -0
  93. package/src/Video/index.tsx +28 -11
  94. package/src/expo-plugin/compressor.ts +2 -1
  95. package/src/index.tsx +7 -2
  96. package/src/utils/index.tsx +11 -5
  97. package/android/.gradle/6.9/executionHistory/executionHistory.lock +0 -0
  98. package/android/.gradle/6.9/fileChanges/last-build.bin +0 -0
  99. package/android/.gradle/6.9/fileHashes/fileHashes.bin +0 -0
  100. package/android/.gradle/6.9/fileHashes/fileHashes.lock +0 -0
  101. package/android/.gradle/6.9/gc.properties +0 -0
  102. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  103. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  104. package/android/.gradle/checksums/checksums.lock +0 -0
  105. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  106. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  107. package/android/.gradle/vcs-1/gc.properties +0 -0
  108. package/android/.idea/caches/build_file_checksums.ser +0 -0
  109. package/android/.idea/compiler.xml +0 -6
  110. package/android/.idea/gradle.xml +0 -20
  111. package/android/.idea/jarRepositories.xml +0 -45
  112. package/android/.idea/libraries/Gradle__androidx_annotation_annotation_1_1_0.xml +0 -13
  113. package/android/.idea/libraries/Gradle__androidx_appcompat_appcompat_1_0_2_aar.xml +0 -24
  114. package/android/.idea/libraries/Gradle__androidx_arch_core_core_common_2_0_0.xml +0 -11
  115. package/android/.idea/libraries/Gradle__androidx_arch_core_core_runtime_2_0_0_aar.xml +0 -19
  116. package/android/.idea/libraries/Gradle__androidx_asynclayoutinflater_asynclayoutinflater_1_0_0_aar.xml +0 -19
  117. package/android/.idea/libraries/Gradle__androidx_autofill_autofill_1_1_0_aar.xml +0 -16
  118. package/android/.idea/libraries/Gradle__androidx_collection_collection_1_0_0.xml +0 -11
  119. package/android/.idea/libraries/Gradle__androidx_coordinatorlayout_coordinatorlayout_1_0_0_aar.xml +0 -24
  120. package/android/.idea/libraries/Gradle__androidx_core_core_1_1_0_aar.xml +0 -16
  121. package/android/.idea/libraries/Gradle__androidx_cursoradapter_cursoradapter_1_0_0_aar.xml +0 -19
  122. package/android/.idea/libraries/Gradle__androidx_customview_customview_1_0_0_aar.xml +0 -19
  123. package/android/.idea/libraries/Gradle__androidx_documentfile_documentfile_1_0_0_aar.xml +0 -19
  124. package/android/.idea/libraries/Gradle__androidx_drawerlayout_drawerlayout_1_0_0_aar.xml +0 -24
  125. package/android/.idea/libraries/Gradle__androidx_fragment_fragment_1_0_0_aar.xml +0 -24
  126. package/android/.idea/libraries/Gradle__androidx_interpolator_interpolator_1_0_0_aar.xml +0 -19
  127. package/android/.idea/libraries/Gradle__androidx_legacy_legacy_support_core_ui_1_0_0_aar.xml +0 -19
  128. package/android/.idea/libraries/Gradle__androidx_legacy_legacy_support_core_utils_1_0_0_aar.xml +0 -19
  129. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_common_2_0_0.xml +0 -11
  130. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_2_0_0_aar.xml +0 -19
  131. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_livedata_core_2_0_0_aar.xml +0 -19
  132. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_runtime_2_0_0_aar.xml +0 -19
  133. package/android/.idea/libraries/Gradle__androidx_lifecycle_lifecycle_viewmodel_2_0_0_aar.xml +0 -19
  134. package/android/.idea/libraries/Gradle__androidx_loader_loader_1_0_0_aar.xml +0 -19
  135. package/android/.idea/libraries/Gradle__androidx_localbroadcastmanager_localbroadcastmanager_1_0_0_aar.xml +0 -19
  136. package/android/.idea/libraries/Gradle__androidx_print_print_1_0_0_aar.xml +0 -24
  137. package/android/.idea/libraries/Gradle__androidx_slidingpanelayout_slidingpanelayout_1_0_0_aar.xml +0 -19
  138. package/android/.idea/libraries/Gradle__androidx_swiperefreshlayout_swiperefreshlayout_1_0_0_aar.xml +0 -24
  139. package/android/.idea/libraries/Gradle__androidx_vectordrawable_vectordrawable_1_0_1_aar.xml +0 -19
  140. package/android/.idea/libraries/Gradle__androidx_vectordrawable_vectordrawable_animated_1_0_0_aar.xml +0 -19
  141. package/android/.idea/libraries/Gradle__androidx_versionedparcelable_versionedparcelable_1_1_0_aar.xml +0 -13
  142. package/android/.idea/libraries/Gradle__androidx_viewpager_viewpager_1_0_0_aar.xml +0 -19
  143. package/android/.idea/libraries/Gradle__com_facebook_fbjni_fbjni_java_only_0_2_2.xml +0 -13
  144. package/android/.idea/libraries/Gradle__com_facebook_fresco_drawee_2_5_0_aar.xml +0 -15
  145. package/android/.idea/libraries/Gradle__com_facebook_fresco_fbcore_2_5_0_aar.xml +0 -18
  146. package/android/.idea/libraries/Gradle__com_facebook_fresco_fresco_2_5_0_aar.xml +0 -18
  147. package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_2_5_0_aar.xml +0 -18
  148. package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_base_2_5_0_aar.xml +0 -18
  149. package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_native_2_5_0_aar.xml +0 -15
  150. package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_okhttp3_2_5_0_aar.xml +0 -15
  151. package/android/.idea/libraries/Gradle__com_facebook_fresco_memory_type_ashmem_2_5_0_aar.xml +0 -15
  152. package/android/.idea/libraries/Gradle__com_facebook_fresco_memory_type_java_2_5_0_aar.xml +0 -15
  153. package/android/.idea/libraries/Gradle__com_facebook_fresco_memory_type_native_2_5_0_aar.xml +0 -15
  154. package/android/.idea/libraries/Gradle__com_facebook_fresco_nativeimagefilters_2_5_0_aar.xml +0 -15
  155. package/android/.idea/libraries/Gradle__com_facebook_fresco_nativeimagetranscoder_2_5_0_aar.xml +0 -15
  156. package/android/.idea/libraries/Gradle__com_facebook_fresco_ui_common_2_5_0_aar.xml +0 -15
  157. package/android/.idea/libraries/Gradle__com_facebook_infer_annotation_infer_annotation_0_18_0.xml +0 -13
  158. package/android/.idea/libraries/Gradle__com_facebook_react_react_native_0_66_1_aar.xml +0 -14
  159. package/android/.idea/libraries/Gradle__com_facebook_soloader_annotation_0_10_1.xml +0 -13
  160. package/android/.idea/libraries/Gradle__com_facebook_soloader_nativeloader_0_10_1.xml +0 -13
  161. package/android/.idea/libraries/Gradle__com_facebook_soloader_soloader_0_10_1_aar.xml +0 -15
  162. package/android/.idea/libraries/Gradle__com_facebook_yoga_proguard_annotations_1_19_0.xml +0 -13
  163. package/android/.idea/libraries/Gradle__com_google_code_findbugs_jsr305_3_0_2.xml +0 -13
  164. package/android/.idea/libraries/Gradle__com_googlecode_mp4parser_isoparser_1_0_6.xml +0 -13
  165. package/android/.idea/libraries/Gradle__com_squareup_okhttp3_okhttp_4_9_1.xml +0 -13
  166. package/android/.idea/libraries/Gradle__com_squareup_okhttp3_okhttp_urlconnection_4_9_1.xml +0 -13
  167. package/android/.idea/libraries/Gradle__com_squareup_okio_okio_2_9_0.xml +0 -13
  168. package/android/.idea/libraries/Gradle__io_github_lizhangqu_coreprogress_1_0_2_aar.xml +0 -18
  169. package/android/.idea/libraries/Gradle__javax_inject_javax_inject_1.xml +0 -13
  170. package/android/.idea/libraries/Gradle__org_aspectj_aspectjrt_1_8_2.xml +0 -13
  171. package/android/.idea/libraries/Gradle__org_jetbrains_annotations_13_0.xml +0 -13
  172. package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_annotations_jvm_1_3_72.xml +0 -13
  173. package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_4_10.xml +0 -13
  174. package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_common_1_4_10.xml +0 -13
  175. package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_jdk7_1_4_10.xml +0 -13
  176. package/android/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_jdk8_1_4_10.xml +0 -13
  177. package/android/.idea/libraries/Gradle__org_jetbrains_kotlinx_kotlinx_coroutines_android_1_4_0.xml +0 -13
  178. package/android/.idea/libraries/Gradle__org_jetbrains_kotlinx_kotlinx_coroutines_core_jvm_1_4_0.xml +0 -13
  179. package/android/.idea/misc.xml +0 -9
  180. package/android/.idea/modules/android.iml +0 -138
  181. package/android/.idea/modules.xml +0 -8
  182. package/android/.idea/vcs.xml +0 -6
  183. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  184. package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
  185. package/android/gradlew +0 -183
  186. package/android/gradlew.bat +0 -100
  187. package/android/local.properties +0 -8
  188. package/ios/Compressor.m +0 -351
  189. package/ios/Compressor.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  190. package/ios/Compressor.xcodeproj/project.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  191. package/ios/Compressor.xcodeproj/xcshareddata/xcschemes/Compressor.xcscheme +0 -67
  192. package/ios/Compressor.xcodeproj/xcuserdata/apple.xcuserdatad/xcschemes/xcschememanagement.plist +0 -22
@@ -7,8 +7,24 @@
7
7
  #import <React/RCTConvert.h>
8
8
  #import <Foundation/Foundation.h>
9
9
  #import <MobileCoreServices/MobileCoreServices.h>
10
+ #import <React/RCTEventEmitter.h>
11
+ #import "../Utils/Downloader.h"
12
+ #import "react_native_compressor-Swift.h"
13
+ #import "VideoCompressor.h"
14
+ #import "MediaCache.h"
10
15
 
11
16
  @implementation ImageCompressor
17
+ Compressor *sharedCompressorObject;
18
+ id sharedVideoCompressorObject;
19
+
20
+ + (void)initCompressorInstance:(Compressor*)instance {
21
+ sharedCompressorObject=instance;
22
+ }
23
+
24
+ + (void)initVideoCompressorInstance:(id)object {
25
+ sharedVideoCompressorObject=object;
26
+ }
27
+
12
28
  + (CGSize) findTargetSize: (UIImage *) image maxWidth: (int) maxWidth maxHeight: (int) maxHeight {
13
29
  CGFloat width = image.size.width;
14
30
  CGFloat height = image.size.height;
@@ -293,86 +309,167 @@
293
309
  return returnablePath;
294
310
  }
295
311
 
296
- +(void)getAbsoluteImagePath:(NSString *)imagePath completionHandler:(void (^)(NSString *absoluteImagePath))completionHandler
312
+
313
+ + (void)getFileSizeFromURL:(NSString *)urlString completion:(void (^)(NSNumber *fileSize, NSError *error))completion {
314
+ NSURL *url = [NSURL URLWithString:urlString];
315
+ NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
316
+ [request setHTTPMethod:@"HEAD"];
317
+
318
+ NSURLSession *session = [NSURLSession sharedSession];
319
+ NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
320
+ if (error) {
321
+ if (completion) {
322
+ completion(nil, error);
323
+ }
324
+ return;
325
+ }
326
+
327
+ if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
328
+ NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
329
+ long long contentLength = [httpResponse expectedContentLength];
330
+ if (completion) {
331
+ completion([NSNumber numberWithLongLong:contentLength], nil);
332
+ }
333
+ } else {
334
+ if (completion) {
335
+ completion(nil, [NSError errorWithDomain:@"FileDownloadError" code:-1 userInfo:@{NSLocalizedDescriptionKey: @"Invalid response."}]);
336
+ }
337
+ }
338
+ }];
339
+
340
+ [task resume];
341
+ }
342
+
343
+
344
+ + (void)sendProgressUpdate:(NSNumber*)progress uuid:(NSString *)uuid type:(NSString *)type {
345
+ NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
346
+ NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
347
+ params[@"uuid"] = uuid;
348
+ data[@"progress"] = progress;
349
+ params[@"data"] = data;
350
+
351
+ if(type==@"image")
352
+ {
353
+ [sharedCompressorObject sendEventWithName:@"downloadProgress" body:params];
354
+ }
355
+ else
356
+ {
357
+ [sharedVideoCompressorObject sendEventWithName:@"downloadProgress" body:params];
358
+ }
359
+
360
+ }
361
+
362
+
363
+ + (void)downloadFileAndSaveToCache:(NSString *)fileUrl uuid:(NSString *)uuid type:(NSString *)type completion:(void (^)(NSString *downloadedPath))completion {
364
+
365
+ Downloader *downloader = [[Downloader alloc] init];
366
+ [downloader downloadFile:fileUrl downloadCompleteCallback:^(NSString *filePath) {
367
+ [MediaCache addCompletedImagePath:filePath];
368
+ NSLog(@"download completed file path: %@",filePath);
369
+ completion(filePath);
370
+ } progressCallback:^(NSNumber * progress) {
371
+ [self sendProgressUpdate:progress uuid:uuid type:type];
372
+
373
+ } errorCallback:^(NSError * error) {
374
+ NSLog(@"error downloadFile",error);
375
+ }];
376
+ }
377
+
378
+ +(void)getAbsoluteImagePath:(NSString *)imagePath uuid:(NSString *)uuid completionHandler:(void (^)(NSString *absoluteImagePath))completionHandler
297
379
  {
298
- if (![imagePath containsString:@"ph://"]) {
299
- completionHandler(imagePath);
300
- return;
301
- }
302
- NSURL *imageURL = [NSURL URLWithString:[imagePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"]];
303
- CGSize size = CGSizeZero;
304
- CGFloat scale = 1;
305
- RCTResizeMode resizeMode = RCTResizeModeContain;
306
- NSString *assetID = @"";
307
- PHFetchResult *results;
308
- if (!imageURL) {
309
- NSString *errorText = @"Cannot load a photo library asset with no URL";
310
- @throw([NSException exceptionWithName:errorText reason:errorText userInfo:nil]);
311
- } else if ([imageURL.scheme caseInsensitiveCompare:@"assets-library"] == NSOrderedSame) {
312
- assetID = [imageURL absoluteString];
313
- results = [PHAsset fetchAssetsWithALAssetURLs:@[imageURL] options:nil];
314
- } else {
315
- assetID = [imageURL.absoluteString substringFromIndex:@"ph://".length];
316
- results = [PHAsset fetchAssetsWithLocalIdentifiers:@[assetID] options:nil];
317
- }
318
- if (results.count == 0) {
319
- NSString *errorText = [NSString stringWithFormat:@"Failed to fetch PHAsset with local identifier %@ with no error message.", assetID];
320
- @throw([NSException exceptionWithName:errorText reason:errorText userInfo:nil]);
321
- }
322
- PHAsset *asset = [results firstObject]; // <-- WE GOT THE ASSET
323
- PHImageRequestOptions *imageOptions = [PHImageRequestOptions new];
324
- imageOptions.networkAccessAllowed = YES;
325
- imageOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
326
-
327
- BOOL useMaximumSize = CGSizeEqualToSize(size, CGSizeZero);
328
- CGSize targetSize;
329
- if (useMaximumSize) {
330
- targetSize = PHImageManagerMaximumSize;
331
- imageOptions.resizeMode = PHImageRequestOptionsResizeModeNone;
332
- } else {
333
- targetSize = CGSizeApplyAffineTransform(size, CGAffineTransformMakeScale(scale, scale));
334
- imageOptions.resizeMode = PHImageRequestOptionsResizeModeFast;
335
- }
336
-
337
- PHImageContentMode contentMode = PHImageContentModeAspectFill;
338
- if (resizeMode == RCTResizeModeContain) {
339
- contentMode = PHImageContentModeAspectFit;
340
- }
341
- [[PHImageManager defaultManager] requestImageForAsset:asset
342
- targetSize:targetSize
343
- contentMode:contentMode
344
- options:imageOptions
345
- resultHandler:^(UIImage *result, NSDictionary<NSString *, id> *info) {
346
- // WE GOT THE IMAGE
347
- if (result) {
348
- UIImage *image = result;
349
- NSString *imageName = [assetID stringByReplacingOccurrencesOfString:@"/" withString:@"_"];
350
- NSString *imagePath = [self saveImageIntoCache:image withName:imageName];
351
- completionHandler(imagePath);
380
+ if([imagePath hasPrefix:@"http://"]||[imagePath hasPrefix:@"https://"])
381
+ {
382
+ [ImageCompressor downloadFileAndSaveToCache:imagePath uuid:uuid type:@"image" completion:^(NSString *downloadedPath) {
383
+ completionHandler(downloadedPath); // Pass the downloaded path to the completionHandler
384
+ }];
385
+ return;
386
+
387
+ }
388
+ else if (![imagePath containsString:@"ph://"]) {
389
+ completionHandler(imagePath);
390
+ return;
391
+ }
392
+ NSURL *imageURL = [NSURL URLWithString:[imagePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"]];
393
+ CGSize size = CGSizeZero;
394
+ CGFloat scale = 1;
395
+ RCTResizeMode resizeMode = RCTResizeModeContain;
396
+ NSString *assetID = @"";
397
+ PHFetchResult *results;
398
+ if (!imageURL) {
399
+ NSString *errorText = @"Cannot load a photo library asset with no URL";
400
+ @throw([NSException exceptionWithName:errorText reason:errorText userInfo:nil]);
401
+ } else if ([imageURL.scheme caseInsensitiveCompare:@"assets-library"] == NSOrderedSame) {
402
+ assetID = [imageURL absoluteString];
403
+ results = [PHAsset fetchAssetsWithALAssetURLs:@[imageURL] options:nil];
352
404
  } else {
353
- @throw([NSException exceptionWithName:@"image not found" reason:@"image not found" userInfo:nil]);
405
+ assetID = [imageURL.absoluteString substringFromIndex:@"ph://".length];
406
+ results = [PHAsset fetchAssetsWithLocalIdentifiers:@[assetID] options:nil];
407
+ }
408
+ if (results.count == 0) {
409
+ NSString *errorText = [NSString stringWithFormat:@"Failed to fetch PHAsset with local identifier %@ with no error message.", assetID];
410
+ @throw([NSException exceptionWithName:errorText reason:errorText userInfo:nil]);
354
411
  }
355
- }];
412
+ PHAsset *asset = [results firstObject]; // <-- WE GOT THE ASSET
413
+ PHImageRequestOptions *imageOptions = [PHImageRequestOptions new];
414
+ imageOptions.networkAccessAllowed = YES;
415
+ imageOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
416
+
417
+ BOOL useMaximumSize = CGSizeEqualToSize(size, CGSizeZero);
418
+ CGSize targetSize;
419
+ if (useMaximumSize) {
420
+ targetSize = PHImageManagerMaximumSize;
421
+ imageOptions.resizeMode = PHImageRequestOptionsResizeModeNone;
422
+ } else {
423
+ targetSize = CGSizeApplyAffineTransform(size, CGAffineTransformMakeScale(scale, scale));
424
+ imageOptions.resizeMode = PHImageRequestOptionsResizeModeFast;
425
+ }
426
+
427
+ PHImageContentMode contentMode = PHImageContentModeAspectFill;
428
+ if (resizeMode == RCTResizeModeContain) {
429
+ contentMode = PHImageContentModeAspectFit;
430
+ }
431
+ [[PHImageManager defaultManager] requestImageForAsset:asset
432
+ targetSize:targetSize
433
+ contentMode:contentMode
434
+ options:imageOptions
435
+ resultHandler:^(UIImage *result, NSDictionary<NSString *, id> *info) {
436
+ // WE GOT THE IMAGE
437
+ if (result) {
438
+ UIImage *image = result;
439
+ NSString *imageName = [assetID stringByReplacingOccurrencesOfString:@"/" withString:@"_"];
440
+ NSString *imagePath = [self saveImageIntoCache:image withName:imageName];
441
+ completionHandler(imagePath);
442
+ } else {
443
+ @throw([NSException exceptionWithName:@"image not found" reason:@"image not found" userInfo:nil]);
444
+ }
445
+ }];
356
446
  }
357
447
 
358
448
  +(NSString*) saveImageIntoCache:(UIImage *)image withName:(NSString *)name {
359
- NSData *imageData = UIImageJPEGRepresentation(image, 1);
449
+ NSData *imageData = UIImageJPEGRepresentation(image, 1);
360
450
  NSString *path =[self generateCacheFilePath:@"jpg"];
361
- [[NSFileManager defaultManager] createFileAtPath:path contents:imageData attributes:NULL];
362
- return path;
451
+ [[NSFileManager defaultManager] createFileAtPath:path contents:imageData attributes:NULL];
452
+ return path;
363
453
  }
364
454
 
365
455
  /// for video
366
-
367
- +(void)getAbsoluteVideoPath:(NSString *)videoPath completionHandler:(void (^)(NSString *absoluteImagePath))completionHandler
456
+
457
+ +(void)getAbsoluteVideoPath:(NSString *)videoPath uuid:(NSString *)uuid completionHandler:(void (^)(NSString *absoluteImagePath))completionHandler
368
458
  {
459
+ if([videoPath hasPrefix:@"http://"]||[videoPath hasPrefix:@"https://"])
460
+ {
461
+ [ImageCompressor downloadFileAndSaveToCache:videoPath uuid:uuid type:@"video" completion:^(NSString *downloadedPath) {
462
+ completionHandler(downloadedPath); // Pass the downloaded path to the completionHandler
463
+ }];
464
+ return;
369
465
 
370
- if (![videoPath containsString:@"ph://"]) {
371
- completionHandler(videoPath);
372
- return;
466
+ }
467
+ else if (![videoPath containsString:@"ph://"]) {
468
+ completionHandler(videoPath);
469
+ return;
373
470
  }
374
471
  NSString *assetId =[videoPath stringByReplacingOccurrencesOfString:@"ph://"
375
- withString:@""];
472
+ withString:@""];
376
473
  AVFileType outputFileType = AVFileTypeMPEG4;
377
474
  NSString *pressetType = AVAssetExportPresetPassthrough;
378
475
 
@@ -390,7 +487,7 @@
390
487
  // Getting information from the asset
391
488
  NSString *mimeType = (NSString *)CFBridgingRelease(UTTypeCopyPreferredTagWithClass((__bridge CFStringRef _Nonnull)(outputFileType), kUTTagClassMIMEType));
392
489
  CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (__bridge CFStringRef _Nonnull)(mimeType), NULL);
393
- NSString *extension = (NSString *)CFBridgingRelease(UTTypeCopyPreferredTagWithClass(uti, kUTTagClassFilenameExtension));
490
+ NSString *extension = (NSString *)CFBridgingRelease(UTTypeCopyPreferredTagWithClass(uti, kUTTagClassFilenameExtension));
394
491
 
395
492
  // Creating output url and temp file name
396
493
  NSString *path =[self generateCacheFilePath:extension];
@@ -23,5 +23,6 @@ typedef NS_ENUM(long, ReturnableOutputType) { rbase64,
23
23
  @property(nonatomic, assign) enum OutputType output;
24
24
  @property(nonatomic, assign) enum InputType input;
25
25
  @property(nonatomic, assign) enum ReturnableOutputType returnableOutputType;
26
+ @property(nonatomic, assign) NSString* uuid;
26
27
 
27
28
  @end
@@ -28,7 +28,9 @@
28
28
  [options parseOutput: value];
29
29
  } else if ([key isEqual:@"returnableOutputType"]) {
30
30
  [options parseReturnableOutput: value];
31
- }
31
+ }else if ([key isEqual:@"uuid"]) {
32
+ options.uuid=value;
33
+ }
32
34
  }
33
35
 
34
36
  return options;
@@ -56,6 +58,7 @@
56
58
  self.input = uri;
57
59
  self.output = jpg;
58
60
  self.returnableOutputType = uri;
61
+ self.uuid = uuid;
59
62
  }
60
63
 
61
64
  return self;
@@ -68,6 +71,7 @@
68
71
  @synthesize input;
69
72
  @synthesize output;
70
73
  @synthesize returnableOutputType;
74
+ @synthesize uuid;
71
75
 
72
76
  - (void) parseInput:(NSString*)input {
73
77
  NSDictionary *inputTranslations = @{ @"base64": @(base64), @"uri": @(uri) };
@@ -0,0 +1,16 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ typedef void (^DownloadCompleteCallback)(NSString *filePath);
4
+ typedef void (^ErrorCallback)(NSError*);
5
+ typedef void (^ProgressCallback)(NSNumber*);
6
+
7
+ @interface Downloader : NSObject <NSURLSessionDelegate, NSURLSessionDownloadDelegate>
8
+
9
+ @property (nonatomic, copy) ProgressCallback globalProgressCallback;
10
+ @property (nonatomic, copy) DownloadCompleteCallback globalDownloadCompleteCallback;
11
+ @property (nonatomic, copy) ErrorCallback globalErrorCallback;
12
+
13
+ - (NSString *)downloadFile:(NSString *)fromUrl downloadCompleteCallback:(DownloadCompleteCallback)downloadCompleteCallback progressCallback:(ProgressCallback)progressCallback errorCallback:(ErrorCallback)errorCallback;
14
+ - (NSString *)generateCacheFilePath:(NSString *)extension;
15
+
16
+ @end
@@ -0,0 +1,150 @@
1
+ #import "Downloader.h"
2
+
3
+ @implementation Downloader
4
+
5
+ NSURLSession* _session;
6
+ NSURLSessionDownloadTask* _task;
7
+ NSNumber* _statusCode;
8
+ NSTimeInterval _lastProgressEmitTimestamp;
9
+ NSNumber* _lastProgressValue;
10
+ NSNumber* _contentLength;
11
+ NSNumber* _bytesWritten;
12
+ NSData* _resumeData;
13
+ NSString* _toFile;
14
+
15
+
16
+ ProgressCallback globalProgressCallback;
17
+ DownloadCompleteCallback globalDownloadCompleteCallback;
18
+ ErrorCallback globalErrorCallback;
19
+
20
+ NSFileHandle* _fileHandle;
21
+
22
+ - (NSString *)generateCacheFilePath:(NSString *)extension{
23
+ NSUUID *uuid = [NSUUID UUID];
24
+ NSString *imageNameWihtoutExtension = [uuid UUIDString];
25
+ NSString *imageName=[imageNameWihtoutExtension stringByAppendingPathExtension:extension];
26
+ NSString *filePath =
27
+ [NSTemporaryDirectory() stringByAppendingPathComponent:imageName];
28
+ return filePath;
29
+ }
30
+
31
+ - (NSString *)downloadFile:(NSString *)fromUrl downloadCompleteCallback:(DownloadCompleteCallback)downloadCompleteCallback progressCallback:(ProgressCallback)progressCallback errorCallback:(ErrorCallback)errorCallback
32
+ {
33
+ NSString *uuid = nil;
34
+
35
+ Downloader *downloader = [[Downloader alloc] init];
36
+ globalProgressCallback = progressCallback;
37
+ globalDownloadCompleteCallback = downloadCompleteCallback;
38
+ globalErrorCallback = errorCallback;
39
+
40
+ _lastProgressEmitTimestamp = 0;
41
+ _bytesWritten = 0;
42
+
43
+ NSURL* url = [NSURL URLWithString:fromUrl];
44
+ NSString *fileExtension = [fromUrl pathExtension];
45
+
46
+ NSString *toFile =[self generateCacheFilePath:fileExtension];
47
+ _toFile=toFile;
48
+
49
+ if ([[NSFileManager defaultManager] fileExistsAtPath:toFile]) {
50
+ _fileHandle = [NSFileHandle fileHandleForWritingAtPath:toFile];
51
+
52
+ if (!_fileHandle) {
53
+ NSError* error = [NSError errorWithDomain:@"Downloader" code:NSURLErrorFileDoesNotExist
54
+ userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat: @"Failed to write target file at path: %@", toFile]}];
55
+
56
+ globalErrorCallback(error);
57
+ return nil;
58
+ } else {
59
+ [_fileHandle closeFile];
60
+ }
61
+ }
62
+
63
+ NSURLSessionConfiguration *config;
64
+
65
+ config = [NSURLSessionConfiguration defaultSessionConfiguration];
66
+
67
+ _session = [NSURLSession sessionWithConfiguration:config delegate:downloader delegateQueue:nil];
68
+ _task = [_session downloadTaskWithURL:url];
69
+ [_task resume];
70
+
71
+ return uuid;
72
+ }
73
+
74
+ - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite
75
+ {
76
+ NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)downloadTask.response;
77
+
78
+ _statusCode = [NSNumber numberWithLong:httpResponse.statusCode];
79
+ _contentLength = [NSNumber numberWithLong:httpResponse.expectedContentLength];
80
+
81
+ if ([_statusCode isEqualToNumber:[NSNumber numberWithInt:200]]) {
82
+
83
+ _bytesWritten = @(totalBytesWritten);
84
+
85
+
86
+ double doubleBytesWritten = (double)[_bytesWritten longValue];
87
+ double doubleContentLength = (double)[_contentLength longValue];
88
+ double doublePercents = doubleBytesWritten / doubleContentLength * 100;
89
+ NSNumber* progress = [NSNumber numberWithUnsignedInt: floor(doublePercents)];
90
+ if ([progress unsignedIntValue] % 10 == 0) {
91
+ if (([progress unsignedIntValue] != [_lastProgressValue unsignedIntValue]) || ([_bytesWritten unsignedIntegerValue] == [_contentLength longValue])) {
92
+ _lastProgressValue = [NSNumber numberWithUnsignedInt:[progress unsignedIntValue]];
93
+ NSNumber *progressPercentage = @([_bytesWritten doubleValue] / [_contentLength doubleValue]);
94
+ return globalProgressCallback(progressPercentage);
95
+ }
96
+ }
97
+
98
+
99
+ }
100
+ }
101
+
102
+ - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location
103
+ {
104
+ NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)downloadTask.response;
105
+ if (!_statusCode) {
106
+ _statusCode = [NSNumber numberWithLong:httpResponse.statusCode];
107
+ }
108
+ NSURL *destURL = [NSURL fileURLWithPath:_toFile];
109
+ NSFileManager *fm = [NSFileManager defaultManager];
110
+ NSError *error = nil;
111
+ if([_statusCode integerValue] >= 200 && [_statusCode integerValue] < 300) {
112
+ [fm removeItemAtURL:destURL error:nil]; // Remove file at destination path, if it exists
113
+ [fm moveItemAtURL:location toURL:destURL error:&error];
114
+ // There are no guarantees about how often URLSession:downloadTask:didWriteData: will fire,
115
+ // so we read an authoritative number of bytes written here.
116
+ _bytesWritten = @([fm attributesOfItemAtPath:_toFile error:nil].fileSize);
117
+ }
118
+ if (error) {
119
+ NSLog(@"RNFS download: unable to move tempfile to destination. %@, %@", error, error.userInfo);
120
+ }
121
+
122
+ // When numerous downloads are called the sessions are not always invalidated and cleared by iOS14.
123
+ // This leads to error 28 – no space left on device so we manually flush and invalidate to free up space
124
+ if(session != nil){
125
+ [session flushWithCompletionHandler:^{
126
+ [session finishTasksAndInvalidate];
127
+ }];
128
+ }
129
+ NSURL *fileURL = [NSURL fileURLWithPath:_toFile];
130
+ return globalDownloadCompleteCallback([fileURL absoluteString]);
131
+ }
132
+
133
+ - (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
134
+ {
135
+ if (error) {
136
+ NSLog(@"RNFS download: didCompleteWithError %@, %@", error, error.userInfo);
137
+ if (error.code != NSURLErrorCancelled) {
138
+ _resumeData = error.userInfo[NSURLSessionDownloadTaskResumeData];
139
+ if (_resumeData != nil) {
140
+
141
+ } else {
142
+ globalErrorCallback(error);
143
+ }
144
+ }
145
+ }
146
+ }
147
+
148
+
149
+
150
+ @end
@@ -0,0 +1,11 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ @interface MediaCache : NSObject
4
+
5
+ + (instancetype)sharedCache;
6
+
7
+ + (void)addCompletedImagePath:(NSString *)imagePath;
8
+ + (void)removeCompletedImagePath:(NSString *)imagePath;
9
+ + (void)cleanupCache;
10
+
11
+ @end
@@ -0,0 +1,51 @@
1
+ #import "MediaCache.h"
2
+
3
+ @implementation MediaCache
4
+ NSMutableArray<NSString *> *completedImagePaths;
5
+
6
+ + (void)addCompletedImagePath:(NSString *)imagePath {
7
+ if (imagePath) {
8
+ [completedImagePaths addObject:imagePath];
9
+ }
10
+ }
11
+
12
+ + (void)removeCompletedImagePath:(NSString *)imagePath {
13
+ if (imagePath) {
14
+ [completedImagePaths removeObject:imagePath];
15
+ NSURL *fileURL = [NSURL URLWithString:imagePath];
16
+ NSString *fileSystemPath = [fileURL path];
17
+
18
+ NSFileManager *fileManager = [NSFileManager defaultManager];
19
+ NSError *error = nil;
20
+
21
+ if ([fileManager fileExistsAtPath:fileSystemPath isDirectory:nil]) {
22
+ [fileManager removeItemAtPath:fileSystemPath error:&error];
23
+ }
24
+
25
+ if (error) {
26
+ NSLog(@"Error deleting image at path: %@", fileSystemPath);
27
+ }
28
+ }
29
+ }
30
+
31
+ + (void)cleanupCache {
32
+ NSFileManager *fileManager = [NSFileManager defaultManager];
33
+ NSString *cacheDirectory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
34
+
35
+ for (NSString *imagePath in completedImagePaths) {
36
+ NSString *absoluteImagePath = [cacheDirectory stringByAppendingPathComponent:imagePath];
37
+ NSError *error = nil;
38
+
39
+ if ([fileManager fileExistsAtPath:absoluteImagePath]) {
40
+ [fileManager removeItemAtPath:absoluteImagePath error:&error];
41
+ }
42
+
43
+ if (error) {
44
+ NSLog(@"Error deleting image at path: %@", absoluteImagePath);
45
+ }
46
+ }
47
+
48
+ [completedImagePaths removeAllObjects];
49
+ }
50
+
51
+ @end
@@ -37,12 +37,17 @@ class VideoCompressor: RCTEventEmitter, URLSessionTaskDelegate {
37
37
  var uploadRejectors: [String: RCTPromiseRejectBlock] = [:]
38
38
  var compressorExports: [String: NextLevelSessionExporter] = [:]
39
39
  let videoCompressionThreshold:Int=7
40
-
40
+
41
+ override init() {
42
+ super.init()
43
+ ImageCompressor.initVideoCompressorInstance(self)
44
+ }
41
45
 
42
46
  override static func requiresMainQueueSetup() -> Bool {
43
47
  return false
44
48
  }
45
49
 
50
+
46
51
  @objc(activateBackgroundTask:withResolver:withRejecter:)
47
52
  func activateBackgroundTask(options: [String: Any], resolve:@escaping RCTPromiseResolveBlock, reject:@escaping RCTPromiseRejectBlock) -> Void {
48
53
  guard backgroundTaskId == .invalid else {
@@ -173,7 +178,7 @@ func makeValidUri(filePath: String) -> String {
173
178
  }
174
179
 
175
180
  override func supportedEvents() -> [String]! {
176
- return ["videoCompressProgress", "VideoCompressorProgress", "backgroundTaskExpired"]
181
+ return ["videoCompressProgress", "VideoCompressorProgress", "backgroundTaskExpired","downloadProgress"]
177
182
  }
178
183
 
179
184
  override func stopObserving() -> Void {
@@ -206,8 +211,10 @@ func makeValidUri(filePath: String) -> String {
206
211
 
207
212
 
208
213
  func compressVideo(url: URL, options: [String: Any], onProgress: @escaping (Float) -> Void, onCompletion: @escaping (URL) -> Void, onFailure: @escaping (Error) -> Void){
209
- ImageCompressor.getAbsoluteVideoPath(url.absoluteString) { absoluteVideoPath in
210
- var minimumFileSizeForCompress:Double=16.0;
214
+ let uuid:String = options["uuid"] as! String
215
+
216
+ ImageCompressor.getAbsoluteVideoPath(url.absoluteString, uuid: uuid) { absoluteVideoPath in
217
+ var minimumFileSizeForCompress:Double=0.0;
211
218
  let videoURL = URL(string: absoluteVideoPath!)
212
219
  let fileSize=self.getfileSize(forURL: videoURL!);
213
220
  if((options["minimumFileSizeForCompress"]) != nil)
@@ -216,11 +223,12 @@ func makeValidUri(filePath: String) -> String {
216
223
  }
217
224
  if(fileSize>minimumFileSizeForCompress)
218
225
  {
219
- if(options["compressionMethod"] as! String=="auto")
226
+ if(options["compressionMethod"] as! String=="manual")
220
227
  {
221
228
  self.autoCompressionHelper(url: videoURL!, options:options) { progress in
222
229
  onProgress(progress)
223
230
  } onCompletion: { outputURL in
231
+ MediaCache.removeCompletedImagePath(absoluteVideoPath);
224
232
  onCompletion(outputURL)
225
233
  } onFailure: { error in
226
234
  onFailure(error)
@@ -231,6 +239,7 @@ func makeValidUri(filePath: String) -> String {
231
239
  self.manualCompressionHelper(url: videoURL!, options:options) { progress in
232
240
  onProgress(progress)
233
241
  } onCompletion: { outputURL in
242
+ MediaCache.removeCompletedImagePath(absoluteVideoPath);
234
243
  onCompletion(outputURL)
235
244
  } onFailure: { error in
236
245
  onFailure(error)
@@ -4,51 +4,50 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
- var _reactNative = require("react-native");
9
-
7
+ var _Main = require("../Main");
10
8
  var _utils = require("../utils");
11
-
12
- const NativeAudio = _reactNative.NativeModules.Compressor;
9
+ const NativeAudio = _Main.Compressor;
13
10
  const Audio = {
14
- compress: async (url, options = _utils.DEFAULT_COMPRESS_AUDIO_OPTIONS) => {
11
+ compress: async function (url) {
12
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _utils.DEFAULT_COMPRESS_AUDIO_OPTIONS;
15
13
  try {
16
14
  const checkUrlAndOptionsResult = await (0, _utils.checkUrlAndOptions)(url, options);
17
-
18
15
  if (!checkUrlAndOptionsResult.isCorrect) {
19
16
  throw checkUrlAndOptionsResult.message;
20
17
  } else {
21
18
  // Get resulting output file path
19
+
22
20
  // Get media details
23
21
  // const mediaDetails: any = await getDetails(url).catch(() => null);
24
22
  const mediaDetails = {
25
23
  bitrate: 0
26
- }; // Initialize bitrate
24
+ };
27
25
 
26
+ // Initialize bitrate
28
27
  let bitrate = _utils.DEFAULT_COMPRESS_AUDIO_OPTIONS.bitrate;
29
-
30
28
  if (mediaDetails && mediaDetails.bitrate) {
31
29
  // Check and return the appropriate bitrate according to quality expected
32
30
  for (let i = 0; i < _utils.AUDIO_BITRATE.length; i++) {
33
31
  // Check a particular bitrate to return its nearest lower according to quality
32
+ //@ts-ignore
34
33
  if (mediaDetails.bitrate > _utils.AUDIO_BITRATE[i]) {
35
34
  if (i + 2 < _utils.AUDIO_BITRATE.length) {
36
35
  if (options.quality === 'low') bitrate = _utils.AUDIO_BITRATE[i + 2];else if (options.quality === 'medium') bitrate = _utils.AUDIO_BITRATE[i + 1];else bitrate = _utils.AUDIO_BITRATE[i];
37
36
  } else if (i + 1 < _utils.AUDIO_BITRATE.length) {
38
37
  if (options.quality === 'low') bitrate = _utils.AUDIO_BITRATE[i + 1];else bitrate = _utils.AUDIO_BITRATE[i];
39
38
  } else bitrate = _utils.AUDIO_BITRATE[i];
40
-
41
39
  break;
42
- } // Check if the matching bitrate is the last in the array
43
-
40
+ }
44
41
 
45
- if (mediaDetails.bitrate <= _utils.AUDIO_BITRATE[_utils.AUDIO_BITRATE.length - 1]) {
42
+ // Check if the matching bitrate is the last in the array
43
+ if (
44
+ //@ts-ignore
45
+ mediaDetails.bitrate <= _utils.AUDIO_BITRATE[_utils.AUDIO_BITRATE.length - 1]) {
46
46
  bitrate = _utils.AUDIO_BITRATE[_utils.AUDIO_BITRATE.length - 1];
47
47
  break;
48
48
  }
49
49
  }
50
50
  }
51
-
52
51
  return NativeAudio.compress_audio(url, {
53
52
  bitrate,
54
53
  quality: options.quality