react-native-compressor 1.0.3 → 1.2.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 (45) hide show
  1. package/README.md +84 -2
  2. package/android/.gradle/6.9/executionHistory/executionHistory.lock +0 -0
  3. package/android/.gradle/{6.1.1 → 6.9}/fileChanges/last-build.bin +0 -0
  4. package/android/.gradle/6.9/fileHashes/fileHashes.lock +0 -0
  5. package/android/.gradle/{6.1.1 → 6.9}/gc.properties +0 -0
  6. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  7. package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
  8. package/android/.gradle/checksums/checksums.lock +0 -0
  9. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  10. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  11. package/android/src/main/java/com/reactnativecompressor/Image/ImageCompressor.java +6 -14
  12. package/android/src/main/java/com/reactnativecompressor/Video/AutoVideoCompression/AutoVideoCompression.java +3 -2
  13. package/android/src/main/java/com/reactnativecompressor/Video/VideoCompressorHelper.java +4 -0
  14. package/app.plugin.js +1 -0
  15. package/ios/Video/VideoCompressor.swift +9 -9
  16. package/lib/commonjs/Video/index.js +7 -5
  17. package/lib/commonjs/Video/index.js.map +1 -1
  18. package/lib/commonjs/expo-plugin/compressor.js +17 -0
  19. package/lib/commonjs/expo-plugin/compressor.js.map +1 -0
  20. package/lib/commonjs/index.js +8 -1
  21. package/lib/commonjs/index.js.map +1 -1
  22. package/lib/commonjs/utils/index.js +13 -1
  23. package/lib/commonjs/utils/index.js.map +1 -1
  24. package/lib/module/Video/index.js +5 -2
  25. package/lib/module/Video/index.js.map +1 -1
  26. package/lib/module/expo-plugin/compressor.js +8 -0
  27. package/lib/module/expo-plugin/compressor.js.map +1 -0
  28. package/lib/module/index.js +4 -3
  29. package/lib/module/index.js.map +1 -1
  30. package/lib/module/utils/index.js +9 -0
  31. package/lib/module/utils/index.js.map +1 -1
  32. package/lib/typescript/Video/index.d.ts +2 -1
  33. package/lib/typescript/expo-plugin/compressor.d.ts +4 -0
  34. package/lib/typescript/index.d.ts +3 -2
  35. package/lib/typescript/utils/index.d.ts +1 -0
  36. package/package.json +4 -7
  37. package/src/Video/index.tsx +9 -2
  38. package/src/expo-plugin/compressor.ts +8 -0
  39. package/src/index.tsx +3 -1
  40. package/src/utils/index.tsx +17 -0
  41. package/android/.gradle/6.1.1/executionHistory/executionHistory.bin +0 -0
  42. package/android/.gradle/6.1.1/executionHistory/executionHistory.lock +0 -0
  43. package/android/.gradle/6.1.1/fileHashes/fileHashes.bin +0 -0
  44. package/android/.gradle/6.1.1/fileHashes/fileHashes.lock +0 -0
  45. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
package/README.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### Would you like to support me?
2
+
3
+ <a href="https://www.buymeacoffee.com/numan.dev" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>
4
+
5
+ ---
6
+
1
7
  # react-native-compressor
2
8
 
3
9
  <!-- Title -->
@@ -18,12 +24,16 @@
18
24
 
19
25
  **react-native-compressor** package is a set of functions that allow you compress `Image`,`Audio` and `Video`
20
26
 
27
+ If you find this package useful hit the star 🌟
28
+
21
29
  ## Installation
22
30
 
23
- #### For React Native 0.64 or lower
31
+ ### React Native
32
+
33
+ #### For React Native<0.65
24
34
 
25
35
  ```sh
26
- yarn add react-native-compressor@0.5.6
36
+ yarn add react-native-compressor@0.5.9
27
37
  ```
28
38
 
29
39
  #### For React Native 0.65 or greater
@@ -32,6 +42,33 @@ yarn add react-native-compressor@0.5.6
32
42
  yarn add react-native-compressor
33
43
  ```
34
44
 
45
+ ### Managed Expo
46
+
47
+ ```
48
+ expo install react-native-compressor
49
+ ```
50
+
51
+ Add the Compressor plugin to your Expo config (`app.json`, `app.config.json` or `app.config.js`):
52
+
53
+ ```json
54
+ {
55
+ "name": "my app",
56
+ "plugins": ["react-native-compressor"]
57
+ }
58
+ ```
59
+
60
+ Finally, compile the mods:
61
+
62
+ ```
63
+ expo prebuild
64
+ ```
65
+
66
+ To apply the changes, build a new binary with EAS:
67
+
68
+ ```
69
+ eas build
70
+ ```
71
+
35
72
  ### Automatic linking (for React Native >= 0.60 only)
36
73
 
37
74
  Automatic linking is supported for both `Android` and `IOS`
@@ -150,6 +187,23 @@ const result = await Audio.compress(
150
187
  );
151
188
  ```
152
189
 
190
+ ### Background Upload
191
+
192
+ ```js
193
+ import { backgroundUpload } from 'react-native-compressor';
194
+
195
+ const headers = {};
196
+
197
+ const uploadResult = await backgroundUpload(
198
+ url,
199
+ fileUrl,
200
+ { httpMethod: 'PUT', headers },
201
+ (written, total) => {
202
+ console.log(written, total);
203
+ }
204
+ );
205
+ ```
206
+
153
207
  # API
154
208
 
155
209
  ## Image
@@ -204,8 +258,12 @@ const result = await Audio.compress(
204
258
  The maximum size can be height in case of portrait video or can be width in case of landscape video.
205
259
 
206
260
  - ###### `bitrate: string`
261
+
207
262
  bitrate of video which reduce or increase video size. if compressionMethod will auto then this prop will not work
208
263
 
264
+ - ###### `minimumFileSizeForCompress: number` (default: 16)
265
+ 16 means 16mb. default our package do not compress under 16mb video file. minimumFileSizeForCompress will allow us to change this 16mb offset. fixed [#26](https://github.com/Shobbak/react-native-compressor/issues/26)
266
+
209
267
  ## Audio
210
268
 
211
269
  - ###### `compress(url: string, options?: audioCompresssionType): Promise<string>`
@@ -217,6 +275,30 @@ const result = await Audio.compress(
217
275
 
218
276
  **Note: Audio compression will be add soon**
219
277
 
278
+ ## Background Upload
279
+
280
+ - ###### `backgroundUpload: (url: string, fileUrl: string, options: FileSystemUploadOptions, onProgress?: ((writtem: number, total: number) => void) | undefined) => Promise<any>
281
+
282
+ - ###### ` FileSystemUploadOptions`
283
+
284
+ ```js
285
+ type FileSystemUploadOptions = (
286
+ | {
287
+ uploadType?: FileSystemUploadType.BINARY_CONTENT,
288
+ }
289
+ | {
290
+ uploadType: FileSystemUploadType.MULTIPART,
291
+ fieldName?: string,
292
+ mimeType?: string,
293
+ parameters?: Record<string, string>,
294
+ }
295
+ ) & {
296
+ headers?: Record<string, string>,
297
+ httpMethod?: FileSystemAcceptedUploadHttpMethod,
298
+ sessionType?: FileSystemSessionType,
299
+ };
300
+ ```
301
+
220
302
  ## Contributing
221
303
 
222
304
  See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
File without changes
@@ -1,2 +1,2 @@
1
- #Fri May 28 18:36:00 PKT 2021
2
- gradle.version=6.1.1
1
+ #Mon Dec 20 15:53:04 PKT 2021
2
+ gradle.version=6.9
@@ -66,7 +66,7 @@ public class ImageCompressor {
66
66
 
67
67
 
68
68
 
69
- public static String encodeImage(ByteArrayOutputStream imageDataByteArrayOutputStream, Boolean isBase64, Bitmap bitmapImage,String outputExtension, ReactApplicationContext reactContext) {
69
+ public static String encodeImage(ByteArrayOutputStream imageDataByteArrayOutputStream, Boolean isBase64,String outputExtension, ReactApplicationContext reactContext) {
70
70
  if(isBase64)
71
71
  {
72
72
  byte[] imageData=imageDataByteArrayOutputStream.toByteArray();
@@ -124,16 +124,16 @@ public class ImageCompressor {
124
124
  final ByteArrayOutputStream imageDataByteArrayOutputStream = ImageCompressor.compress(resizedImage, options.output, options.quality);
125
125
  Boolean isBase64=options.returnableOutputType==ImageCompressorOptions.ReturnableOutputType.base64;
126
126
 
127
- String returnableResult = ImageCompressor.encodeImage(imageDataByteArrayOutputStream,isBase64,image,options.output.toString(),reactContext);
127
+ String returnableResult = ImageCompressor.encodeImage(imageDataByteArrayOutputStream,isBase64,options.output.toString(),reactContext);
128
128
  return returnableResult;
129
129
  }
130
130
 
131
131
 
132
132
  public static String autoCompressImage(String imagePath,ImageCompressorOptions compressorOptions, ReactApplicationContext reactContext) {
133
133
  String outputExtension=compressorOptions.output.toString();
134
- int quality= (int) (compressorOptions.quality*100);
135
134
  float autoCompressMaxHeight = compressorOptions.maxHeight;
136
135
  float autoCompressMaxWidth = compressorOptions.maxWidth;
136
+ Boolean isBase64=compressorOptions.returnableOutputType==ImageCompressorOptions.ReturnableOutputType.base64;
137
137
 
138
138
  Uri uri= Uri.parse(imagePath);
139
139
  imagePath = uri.getPath();
@@ -217,18 +217,10 @@ public class ImageCompressor {
217
217
  } catch (IOException e) {
218
218
  e.printStackTrace();
219
219
  }
220
- FileOutputStream out = null;
221
- String filepath = generateCacheFilePath(outputExtension,reactContext);;
222
- try {
223
- out = new FileOutputStream(filepath);
224
-
225
- //write the compressed bitmap at the destination specified by filename.
226
- scaledBitmap.compress(Bitmap.CompressFormat.JPEG, quality, out);
227
220
 
228
- } catch (FileNotFoundException e) {
229
- e.printStackTrace();
230
- }
231
- return getRNFileUrl(filepath);
221
+ final ByteArrayOutputStream imageDataByteArrayOutputStream = ImageCompressor.compress(scaledBitmap, compressorOptions.output, compressorOptions.quality);
222
+ String returnableResult = ImageCompressor.encodeImage(imageDataByteArrayOutputStream,isBase64,compressorOptions.output.toString(),reactContext);
223
+ return returnableResult;
232
224
  }
233
225
 
234
226
  public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
@@ -26,7 +26,8 @@ public class AutoVideoCompression {
26
26
  static int currentVideoCompression=0;
27
27
 
28
28
  public static void createCompressionSettings(String fileUrl,VideoCompressorHelper options,Promise promise, ReactApplicationContext reactContext) {
29
- float maxSize = options.maxSize;;
29
+ float maxSize = options.maxSize;
30
+ float minimumFileSizeForCompress=options.minimumFileSizeForCompress;
30
31
  try{
31
32
  Uri uri= Uri.parse(fileUrl);
32
33
  String srcPath = uri.getPath();
@@ -35,7 +36,7 @@ public class AutoVideoCompression {
35
36
  File file=new File(srcPath);
36
37
  float sizeInBytes = file.length();
37
38
  float sizeInMb = sizeInBytes / (1024 * 1024);
38
- if(sizeInMb>16)
39
+ if(sizeInMb>minimumFileSizeForCompress)
39
40
  {
40
41
  String destinationPath = generateCacheFilePath("mp4", reactContext);
41
42
  int actualHeight =Integer.parseInt(metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT));
@@ -102,6 +102,7 @@ public class VideoCompressorHelper {
102
102
  public float bitrate = 0;
103
103
  public String uuid = "";
104
104
  public float maxSize = 640.0f;
105
+ public float minimumFileSizeForCompress = 16.0f;
105
106
 
106
107
  public static VideoCompressorHelper fromMap(ReadableMap map) {
107
108
  final VideoCompressorHelper options = new VideoCompressorHelper();
@@ -120,6 +121,9 @@ public class VideoCompressorHelper {
120
121
  case "uuid":
121
122
  options.uuid = map.getString(key);
122
123
  break;
124
+ case "minimumFileSizeForCompress":
125
+ options.minimumFileSizeForCompress =(float) map.getDouble(key);
126
+ break;
123
127
 
124
128
  }
125
129
  }
package/app.plugin.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./lib/commonjs/expo-plugin/compressor');
@@ -199,10 +199,13 @@ func makeValidUri(filePath: String) -> String {
199
199
 
200
200
 
201
201
  func compressVideo(url: URL, options: [String: Any], onProgress: @escaping (Float) -> Void, onCompletion: @escaping (URL) -> Void, onFailure: @escaping (Error) -> Void){
202
-
202
+ var minimumFileSizeForCompress:Double=16.0;
203
203
  let fileSize=self.getfileSize(forURL: url);
204
-
205
- if(fileSize>16)
204
+ if((options["minimumFileSizeForCompress"]) != nil)
205
+ {
206
+ minimumFileSizeForCompress=options["minimumFileSizeForCompress"] as! Double;
207
+ }
208
+ if(fileSize>minimumFileSizeForCompress)
206
209
  {
207
210
  if(options["compressionMethod"] as! String=="auto")
208
211
  {
@@ -242,9 +245,9 @@ func makeValidUri(filePath: String) -> String {
242
245
  let compressFactor:Float = 0.8
243
246
  let minCompressFactor:Float = 0.8
244
247
  let maxBitrate:Int = 1669000
245
-
246
- var remeasuredBitrate:Int = originalBitrate / (min(originalHeight/height,originalWidth/width))
247
- remeasuredBitrate = remeasuredBitrate*Int(compressFactor)
248
+ let minValue:Float=min(Float(originalHeight)/Float(height),Float(originalWidth)/Float(width))
249
+ var remeasuredBitrate:Int = Int(Float(originalBitrate) / minValue)
250
+ remeasuredBitrate = Int(Float(remeasuredBitrate)*compressFactor)
248
251
  let minBitrate:Int = self.getVideoBitrateWithFactor(f: minCompressFactor) / (1280 * 720 / (width * height))
249
252
  if (originalBitrate < minBitrate) {
250
253
  return remeasuredBitrate;
@@ -379,14 +382,11 @@ func makeValidUri(filePath: String) -> String {
379
382
  onCompletion(exporter.outputURL!)
380
383
  break
381
384
  default:
382
- // let error = CompressionError(message: "Compression didn't complete")
383
- // onFailure(error)
384
385
  onCompletion(url)
385
386
  break
386
387
  }
387
388
  break
388
389
  case .failure(let error):
389
- // onFailure(error)
390
390
  onCompletion(url)
391
391
  break
392
392
  }
@@ -7,15 +7,13 @@ exports.default = exports.backgroundUpload = void 0;
7
7
 
8
8
  var _reactNative = require("react-native");
9
9
 
10
- require("react-native-get-random-values");
11
-
12
- var _uuid = require("uuid");
10
+ var _utils = require("../utils");
13
11
 
14
12
  const VideoCompressEventEmitter = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.VideoCompressor);
15
13
  const NativeVideoCompressor = _reactNative.NativeModules.VideoCompressor;
16
14
 
17
15
  const backgroundUpload = async (url, fileUrl, options, onProgress) => {
18
- const uuid = (0, _uuid.v4)();
16
+ const uuid = (0, _utils.uuidv4)();
19
17
  let subscription;
20
18
 
21
19
  try {
@@ -49,7 +47,7 @@ const backgroundUpload = async (url, fileUrl, options, onProgress) => {
49
47
  exports.backgroundUpload = backgroundUpload;
50
48
  const Video = {
51
49
  compress: async (fileUrl, options, onProgress) => {
52
- const uuid = (0, _uuid.v4)();
50
+ const uuid = (0, _utils.uuidv4)();
53
51
  let subscription;
54
52
 
55
53
  try {
@@ -78,6 +76,10 @@ const Video = {
78
76
  modifiedOptions.maxSize = 640;
79
77
  }
80
78
 
79
+ if (options !== null && options !== void 0 && options.minimumFileSizeForCompress) {
80
+ modifiedOptions.minimumFileSizeForCompress = options === null || options === void 0 ? void 0 : options.minimumFileSizeForCompress;
81
+ }
82
+
81
83
  const result = await NativeVideoCompressor.compress(fileUrl, modifiedOptions);
82
84
  return result;
83
85
  } finally {
@@ -1 +1 @@
1
- {"version":3,"sources":["index.tsx"],"names":["VideoCompressEventEmitter","NativeEventEmitter","NativeModules","VideoCompressor","NativeVideoCompressor","backgroundUpload","url","fileUrl","options","onProgress","uuid","subscription","addListener","event","data","written","total","Platform","OS","includes","replace","result","upload","method","httpMethod","headers","remove","Video","compress","progress","modifiedOptions","bitrate","compressionMethod","maxSize","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners"],"mappings":";;;;;;;AAAA;;AAMA;;AACA;;AA4DA,MAAMA,yBAAyB,GAAG,IAAIC,+BAAJ,CAChCC,2BAAcC,eADkB,CAAlC;AAIA,MAAMC,qBAAqB,GAAGF,2BAAcC,eAA5C;;AAEO,MAAME,gBAAgB,GAAG,OAC9BC,GAD8B,EAE9BC,OAF8B,EAG9BC,OAH8B,EAI9BC,UAJ8B,KAKb;AACjB,QAAMC,IAAI,GAAG,eAAb;AACA,MAAIC,YAAJ;;AACA,MAAI;AACF,QAAIF,UAAJ,EAAgB;AACdE,MAAAA,YAAY,GAAGX,yBAAyB,CAACY,WAA1B,CACb,yBADa,EAEZC,KAAD,IAAgB;AACd,YAAIA,KAAK,CAACH,IAAN,KAAeA,IAAnB,EAAyB;AACvBD,UAAAA,UAAU,CAACI,KAAK,CAACC,IAAN,CAAWC,OAAZ,EAAqBF,KAAK,CAACC,IAAN,CAAWE,KAAhC,CAAV;AACD;AACF,OANY,CAAf;AAQD;;AACD,QAAIC,sBAASC,EAAT,KAAgB,SAAhB,IAA6BX,OAAO,CAACY,QAAR,CAAiB,SAAjB,CAAjC,EAA8D;AAC5DZ,MAAAA,OAAO,GAAGA,OAAO,CAACa,OAAR,CAAgB,SAAhB,EAA2B,EAA3B,CAAV;AACD;;AACD,UAAMC,MAAM,GAAG,MAAMjB,qBAAqB,CAACkB,MAAtB,CAA6Bf,OAA7B,EAAsC;AACzDG,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OAAhB,GAA0BzB,OAA1B,aAA0BA,OAA1B,uBAA0BA,OAAO,CAAEyB,OAAnC;AACD,OAFD,MAEO;AACLH,QAAAA,eAAe,CAACG,OAAhB,GAA0B,GAA1B;AACD;;AACD,YAAMZ,MAAM,GAAG,MAAMjB,qBAAqB,CAACwB,QAAtB,CACnBrB,OADmB,EAEnBuB,eAFmB,CAArB;AAIA,aAAOT,MAAP;AACD,KAjCD,SAiCU;AACR;AACA,UAAIV,YAAJ,EAAkB;AAChBA,QAAAA,YAAY,CAACe,MAAb;AACD;AACF;AACF,GAnDgC;AAoDjCrB,EAAAA,gBApDiC;;AAqDjC6B,EAAAA,sBAAsB,CAACC,SAAD,EAAa;AACjC,QAAIA,SAAJ,EAAe;AACb,YAAMxB,YAAqC,GACzCX,yBAAyB,CAACY,WAA1B,CACE,uBADF,EAEGC,KAAD,IAAgB;AACdsB,QAAAA,SAAS,CAACtB,KAAD,CAAT;;AACA,YAAIF,YAAJ,EAAkB;AAChBA,UAAAA,YAAY,CAACe,MAAb;AACD;AACF,OAPH,CADF;AAUD;;AACD,WAAOtB,qBAAqB,CAAC8B,sBAAtB,CAA6C,EAA7C,CAAP;AACD,GAnEgC;;AAoEjCE,EAAAA,wBAAwB,GAAG;AACzBpC,IAAAA,yBAAyB,CAACqC,kBAA1B,CAA6C,uBAA7C;AACA,WAAOjC,qBAAqB,CAACgC,wBAAtB,CAA+C,EAA/C,CAAP;AACD;;AAvEgC,CAAnC;eA0EeT,K","sourcesContent":["import {\n NativeModules,\n NativeEventEmitter,\n Platform,\n NativeEventSubscription,\n} from 'react-native';\nimport 'react-native-get-random-values';\nimport { v4 as uuidv4 } from 'uuid';\n\nexport declare enum FileSystemUploadType {\n BINARY_CONTENT = 0,\n MULTIPART = 1,\n}\n\nexport declare type FileSystemAcceptedUploadHttpMethod =\n | 'POST'\n | 'PUT'\n | 'PATCH';\nexport type compressionMethod = 'auto' | 'manual';\ntype videoCompresssionType = {\n bitrate?: number;\n compressionMethod?: compressionMethod;\n};\n\nexport declare enum FileSystemSessionType {\n BACKGROUND = 0,\n FOREGROUND = 1,\n}\n\nexport declare type HTTPResponse = {\n status: number;\n headers: Record<string, string>;\n body: string;\n};\n\nexport declare type FileSystemUploadOptions = (\n | {\n uploadType?: FileSystemUploadType.BINARY_CONTENT;\n }\n | {\n uploadType: FileSystemUploadType.MULTIPART;\n fieldName?: string;\n mimeType?: string;\n parameters?: Record<string, string>;\n }\n) & {\n headers?: Record<string, string>;\n httpMethod?: FileSystemAcceptedUploadHttpMethod;\n sessionType?: FileSystemSessionType;\n};\n\nexport type VideoCompressorType = {\n compress(\n fileUrl: string,\n options?: videoCompresssionType,\n onProgress?: (progress: number) => void\n ): Promise<string>;\n backgroundUpload(\n url: string,\n fileUrl: string,\n options: FileSystemUploadOptions,\n onProgress?: (writtem: number, total: number) => void\n ): Promise<any>;\n activateBackgroundTask(onExpired?: (data: any) => void): Promise<any>;\n deactivateBackgroundTask(): Promise<any>;\n};\n\nconst VideoCompressEventEmitter = new NativeEventEmitter(\n NativeModules.VideoCompressor\n);\n\nconst NativeVideoCompressor = NativeModules.VideoCompressor;\n\nexport const backgroundUpload = async (\n url: string,\n fileUrl: string,\n options: FileSystemUploadOptions,\n onProgress?: (writtem: number, total: number) => void\n): Promise<any> => {\n const uuid = uuidv4();\n let subscription: NativeEventSubscription;\n try {\n if (onProgress) {\n subscription = VideoCompressEventEmitter.addListener(\n 'VideoCompressorProgress',\n (event: any) => {\n if (event.uuid === uuid) {\n onProgress(event.data.written, event.data.total);\n }\n }\n );\n }\n if (Platform.OS === 'android' && fileUrl.includes('file://')) {\n fileUrl = fileUrl.replace('file://', '');\n }\n const result = await NativeVideoCompressor.upload(fileUrl, {\n uuid,\n method: options.httpMethod,\n headers: options.headers,\n url,\n });\n return result;\n } finally {\n // @ts-ignore\n if (subscription) {\n subscription.remove();\n }\n }\n};\n\nconst Video: VideoCompressorType = {\n compress: async (\n fileUrl: string,\n options?: {\n bitrate?: number;\n compressionMethod?: compressionMethod;\n maxSize?: number;\n },\n onProgress?: (progress: number) => void\n ) => {\n const uuid = uuidv4();\n let subscription: NativeEventSubscription;\n try {\n if (onProgress) {\n subscription = VideoCompressEventEmitter.addListener(\n 'videoCompressProgress',\n (event: any) => {\n if (event.uuid === uuid) {\n onProgress(event.data.progress);\n }\n }\n );\n }\n const modifiedOptions: {\n uuid: string;\n bitrate?: number;\n compressionMethod?: compressionMethod;\n maxSize?: number;\n } = { uuid };\n if (options?.bitrate) modifiedOptions.bitrate = options?.bitrate;\n if (options?.compressionMethod) {\n modifiedOptions.compressionMethod = options?.compressionMethod;\n } else {\n modifiedOptions.compressionMethod = 'manual';\n }\n if (options?.maxSize) {\n modifiedOptions.maxSize = options?.maxSize;\n } else {\n modifiedOptions.maxSize = 640;\n }\n const result = await NativeVideoCompressor.compress(\n fileUrl,\n modifiedOptions\n );\n return result;\n } finally {\n // @ts-ignore\n if (subscription) {\n subscription.remove();\n }\n }\n },\n backgroundUpload,\n activateBackgroundTask(onExpired?) {\n if (onExpired) {\n const subscription: NativeEventSubscription =\n VideoCompressEventEmitter.addListener(\n 'backgroundTaskExpired',\n (event: any) => {\n onExpired(event);\n if (subscription) {\n subscription.remove();\n }\n }\n );\n }\n return NativeVideoCompressor.activateBackgroundTask({});\n },\n deactivateBackgroundTask() {\n VideoCompressEventEmitter.removeAllListeners('backgroundTaskExpired');\n return NativeVideoCompressor.deactivateBackgroundTask({});\n },\n} as VideoCompressorType;\n\nexport default Video;\n"]}
1
+ {"version":3,"sources":["index.tsx"],"names":["VideoCompressEventEmitter","NativeEventEmitter","NativeModules","VideoCompressor","NativeVideoCompressor","backgroundUpload","url","fileUrl","options","onProgress","uuid","subscription","addListener","event","data","written","total","Platform","OS","includes","replace","result","upload","method","httpMethod","headers","remove","Video","compress","progress","modifiedOptions","bitrate","compressionMethod","maxSize","minimumFileSizeForCompress","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners"],"mappings":";;;;;;;AAAA;;AAMA;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CAArB;AAIA,aAAOT,MAAP;AACD,KAtCD,SAsCU;AACR;AACA,UAAIV,YAAJ,EAAkB;AAChBA,QAAAA,YAAY,CAACe,MAAb;AACD;AACF;AACF,GAzDgC;AA0DjCrB,EAAAA,gBA1DiC;;AA2DjC8B,EAAAA,sBAAsB,CAACC,SAAD,EAAa;AACjC,QAAIA,SAAJ,EAAe;AACb,YAAMzB,YAAqC,GACzCX,yBAAyB,CAACY,WAA1B,CACE,uBADF,EAEGC,KAAD,IAAgB;AACduB,QAAAA,SAAS,CAACvB,KAAD,CAAT;;AACA,YAAIF,YAAJ,EAAkB;AAChBA,UAAAA,YAAY,CAACe,MAAb;AACD;AACF,OAPH,CADF;AAUD;;AACD,WAAOtB,qBAAqB,CAAC+B,sBAAtB,CAA6C,EAA7C,CAAP;AACD,GAzEgC;;AA0EjCE,EAAAA,wBAAwB,GAAG;AACzBrC,IAAAA,yBAAyB,CAACsC,kBAA1B,CAA6C,uBAA7C;AACA,WAAOlC,qBAAqB,CAACiC,wBAAtB,CAA+C,EAA/C,CAAP;AACD;;AA7EgC,CAAnC;eAgFeV,K","sourcesContent":["import {\n NativeModules,\n NativeEventEmitter,\n Platform,\n NativeEventSubscription,\n} from 'react-native';\nimport { uuidv4 } from '../utils';\n\nexport declare enum FileSystemUploadType {\n BINARY_CONTENT = 0,\n MULTIPART = 1,\n}\n\nexport declare type FileSystemAcceptedUploadHttpMethod =\n | 'POST'\n | 'PUT'\n | 'PATCH';\nexport type compressionMethod = 'auto' | 'manual';\ntype videoCompresssionType = {\n bitrate?: number;\n maxSize?: number;\n compressionMethod?: compressionMethod;\n minimumFileSizeForCompress?: number;\n};\n\nexport declare enum FileSystemSessionType {\n BACKGROUND = 0,\n FOREGROUND = 1,\n}\n\nexport declare type HTTPResponse = {\n status: number;\n headers: Record<string, string>;\n body: string;\n};\n\nexport declare type FileSystemUploadOptions = (\n | {\n uploadType?: FileSystemUploadType.BINARY_CONTENT;\n }\n | {\n uploadType: FileSystemUploadType.MULTIPART;\n fieldName?: string;\n mimeType?: string;\n parameters?: Record<string, string>;\n }\n) & {\n headers?: Record<string, string>;\n httpMethod?: FileSystemAcceptedUploadHttpMethod;\n sessionType?: FileSystemSessionType;\n};\n\nexport type VideoCompressorType = {\n compress(\n fileUrl: string,\n options?: videoCompresssionType,\n onProgress?: (progress: number) => void\n ): Promise<string>;\n backgroundUpload(\n url: string,\n fileUrl: string,\n options: FileSystemUploadOptions,\n onProgress?: (writtem: number, total: number) => void\n ): Promise<any>;\n activateBackgroundTask(onExpired?: (data: any) => void): Promise<any>;\n deactivateBackgroundTask(): Promise<any>;\n};\n\nconst VideoCompressEventEmitter = new NativeEventEmitter(\n NativeModules.VideoCompressor\n);\n\nconst NativeVideoCompressor = NativeModules.VideoCompressor;\n\nexport const backgroundUpload = async (\n url: string,\n fileUrl: string,\n options: FileSystemUploadOptions,\n onProgress?: (writtem: number, total: number) => void\n): Promise<any> => {\n const uuid = uuidv4();\n let subscription: NativeEventSubscription;\n try {\n if (onProgress) {\n subscription = VideoCompressEventEmitter.addListener(\n 'VideoCompressorProgress',\n (event: any) => {\n if (event.uuid === uuid) {\n onProgress(event.data.written, event.data.total);\n }\n }\n );\n }\n if (Platform.OS === 'android' && fileUrl.includes('file://')) {\n fileUrl = fileUrl.replace('file://', '');\n }\n const result = await NativeVideoCompressor.upload(fileUrl, {\n uuid,\n method: options.httpMethod,\n headers: options.headers,\n url,\n });\n return result;\n } finally {\n // @ts-ignore\n if (subscription) {\n subscription.remove();\n }\n }\n};\n\nconst Video: VideoCompressorType = {\n compress: async (\n fileUrl: string,\n options?: {\n bitrate?: number;\n compressionMethod?: compressionMethod;\n maxSize?: number;\n minimumFileSizeForCompress?: number;\n },\n onProgress?: (progress: number) => void\n ) => {\n const uuid = uuidv4();\n let subscription: NativeEventSubscription;\n try {\n if (onProgress) {\n subscription = VideoCompressEventEmitter.addListener(\n 'videoCompressProgress',\n (event: any) => {\n if (event.uuid === uuid) {\n onProgress(event.data.progress);\n }\n }\n );\n }\n const modifiedOptions: {\n uuid: string;\n bitrate?: number;\n compressionMethod?: compressionMethod;\n maxSize?: number;\n minimumFileSizeForCompress?: number;\n } = { uuid };\n if (options?.bitrate) modifiedOptions.bitrate = options?.bitrate;\n if (options?.compressionMethod) {\n modifiedOptions.compressionMethod = options?.compressionMethod;\n } else {\n modifiedOptions.compressionMethod = 'manual';\n }\n if (options?.maxSize) {\n modifiedOptions.maxSize = options?.maxSize;\n } else {\n modifiedOptions.maxSize = 640;\n }\n if (options?.minimumFileSizeForCompress) {\n modifiedOptions.minimumFileSizeForCompress =\n options?.minimumFileSizeForCompress;\n }\n const result = await NativeVideoCompressor.compress(\n fileUrl,\n modifiedOptions\n );\n return result;\n } finally {\n // @ts-ignore\n if (subscription) {\n subscription.remove();\n }\n }\n },\n backgroundUpload,\n activateBackgroundTask(onExpired?) {\n if (onExpired) {\n const subscription: NativeEventSubscription =\n VideoCompressEventEmitter.addListener(\n 'backgroundTaskExpired',\n (event: any) => {\n onExpired(event);\n if (subscription) {\n subscription.remove();\n }\n }\n );\n }\n return NativeVideoCompressor.activateBackgroundTask({});\n },\n deactivateBackgroundTask() {\n VideoCompressEventEmitter.removeAllListeners('backgroundTaskExpired');\n return NativeVideoCompressor.deactivateBackgroundTask({});\n },\n} as VideoCompressorType;\n\nexport default Video;\n"]}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _configPlugins = require("@expo/config-plugins");
9
+
10
+ const pkg = require('../../../package.json');
11
+
12
+ const withCompressor = config => config;
13
+
14
+ var _default = (0, _configPlugins.createRunOncePlugin)(withCompressor, pkg.name, pkg.version);
15
+
16
+ exports.default = _default;
17
+ //# sourceMappingURL=compressor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["compressor.ts"],"names":["pkg","require","withCompressor","config","name","version"],"mappings":";;;;;;;AAAA;;AACA,MAAMA,GAAG,GAAGC,OAAO,CAAC,uBAAD,CAAnB;;AAIA,MAAMC,cAAmC,GAAIC,MAAD,IAAYA,MAAxD;;eAEe,wCAAoBD,cAApB,EAAoCF,GAAG,CAACI,IAAxC,EAA8CJ,GAAG,CAACK,OAAlD,C","sourcesContent":["import { ConfigPlugin, createRunOncePlugin } from '@expo/config-plugins';\nconst pkg = require('../../../package.json');\n\ntype Props = {};\n\nconst withCompressor: ConfigPlugin<Props> = (config) => config;\n\nexport default createRunOncePlugin(withCompressor, pkg.name, pkg.version);\n"]}
@@ -39,6 +39,12 @@ Object.defineProperty(exports, "getDetails", {
39
39
  return _utils.getDetails;
40
40
  }
41
41
  });
42
+ Object.defineProperty(exports, "uuidv4", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _utils.uuidv4;
46
+ }
47
+ });
42
48
  exports.default = void 0;
43
49
 
44
50
  var _Video = _interopRequireWildcard(require("./Video"));
@@ -60,7 +66,8 @@ var _default = {
60
66
  Audio: _Audio.default,
61
67
  Image: _Image.default,
62
68
  backgroundUpload: _Video.backgroundUpload,
63
- getDetails: _utils.getDetails
69
+ getDetails: _utils.getDetails,
70
+ uuidv4: _utils.uuidv4
64
71
  };
65
72
  exports.default = _default;
66
73
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["index.tsx"],"names":["Video","Audio","Image","backgroundUpload","getDetails"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;;;eAWe;AACbA,EAAAA,KAAK,EAALA,cADa;AAEbC,EAAAA,KAAK,EAALA,cAFa;AAGbC,EAAAA,KAAK,EAALA,cAHa;AAIbC,EAAAA,gBAAgB,EAAhBA,uBAJa;AAKbC,EAAAA,UAAU,EAAVA;AALa,C","sourcesContent":["import Video, { VideoCompressorType, backgroundUpload } from './Video';\nimport Audio from './Audio';\nimport Image from './Image';\nimport { getDetails } from './utils';\n\nexport {\n Video,\n Audio,\n Image,\n backgroundUpload,\n //type\n VideoCompressorType,\n getDetails,\n};\nexport default {\n Video,\n Audio,\n Image,\n backgroundUpload,\n getDetails,\n};\n"]}
1
+ {"version":3,"sources":["index.tsx"],"names":["Video","Audio","Image","backgroundUpload","getDetails","uuidv4"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;;;eAYe;AACbA,EAAAA,KAAK,EAALA,cADa;AAEbC,EAAAA,KAAK,EAALA,cAFa;AAGbC,EAAAA,KAAK,EAALA,cAHa;AAIbC,EAAAA,gBAAgB,EAAhBA,uBAJa;AAKbC,EAAAA,UAAU,EAAVA,iBALa;AAMbC,EAAAA,MAAM,EAANA;AANa,C","sourcesContent":["import Video, { VideoCompressorType, backgroundUpload } from './Video';\nimport Audio from './Audio';\nimport Image from './Image';\nimport { getDetails, uuidv4 } from './utils';\n\nexport {\n Video,\n Audio,\n Image,\n backgroundUpload,\n //type\n VideoCompressorType,\n getDetails,\n uuidv4,\n};\nexport default {\n Video,\n Audio,\n Image,\n backgroundUpload,\n getDetails,\n uuidv4,\n};\n"]}
@@ -3,10 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.checkUrlAndOptions = exports.getDetails = exports.DEFAULT_COMPRESS_AUDIO_OPTIONS = exports.AUDIO_BITRATE = void 0;
6
+ exports.uuidv4 = exports.checkUrlAndOptions = exports.getDetails = exports.DEFAULT_COMPRESS_AUDIO_OPTIONS = exports.AUDIO_BITRATE = void 0;
7
7
 
8
8
  var _reactNative = require("react-native");
9
9
 
10
+ /* eslint-disable no-bitwise */
10
11
  const {
11
12
  Compressor
12
13
  } = _reactNative.NativeModules;
@@ -136,4 +137,15 @@ const checkUrlAndOptions = async (url, options) => {
136
137
  };
137
138
 
138
139
  exports.checkUrlAndOptions = checkUrlAndOptions;
140
+
141
+ const uuidv4 = () => {
142
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
143
+ const r = parseFloat('0.' + Math.random().toString().replace('0.', '') + new Date().getTime()) * 16 | 0,
144
+ // eslint-disable-next-line eqeqeq
145
+ v = c == 'x' ? r : r & 0x3 | 0x8;
146
+ return v.toString(16);
147
+ });
148
+ };
149
+
150
+ exports.uuidv4 = uuidv4;
139
151
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["index.tsx"],"names":["Compressor","NativeModules","AUDIO_BITRATE","INCORRECT_INPUT_PATH","INCORRECT_OUTPUT_PATH","ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE","DEFAULT_COMPRESS_AUDIO_OPTIONS","bitrate","quality","outputFilePath","generateFile","extension","Promise","resolve","reject","then","result","catch","error","isValidUrl","url","test","getFullFilename","path","_path","includes","length","substring","array","split","isFileNameError","filename","getFilename","fullFilename","slice","join","isRemoteMedia","getDetails","mediaFullPath","extesnion","Error","mediaInfo","JSON","parse","mediaInformation","getMediaProperties","bit_rate","size","Number","format","e","checkUrlAndOptions","options","defaultResult","isCorrect","message","undefined"],"mappings":";;;;;;;AAAA;;AACA,MAAM;AAAEA,EAAAA;AAAF,IAAiBC,0BAAvB;AACO,MAAMC,aAAa,GAAG,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,EAAgB,GAAhB,EAAqB,EAArB,EAAyB,EAAzB,EAA6B,EAA7B,CAAtB;;AAEP,MAAMC,oBAAoB,GAAG,kDAA7B;AACA,MAAMC,qBAAqB,GACzB,mDADF;AAEA,MAAMC,wCAAwC,GAC5C,6CADF;AAcO,MAAMC,8BAAqD,GAAG;AACnEC,EAAAA,OAAO,EAAE,EAD0D;AAEnEC,EAAAA,OAAO,EAAE,QAF0D;AAGnEC,EAAAA,cAAc,EAAE;AAHmD,CAA9D;;;AAUP,MAAMC,YAAiB,GAAIC,SAAD,IAAuB;AAC/C,SAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EA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,GArBD,SAqBU;AACR,WAAOgD,aAAP;AACD;AACF,CAzCM","sourcesContent":["import { NativeModules } from 'react-native';\nconst { Compressor } = NativeModules;\nexport const AUDIO_BITRATE = [256, 192, 160, 128, 96, 64, 32];\ntype qualityType = 'low' | 'medium' | 'high';\nconst INCORRECT_INPUT_PATH = 'Incorrect input path. Please provide a valid one';\nconst INCORRECT_OUTPUT_PATH =\n 'Incorrect output path. Please provide a valid one';\nconst ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE =\n 'An error occur while generating output file';\ntype audioCompresssionType = {\n bitrate?: number;\n quality: qualityType;\n outputFilePath?: string | undefined | null;\n};\n\nexport type defaultResultType = {\n outputFilePath: string | undefined | null;\n isCorrect: boolean;\n message: string;\n};\n\nexport const DEFAULT_COMPRESS_AUDIO_OPTIONS: audioCompresssionType = {\n bitrate: 96,\n quality: 'medium',\n outputFilePath: '',\n};\n\nexport type AudioType = {\n compress(value: string, options?: audioCompresssionType): Promise<string>;\n};\n\nconst generateFile: any = (extension: string) => {\n return new Promise((resolve, reject) => {\n Compressor.generateFile(extension)\n .then((result: any) => resolve('file://' + result))\n .catch((error: any) => reject(error));\n });\n};\n\nconst isValidUrl = (url: string) =>\n /^(?:\\w+:)?\\/\\/([^\\s\\.]+\\.\\S{2}|localhost[\\:?\\d]*)\\S*$/.test(url);\n\nconst getFullFilename = (path: string | null) => {\n if (typeof path === 'string') {\n let _path = path;\n\n // In case of remote media, check if the url would be valid one\n if (path.includes('http') && !isValidUrl(path)) {\n return INCORRECT_INPUT_PATH;\n }\n\n // In case of url, check if it ends with \"/\" and do not consider it furthermore\n if (_path[_path.length - 1] === '/')\n _path = _path.substring(0, path.length - 1);\n\n const array = _path.split('/');\n return array.length > 1 ? array[array.length - 1] : INCORRECT_INPUT_PATH;\n }\n return INCORRECT_INPUT_PATH;\n};\n\nconst isFileNameError = (filename: string) => {\n return filename === INCORRECT_INPUT_PATH;\n};\n\nconst getFilename = (path: string | null) => {\n const fullFilename = getFullFilename(path);\n if (!isFileNameError(fullFilename)) {\n const array = fullFilename.split('.');\n return array.length > 1 ? array.slice(0, -1).join('') : array.join('');\n }\n return fullFilename;\n};\n\nconst isRemoteMedia = (path: string | null) => {\n return typeof path === 'string' ? path.split(':/')[0].includes('http') : null;\n};\n\nexport const getDetails = (\n mediaFullPath: string,\n extesnion: 'mp3' | 'mp4' = 'mp3'\n): Promise<any | null> => {\n return new Promise(async (resolve, reject) => {\n try {\n // Since we used \"-v error\", a work around is to call first this command before the following\n const result: any = {};\n if (result !== 0) {\n throw new Error('Failed to execute command');\n }\n\n // get the output result of the command\n // example of output {\"programs\": [], \"streams\": [{\"width\": 640,\"height\": 360}], \"format\": {\"size\": \"15804433\"}}\n let mediaInfo: any = await {};\n mediaInfo = JSON.parse(mediaInfo);\n\n // execute second command\n const mediaInformation: any = await {};\n\n // treat both results\n mediaInformation.filename = getFilename(mediaFullPath);\n mediaInformation.bitrate = mediaInformation.getMediaProperties().bit_rate;\n mediaInformation.extension = extesnion;\n mediaInformation.isRemoteMedia = isRemoteMedia(mediaFullPath);\n mediaInformation.size = Number(mediaInfo.format.size);\n\n resolve(mediaInformation);\n } catch (e) {\n reject(e);\n }\n });\n};\n\nexport const checkUrlAndOptions = async (\n url: string,\n options: audioCompresssionType\n): Promise<defaultResultType> => {\n if (!url) {\n throw new Error(\n 'Compression url is empty, please provide a url for compression.'\n );\n }\n const defaultResult: defaultResultType = {\n outputFilePath: '',\n isCorrect: true,\n message: '',\n };\n\n // Check if output file is correct\n let outputFilePath: string | undefined | null;\n try {\n // use default output file\n // or use new file from cache folder\n if (options.outputFilePath) {\n outputFilePath = options.outputFilePath;\n defaultResult.outputFilePath = outputFilePath;\n } else {\n outputFilePath = await generateFile('mp3');\n defaultResult.outputFilePath = outputFilePath;\n }\n if (outputFilePath === undefined || outputFilePath === null) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n }\n } catch (e) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n } finally {\n return defaultResult;\n }\n};\n"]}
1
+ {"version":3,"sources":["index.tsx"],"names":["Compressor","NativeModules","AUDIO_BITRATE","INCORRECT_INPUT_PATH","INCORRECT_OUTPUT_PATH","ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE","DEFAULT_COMPRESS_AUDIO_OPTIONS","bitrate","quality","outputFilePath","generateFile","extension","Promise","resolve","reject","then","result","catch","error","isValidUrl","url","test","getFullFilename","path","_path","includes","length","substring","array","split","isFileNameError","filename","getFilename","fullFilename","slice","join","isRemoteMedia","getDetails","mediaFullPath","extesnion","Error","mediaInfo","JSON","parse","mediaInformation","getMediaProperties","bit_rate","size","Number","format","e","checkUrlAndOptions","options","defaultResult","isCorrect","message","undefined","uuidv4","replace","c","r","parseFloat","Math","random","toString","Date","getTime","v"],"mappings":";;;;;;;AACA;;AADA;AAEA,MAAM;AAAEA,EAAAA;AAAF,IAAiBC,0BAAvB;AACO,MAAMC,aAAa,GAAG,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,EAAgB,GAAhB,EAAqB,EAArB,EAAyB,EAAzB,EAA6B,EAA7B,CAAtB;;AAEP,MAAMC,oBAAoB,GAAG,kDAA7B;AACA,MAAMC,qBAAqB,GACzB,mDADF;AAEA,MAAMC,wCAAwC,GAC5C,6CADF;AAcO,MAAMC,8BAAqD,GAAG;AACnEC,EAAAA,OAAO,EAAE,EAD0D;AAEnEC,EAAAA,OAAO,EAAE,QAF0D;AAGnEC,EAAAA,cAAc,EAAE;AAHmD,CAA9D;;;AAUP,MAAMC,YAAiB,GAAIC,SAAD,IAAuB;AAC/C,SAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;AACtCd,IAAAA,UAAU,CAACU,YAAX,CAAwBC,S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,MAAMI,MAAM,GAAG,MAAM;AAC1B,SAAO,uCAAuCC,OAAvC,CAA+C,OAA/C,EAAwD,UAAUC,CAAV,EAAa;AAC1E,UAAMC,CAAC,GACFC,UAAU,CACT,OACEC,IAAI,CAACC,MAAL,GAAcC,QAAd,GAAyBN,OAAzB,CAAiC,IAAjC,EAAuC,EAAvC,CADF,GAEE,IAAIO,IAAJ,GAAWC,OAAX,EAHO,CAAV,GAKC,EALF,GAMA,CAPJ;AAAA,UAQE;AACAC,IAAAA,CAAC,GAAGR,CAAC,IAAI,GAAL,GAAWC,CAAX,GAAgBA,CAAC,GAAG,GAAL,GAAY,GATjC;AAUA,WAAOO,CAAC,CAACH,QAAF,CAAW,EAAX,CAAP;AACD,GAZM,CAAP;AAaD,CAdM","sourcesContent":["/* eslint-disable no-bitwise */\nimport { NativeModules } from 'react-native';\nconst { Compressor } = NativeModules;\nexport const AUDIO_BITRATE = [256, 192, 160, 128, 96, 64, 32];\ntype qualityType = 'low' | 'medium' | 'high';\nconst INCORRECT_INPUT_PATH = 'Incorrect input path. Please provide a valid one';\nconst INCORRECT_OUTPUT_PATH =\n 'Incorrect output path. Please provide a valid one';\nconst ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE =\n 'An error occur while generating output file';\ntype audioCompresssionType = {\n bitrate?: number;\n quality: qualityType;\n outputFilePath?: string | undefined | null;\n};\n\nexport type defaultResultType = {\n outputFilePath: string | undefined | null;\n isCorrect: boolean;\n message: string;\n};\n\nexport const DEFAULT_COMPRESS_AUDIO_OPTIONS: audioCompresssionType = {\n bitrate: 96,\n quality: 'medium',\n outputFilePath: '',\n};\n\nexport type AudioType = {\n compress(value: string, options?: audioCompresssionType): Promise<string>;\n};\n\nconst generateFile: any = (extension: string) => {\n return new Promise((resolve, reject) => {\n Compressor.generateFile(extension)\n .then((result: any) => resolve('file://' + result))\n .catch((error: any) => reject(error));\n });\n};\n\nconst isValidUrl = (url: string) =>\n /^(?:\\w+:)?\\/\\/([^\\s\\.]+\\.\\S{2}|localhost[\\:?\\d]*)\\S*$/.test(url);\n\nconst getFullFilename = (path: string | null) => {\n if (typeof path === 'string') {\n let _path = path;\n\n // In case of remote media, check if the url would be valid one\n if (path.includes('http') && !isValidUrl(path)) {\n return INCORRECT_INPUT_PATH;\n }\n\n // In case of url, check if it ends with \"/\" and do not consider it furthermore\n if (_path[_path.length - 1] === '/')\n _path = _path.substring(0, path.length - 1);\n\n const array = _path.split('/');\n return array.length > 1 ? array[array.length - 1] : INCORRECT_INPUT_PATH;\n }\n return INCORRECT_INPUT_PATH;\n};\n\nconst isFileNameError = (filename: string) => {\n return filename === INCORRECT_INPUT_PATH;\n};\n\nconst getFilename = (path: string | null) => {\n const fullFilename = getFullFilename(path);\n if (!isFileNameError(fullFilename)) {\n const array = fullFilename.split('.');\n return array.length > 1 ? array.slice(0, -1).join('') : array.join('');\n }\n return fullFilename;\n};\n\nconst isRemoteMedia = (path: string | null) => {\n return typeof path === 'string' ? path.split(':/')[0].includes('http') : null;\n};\n\nexport const getDetails = (\n mediaFullPath: string,\n extesnion: 'mp3' | 'mp4' = 'mp3'\n): Promise<any | null> => {\n return new Promise(async (resolve, reject) => {\n try {\n // Since we used \"-v error\", a work around is to call first this command before the following\n const result: any = {};\n if (result !== 0) {\n throw new Error('Failed to execute command');\n }\n\n // get the output result of the command\n // example of output {\"programs\": [], \"streams\": [{\"width\": 640,\"height\": 360}], \"format\": {\"size\": \"15804433\"}}\n let mediaInfo: any = await {};\n mediaInfo = JSON.parse(mediaInfo);\n\n // execute second command\n const mediaInformation: any = await {};\n\n // treat both results\n mediaInformation.filename = getFilename(mediaFullPath);\n mediaInformation.bitrate = mediaInformation.getMediaProperties().bit_rate;\n mediaInformation.extension = extesnion;\n mediaInformation.isRemoteMedia = isRemoteMedia(mediaFullPath);\n mediaInformation.size = Number(mediaInfo.format.size);\n\n resolve(mediaInformation);\n } catch (e) {\n reject(e);\n }\n });\n};\n\nexport const checkUrlAndOptions = async (\n url: string,\n options: audioCompresssionType\n): Promise<defaultResultType> => {\n if (!url) {\n throw new Error(\n 'Compression url is empty, please provide a url for compression.'\n );\n }\n const defaultResult: defaultResultType = {\n outputFilePath: '',\n isCorrect: true,\n message: '',\n };\n\n // Check if output file is correct\n let outputFilePath: string | undefined | null;\n try {\n // use default output file\n // or use new file from cache folder\n if (options.outputFilePath) {\n outputFilePath = options.outputFilePath;\n defaultResult.outputFilePath = outputFilePath;\n } else {\n outputFilePath = await generateFile('mp3');\n defaultResult.outputFilePath = outputFilePath;\n }\n if (outputFilePath === undefined || outputFilePath === null) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n }\n } catch (e) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n } finally {\n return defaultResult;\n }\n};\n\nexport const uuidv4 = () => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {\n const r =\n (parseFloat(\n '0.' +\n Math.random().toString().replace('0.', '') +\n new Date().getTime()\n ) *\n 16) |\n 0,\n // eslint-disable-next-line eqeqeq\n v = c == 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n};\n"]}
@@ -1,6 +1,5 @@
1
1
  import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
2
- import 'react-native-get-random-values';
3
- import { v4 as uuidv4 } from 'uuid';
2
+ import { uuidv4 } from '../utils';
4
3
  const VideoCompressEventEmitter = new NativeEventEmitter(NativeModules.VideoCompressor);
5
4
  const NativeVideoCompressor = NativeModules.VideoCompressor;
6
5
  export const backgroundUpload = async (url, fileUrl, options, onProgress) => {
@@ -65,6 +64,10 @@ const Video = {
65
64
  modifiedOptions.maxSize = 640;
66
65
  }
67
66
 
67
+ if (options !== null && options !== void 0 && options.minimumFileSizeForCompress) {
68
+ modifiedOptions.minimumFileSizeForCompress = options === null || options === void 0 ? void 0 : options.minimumFileSizeForCompress;
69
+ }
70
+
68
71
  const result = await NativeVideoCompressor.compress(fileUrl, modifiedOptions);
69
72
  return result;
70
73
  } finally {
@@ -1 +1 @@
1
- {"version":3,"sources":["index.tsx"],"names":["NativeModules","NativeEventEmitter","Platform","v4","uuidv4","VideoCompressEventEmitter","VideoCompressor","NativeVideoCompressor","backgroundUpload","url","fileUrl","options","onProgress","uuid","subscription","addListener","event","data","written","total","OS","includes","replace","result","upload","method","httpMethod","headers","remove","Video","compress","progress","modifiedOptions","bitrate","compressionMethod","maxSize","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners"],"mappings":"AAAA,SACEA,aADF,EAEEC,kBAFF,EAGEC,QAHF,QAKO,cALP;AAMA,OAAO,gCAAP;AACA,SAASC,EAAE,IAAIC,MAAf,QAA6B,MAA7B;AA4DA,MAAMC,yBAAyB,GAAG,IAAIJ,kBAAJ,CAChCD,aAAa,CAACM,eADkB,CAAlC;AAIA,MAAMC,qBAAqB,GAAGP,aAAa,CAACM,eAA5C;AAEA,OAAO,MAAME,gBAAgB,GAAG,OAC9BC,GAD8B,EAE9BC,OAF8B,EAG9BC,OAH8B,EAI9BC,UAJ8B,KAKb;AACjB,QAAMC,IAAI,GAAGT,MAAM,EAAnB;AACA,MAAIU,YAAJ;;AACA,MAAI;AACF,QAAIF,UAAJ,EAAgB;AACdE,MAAAA,YAAY,GAAGT,yBAAyB,CAACU,WAA1B,CACb,yBADa,EAEZC,KAAD,IAAgB;AACd,YAAIA,KAAK,CAACH,IAAN,KAAeA,IAAnB,EAAyB;AACvBD,UAAAA,UAAU,CAACI,KAAK,CAACC,IAAN,CAAWC,OAAZ,EAAqBF,KAAK,CAACC,IAAN,CAAWE,KAAhC,CAAV;AACD;AACF,OANY,CAAf;AAQD;;AACD,QAAIjB,QAAQ,CAACkB,EAAT,KAAgB,SAAhB,IAA6BV,OAAO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,OAApC,aAAoCA,OAApC,uBAAoCA,OAAO,CAAEuB,iBAA7C;AACD,OAFD,MAEO;AACLF,QAAAA,eAAe,CAACE,iBAAhB,GAAoC,QAApC;AACD;;AACD,UAAIvB,OAAJ,aAAIA,OAAJ,eAAIA,OAAO,CAAEwB,OAAb,EAAsB;AACpBH,QAAAA,eAAe,CAACG,OAAhB,GAA0BxB,OAA1B,aAA0BA,OAA1B,uBAA0BA,OAAO,CAAEwB,OAAnC;AACD,OAFD,MAEO;AACLH,QAAAA,eAAe,CAACG,OAAhB,GAA0B,GAA1B;AACD;;AACD,YAAMZ,MAAM,GAAG,MAAMhB,qBAAqB,CAACuB,QAAtB,CACnBpB,OADmB,EAEnBsB,eAFmB,CAArB;AAIA,aAAOT,MAAP;AACD,KAjCD,SAiCU;AACR;AACA,UAAIT,YAAJ,EAAkB;AAChBA,QAAAA,YAAY,CAACc,MAAb;AACD;AACF;AACF,GAnDgC;AAoDjCpB,EAAAA,gBApDiC;;AAqDjC4B,EAAAA,sBAAsB,CAACC,SAAD,EAAa;AACjC,QAAIA,SAAJ,EAAe;AACb,YAAMvB,YAAqC,GACzCT,yBAAyB,CAACU,WAA1B,CACE,uBADF,EAEGC,KAAD,IAAgB;AACdqB,QAAAA,SAAS,CAACrB,KAAD,CAAT;;AACA,YAAIF,YAAJ,EAAkB;AAChBA,UAAAA,YAAY,CAACc,MAAb;AACD;AACF,OAPH,CADF;AAUD;;AACD,WAAOrB,qBAAqB,CAAC6B,sBAAtB,CAA6C,EAA7C,CAAP;AACD,GAnEgC;;AAoEjCE,EAAAA,wBAAwB,GAAG;AACzBjC,IAAAA,yBAAyB,CAACkC,kBAA1B,CAA6C,uBAA7C;AACA,WAAOhC,qBAAqB,CAAC+B,wBAAtB,CAA+C,EAA/C,CAAP;AACD;;AAvEgC,CAAnC;AA0EA,eAAeT,KAAf","sourcesContent":["import {\n NativeModules,\n NativeEventEmitter,\n Platform,\n NativeEventSubscription,\n} from 'react-native';\nimport 'react-native-get-random-values';\nimport { v4 as uuidv4 } from 'uuid';\n\nexport declare enum FileSystemUploadType {\n BINARY_CONTENT = 0,\n MULTIPART = 1,\n}\n\nexport declare type FileSystemAcceptedUploadHttpMethod =\n | 'POST'\n | 'PUT'\n | 'PATCH';\nexport type compressionMethod = 'auto' | 'manual';\ntype videoCompresssionType = {\n bitrate?: number;\n compressionMethod?: compressionMethod;\n};\n\nexport declare enum FileSystemSessionType {\n BACKGROUND = 0,\n FOREGROUND = 1,\n}\n\nexport declare type HTTPResponse = {\n status: number;\n headers: Record<string, string>;\n body: string;\n};\n\nexport declare type FileSystemUploadOptions = (\n | {\n uploadType?: FileSystemUploadType.BINARY_CONTENT;\n }\n | {\n uploadType: FileSystemUploadType.MULTIPART;\n fieldName?: string;\n mimeType?: string;\n parameters?: Record<string, string>;\n }\n) & {\n headers?: Record<string, string>;\n httpMethod?: FileSystemAcceptedUploadHttpMethod;\n sessionType?: FileSystemSessionType;\n};\n\nexport type VideoCompressorType = {\n compress(\n fileUrl: string,\n options?: videoCompresssionType,\n onProgress?: (progress: number) => void\n ): Promise<string>;\n backgroundUpload(\n url: string,\n fileUrl: string,\n options: FileSystemUploadOptions,\n onProgress?: (writtem: number, total: number) => void\n ): Promise<any>;\n activateBackgroundTask(onExpired?: (data: any) => void): Promise<any>;\n deactivateBackgroundTask(): Promise<any>;\n};\n\nconst VideoCompressEventEmitter = new NativeEventEmitter(\n NativeModules.VideoCompressor\n);\n\nconst NativeVideoCompressor = NativeModules.VideoCompressor;\n\nexport const backgroundUpload = async (\n url: string,\n fileUrl: string,\n options: FileSystemUploadOptions,\n onProgress?: (writtem: number, total: number) => void\n): Promise<any> => {\n const uuid = uuidv4();\n let subscription: NativeEventSubscription;\n try {\n if (onProgress) {\n subscription = VideoCompressEventEmitter.addListener(\n 'VideoCompressorProgress',\n (event: any) => {\n if (event.uuid === uuid) {\n onProgress(event.data.written, event.data.total);\n }\n }\n );\n }\n if (Platform.OS === 'android' && fileUrl.includes('file://')) {\n fileUrl = fileUrl.replace('file://', '');\n }\n const result = await NativeVideoCompressor.upload(fileUrl, {\n uuid,\n method: options.httpMethod,\n headers: options.headers,\n url,\n });\n return result;\n } finally {\n // @ts-ignore\n if (subscription) {\n subscription.remove();\n }\n }\n};\n\nconst Video: VideoCompressorType = {\n compress: async (\n fileUrl: string,\n options?: {\n bitrate?: number;\n compressionMethod?: compressionMethod;\n maxSize?: number;\n },\n onProgress?: (progress: number) => void\n ) => {\n const uuid = uuidv4();\n let subscription: NativeEventSubscription;\n try {\n if (onProgress) {\n subscription = VideoCompressEventEmitter.addListener(\n 'videoCompressProgress',\n (event: any) => {\n if (event.uuid === uuid) {\n onProgress(event.data.progress);\n }\n }\n );\n }\n const modifiedOptions: {\n uuid: string;\n bitrate?: number;\n compressionMethod?: compressionMethod;\n maxSize?: number;\n } = { uuid };\n if (options?.bitrate) modifiedOptions.bitrate = options?.bitrate;\n if (options?.compressionMethod) {\n modifiedOptions.compressionMethod = options?.compressionMethod;\n } else {\n modifiedOptions.compressionMethod = 'manual';\n }\n if (options?.maxSize) {\n modifiedOptions.maxSize = options?.maxSize;\n } else {\n modifiedOptions.maxSize = 640;\n }\n const result = await NativeVideoCompressor.compress(\n fileUrl,\n modifiedOptions\n );\n return result;\n } finally {\n // @ts-ignore\n if (subscription) {\n subscription.remove();\n }\n }\n },\n backgroundUpload,\n activateBackgroundTask(onExpired?) {\n if (onExpired) {\n const subscription: NativeEventSubscription =\n VideoCompressEventEmitter.addListener(\n 'backgroundTaskExpired',\n (event: any) => {\n onExpired(event);\n if (subscription) {\n subscription.remove();\n }\n }\n );\n }\n return NativeVideoCompressor.activateBackgroundTask({});\n },\n deactivateBackgroundTask() {\n VideoCompressEventEmitter.removeAllListeners('backgroundTaskExpired');\n return NativeVideoCompressor.deactivateBackgroundTask({});\n },\n} as VideoCompressorType;\n\nexport default Video;\n"]}
1
+ {"version":3,"sources":["index.tsx"],"names":["NativeModules","NativeEventEmitter","Platform","uuidv4","VideoCompressEventEmitter","VideoCompressor","NativeVideoCompressor","backgroundUpload","url","fileUrl","options","onProgress","uuid","subscription","addListener","event","data","written","total","OS","includes","replace","result","upload","method","httpMethod","headers","remove","Video","compress","progress","modifiedOptions","bitrate","compressionMethod","maxSize","minimumFileSizeForCompress","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners"],"mappings":"AAAA,SACEA,aADF,EAEEC,kBAFF,EAGEC,QAHF,QAKO,cALP;AAMA,SAASC,MAAT,QAAuB,UAAvB;AA8DA,MAAMC,yBAAyB,GAAG,IAAIH,kBAAJ,CAChCD,aAAa,CAACK,eADkB,CAAlC;AAIA,MAAMC,qBAAqB,GAAGN,aAAa,CAACK,eAA5C;AAEA,OAAO,MAAME,gBAAgB,GAAG,OAC9BC,GAD8B,EAE9BC,OAF8B,EAG9BC,OAH8B,EAI9BC,UAJ8B,KAKb;AACjB,QAAMC,IAAI,GAAGT,MAAM,EAAnB;AACA,MAAIU,YAAJ;;AACA,MAAI;AACF,QAAIF,UAAJ,EAAgB;AACdE,MAAAA,YAAY,GAAGT,yBAAyB,CAACU,WAA1B,CACb,yBADa,EAEZC,KAAD,IAAgB;AACd,YAAIA,KAAK,CAACH,IAAN,KAAeA,IAAnB,EAAyB;AACvBD,UAAAA,UAAU,CAACI,KAAK,CAACC,IAAN,CAAWC,OAAZ,EAAqBF,KAAK,CAACC,IAAN,CAAWE,KAAhC,CAAV;AACD;AACF,OANY,CAAf;AAQD;;AACD,QAAIhB,QAAQ,CAACiB,EAAT,KAAgB,SAAhB,IAA6BV,OAAO,CAACW,QAAR,CAAiB,SAAjB,CAAjC,EAA8D;AAC5DX,MAAAA,OAAO,GAAGA,OAAO,CAACY,OAAR,CAAgB,SAAhB,EAA2B,EAA3B,CAAV;AACD;;AACD,UAAMC,MAAM,GAAG,MAAMhB,qBAAqB,CAACiB,MAAtB,CAA6Bd,OAA7B,EAAsC;AACzDG,MAAAA,IADyD;AAEzDY,MAAAA,MAAM,EAAEd,OAAO,CAACe,UAFy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AEwB,OAAnC;AACD,OAFD,MAEO;AACLH,QAAAA,eAAe,CAACG,OAAhB,GAA0B,GAA1B;AACD;;AACD,UAAIxB,OAAJ,aAAIA,OAAJ,eAAIA,OAAO,CAAEyB,0BAAb,EAAyC;AACvCJ,QAAAA,eAAe,CAACI,0BAAhB,GACEzB,OADF,aACEA,OADF,uBACEA,OAAO,CAAEyB,0BADX;AAED;;AACD,YAAMb,MAAM,GAAG,MAAMhB,qBAAqB,CAACuB,QAAtB,CACnBpB,OADmB,EAEnBsB,eAFmB,CAArB;AAIA,aAAOT,MAAP;AACD,KAtCD,SAsCU;AACR;AACA,UAAIT,YAAJ,EAAkB;AAChBA,QAAAA,YAAY,CAACc,MAAb;AACD;AACF;AACF,GAzDgC;AA0DjCpB,EAAAA,gBA1DiC;;AA2DjC6B,EAAAA,sBAAsB,CAACC,SAAD,EAAa;AACjC,QAAIA,SAAJ,EAAe;AACb,YAAMxB,YAAqC,GACzCT,yBAAyB,CAACU,WAA1B,CACE,uBADF,EAEGC,KAAD,IAAgB;AACdsB,QAAAA,SAAS,CAACtB,KAAD,CAAT;;AACA,YAAIF,YAAJ,EAAkB;AAChBA,UAAAA,YAAY,CAACc,MAAb;AACD;AACF,OAPH,CADF;AAUD;;AACD,WAAOrB,qBAAqB,CAAC8B,sBAAtB,CAA6C,EAA7C,CAAP;AACD,GAzEgC;;AA0EjCE,EAAAA,wBAAwB,GAAG;AACzBlC,IAAAA,yBAAyB,CAACmC,kBAA1B,CAA6C,uBAA7C;AACA,WAAOjC,qBAAqB,CAACgC,wBAAtB,CAA+C,EAA/C,CAAP;AACD;;AA7EgC,CAAnC;AAgFA,eAAeV,KAAf","sourcesContent":["import {\n NativeModules,\n NativeEventEmitter,\n Platform,\n NativeEventSubscription,\n} from 'react-native';\nimport { uuidv4 } from '../utils';\n\nexport declare enum FileSystemUploadType {\n BINARY_CONTENT = 0,\n MULTIPART = 1,\n}\n\nexport declare type FileSystemAcceptedUploadHttpMethod =\n | 'POST'\n | 'PUT'\n | 'PATCH';\nexport type compressionMethod = 'auto' | 'manual';\ntype videoCompresssionType = {\n bitrate?: number;\n maxSize?: number;\n compressionMethod?: compressionMethod;\n minimumFileSizeForCompress?: number;\n};\n\nexport declare enum FileSystemSessionType {\n BACKGROUND = 0,\n FOREGROUND = 1,\n}\n\nexport declare type HTTPResponse = {\n status: number;\n headers: Record<string, string>;\n body: string;\n};\n\nexport declare type FileSystemUploadOptions = (\n | {\n uploadType?: FileSystemUploadType.BINARY_CONTENT;\n }\n | {\n uploadType: FileSystemUploadType.MULTIPART;\n fieldName?: string;\n mimeType?: string;\n parameters?: Record<string, string>;\n }\n) & {\n headers?: Record<string, string>;\n httpMethod?: FileSystemAcceptedUploadHttpMethod;\n sessionType?: FileSystemSessionType;\n};\n\nexport type VideoCompressorType = {\n compress(\n fileUrl: string,\n options?: videoCompresssionType,\n onProgress?: (progress: number) => void\n ): Promise<string>;\n backgroundUpload(\n url: string,\n fileUrl: string,\n options: FileSystemUploadOptions,\n onProgress?: (writtem: number, total: number) => void\n ): Promise<any>;\n activateBackgroundTask(onExpired?: (data: any) => void): Promise<any>;\n deactivateBackgroundTask(): Promise<any>;\n};\n\nconst VideoCompressEventEmitter = new NativeEventEmitter(\n NativeModules.VideoCompressor\n);\n\nconst NativeVideoCompressor = NativeModules.VideoCompressor;\n\nexport const backgroundUpload = async (\n url: string,\n fileUrl: string,\n options: FileSystemUploadOptions,\n onProgress?: (writtem: number, total: number) => void\n): Promise<any> => {\n const uuid = uuidv4();\n let subscription: NativeEventSubscription;\n try {\n if (onProgress) {\n subscription = VideoCompressEventEmitter.addListener(\n 'VideoCompressorProgress',\n (event: any) => {\n if (event.uuid === uuid) {\n onProgress(event.data.written, event.data.total);\n }\n }\n );\n }\n if (Platform.OS === 'android' && fileUrl.includes('file://')) {\n fileUrl = fileUrl.replace('file://', '');\n }\n const result = await NativeVideoCompressor.upload(fileUrl, {\n uuid,\n method: options.httpMethod,\n headers: options.headers,\n url,\n });\n return result;\n } finally {\n // @ts-ignore\n if (subscription) {\n subscription.remove();\n }\n }\n};\n\nconst Video: VideoCompressorType = {\n compress: async (\n fileUrl: string,\n options?: {\n bitrate?: number;\n compressionMethod?: compressionMethod;\n maxSize?: number;\n minimumFileSizeForCompress?: number;\n },\n onProgress?: (progress: number) => void\n ) => {\n const uuid = uuidv4();\n let subscription: NativeEventSubscription;\n try {\n if (onProgress) {\n subscription = VideoCompressEventEmitter.addListener(\n 'videoCompressProgress',\n (event: any) => {\n if (event.uuid === uuid) {\n onProgress(event.data.progress);\n }\n }\n );\n }\n const modifiedOptions: {\n uuid: string;\n bitrate?: number;\n compressionMethod?: compressionMethod;\n maxSize?: number;\n minimumFileSizeForCompress?: number;\n } = { uuid };\n if (options?.bitrate) modifiedOptions.bitrate = options?.bitrate;\n if (options?.compressionMethod) {\n modifiedOptions.compressionMethod = options?.compressionMethod;\n } else {\n modifiedOptions.compressionMethod = 'manual';\n }\n if (options?.maxSize) {\n modifiedOptions.maxSize = options?.maxSize;\n } else {\n modifiedOptions.maxSize = 640;\n }\n if (options?.minimumFileSizeForCompress) {\n modifiedOptions.minimumFileSizeForCompress =\n options?.minimumFileSizeForCompress;\n }\n const result = await NativeVideoCompressor.compress(\n fileUrl,\n modifiedOptions\n );\n return result;\n } finally {\n // @ts-ignore\n if (subscription) {\n subscription.remove();\n }\n }\n },\n backgroundUpload,\n activateBackgroundTask(onExpired?) {\n if (onExpired) {\n const subscription: NativeEventSubscription =\n VideoCompressEventEmitter.addListener(\n 'backgroundTaskExpired',\n (event: any) => {\n onExpired(event);\n if (subscription) {\n subscription.remove();\n }\n }\n );\n }\n return NativeVideoCompressor.activateBackgroundTask({});\n },\n deactivateBackgroundTask() {\n VideoCompressEventEmitter.removeAllListeners('backgroundTaskExpired');\n return NativeVideoCompressor.deactivateBackgroundTask({});\n },\n} as VideoCompressorType;\n\nexport default Video;\n"]}
@@ -0,0 +1,8 @@
1
+ import { createRunOncePlugin } from '@expo/config-plugins';
2
+
3
+ const pkg = require('../../../package.json');
4
+
5
+ const withCompressor = config => config;
6
+
7
+ export default createRunOncePlugin(withCompressor, pkg.name, pkg.version);
8
+ //# sourceMappingURL=compressor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["compressor.ts"],"names":["createRunOncePlugin","pkg","require","withCompressor","config","name","version"],"mappings":"AAAA,SAAuBA,mBAAvB,QAAkD,sBAAlD;;AACA,MAAMC,GAAG,GAAGC,OAAO,CAAC,uBAAD,CAAnB;;AAIA,MAAMC,cAAmC,GAAIC,MAAD,IAAYA,MAAxD;;AAEA,eAAeJ,mBAAmB,CAACG,cAAD,EAAiBF,GAAG,CAACI,IAArB,EAA2BJ,GAAG,CAACK,OAA/B,CAAlC","sourcesContent":["import { ConfigPlugin, createRunOncePlugin } from '@expo/config-plugins';\nconst pkg = require('../../../package.json');\n\ntype Props = {};\n\nconst withCompressor: ConfigPlugin<Props> = (config) => config;\n\nexport default createRunOncePlugin(withCompressor, pkg.name, pkg.version);\n"]}
@@ -1,14 +1,15 @@
1
1
  import Video, { VideoCompressorType, backgroundUpload } from './Video';
2
2
  import Audio from './Audio';
3
3
  import Image from './Image';
4
- import { getDetails } from './utils';
4
+ import { getDetails, uuidv4 } from './utils';
5
5
  export { Video, Audio, Image, backgroundUpload //type
6
- , VideoCompressorType, getDetails };
6
+ , VideoCompressorType, getDetails, uuidv4 };
7
7
  export default {
8
8
  Video,
9
9
  Audio,
10
10
  Image,
11
11
  backgroundUpload,
12
- getDetails
12
+ getDetails,
13
+ uuidv4
13
14
  };
14
15
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["index.tsx"],"names":["Video","VideoCompressorType","backgroundUpload","Audio","Image","getDetails"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,mBAAhB,EAAqCC,gBAArC,QAA6D,SAA7D;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,SAASC,UAAT,QAA2B,SAA3B;AAEA,SACEL,KADF,EAEEG,KAFF,EAGEC,KAHF,EAIEF,gBAJF,CAKE;AALF,EAMED,mBANF,EAOEI,UAPF;AASA,eAAe;AACbL,EAAAA,KADa;AAEbG,EAAAA,KAFa;AAGbC,EAAAA,KAHa;AAIbF,EAAAA,gBAJa;AAKbG,EAAAA;AALa,CAAf","sourcesContent":["import Video, { VideoCompressorType, backgroundUpload } from './Video';\nimport Audio from './Audio';\nimport Image from './Image';\nimport { getDetails } from './utils';\n\nexport {\n Video,\n Audio,\n Image,\n backgroundUpload,\n //type\n VideoCompressorType,\n getDetails,\n};\nexport default {\n Video,\n Audio,\n Image,\n backgroundUpload,\n getDetails,\n};\n"]}
1
+ {"version":3,"sources":["index.tsx"],"names":["Video","VideoCompressorType","backgroundUpload","Audio","Image","getDetails","uuidv4"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,mBAAhB,EAAqCC,gBAArC,QAA6D,SAA7D;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,SAASC,UAAT,EAAqBC,MAArB,QAAmC,SAAnC;AAEA,SACEN,KADF,EAEEG,KAFF,EAGEC,KAHF,EAIEF,gBAJF,CAKE;AALF,EAMED,mBANF,EAOEI,UAPF,EAQEC,MARF;AAUA,eAAe;AACbN,EAAAA,KADa;AAEbG,EAAAA,KAFa;AAGbC,EAAAA,KAHa;AAIbF,EAAAA,gBAJa;AAKbG,EAAAA,UALa;AAMbC,EAAAA;AANa,CAAf","sourcesContent":["import Video, { VideoCompressorType, backgroundUpload } from './Video';\nimport Audio from './Audio';\nimport Image from './Image';\nimport { getDetails, uuidv4 } from './utils';\n\nexport {\n Video,\n Audio,\n Image,\n backgroundUpload,\n //type\n VideoCompressorType,\n getDetails,\n uuidv4,\n};\nexport default {\n Video,\n Audio,\n Image,\n backgroundUpload,\n getDetails,\n uuidv4,\n};\n"]}
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-bitwise */
1
2
  import { NativeModules } from 'react-native';
2
3
  const {
3
4
  Compressor
@@ -121,4 +122,12 @@ export const checkUrlAndOptions = async (url, options) => {
121
122
  return defaultResult;
122
123
  }
123
124
  };
125
+ export const uuidv4 = () => {
126
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
127
+ const r = parseFloat('0.' + Math.random().toString().replace('0.', '') + new Date().getTime()) * 16 | 0,
128
+ // eslint-disable-next-line eqeqeq
129
+ v = c == 'x' ? r : r & 0x3 | 0x8;
130
+ return v.toString(16);
131
+ });
132
+ };
124
133
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["index.tsx"],"names":["NativeModules","Compressor","AUDIO_BITRATE","INCORRECT_INPUT_PATH","INCORRECT_OUTPUT_PATH","ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE","DEFAULT_COMPRESS_AUDIO_OPTIONS","bitrate","quality","outputFilePath","generateFile","extension","Promise","resolve","reject","then","result","catch","error","isValidUrl","url","test","getFullFilename","path","_path","includes","length","substring","array","split","isFileNameError","filename","getFilename","fullFilename","slice","join","isRemoteMedia","getDetails","mediaFullPath","extesnion","Error","mediaInfo","JSON","parse","mediaInformation","getMediaProperties","bit_rate","size","Number","format","e","checkUrlAndOptions","options","defaultResult","isCorrect","message","undefined"],"mappings":"AAAA,SAASA,aAAT,QAA8B,cAA9B;AACA,MAAM;AAAEC,EAAAA;AAAF,IAAiBD,aAAvB;AACA,OAAO,MAAME,aAAa,GAAG,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,EAAgB,GAAhB,EAAqB,EAArB,EAAyB,EAAzB,EAA6B,EAA7B,CAAtB;AAEP,MAAMC,oBAAoB,GAAG,kDAA7B;AACA,MAAMC,qBAAqB,GACzB,mDADF;AAEA,MAAMC,wCAAwC,GAC5C,6CADF;AAcA,OAAO,MAAMC,8BAAqD,GAAG;AACnEC,EAAAA,OAAO,EAAE,EAD0D;AAEnEC,EAAAA,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AO6C,CAAP,EAAU;AACVG,IAAAA,aAAa,CAACC,SAAd,GAA0B,KAA1B;AACAD,IAAAA,aAAa,CAACE,OAAd,GAAwBH,OAAO,CAAC3C,cAAR,GACpBL,qBADoB,GAEpBC,wCAFJ;AAGD,GArBD,SAqBU;AACR,WAAOgD,aAAP;AACD;AACF,CAzCM","sourcesContent":["import { NativeModules } from 'react-native';\nconst { Compressor } = NativeModules;\nexport const AUDIO_BITRATE = [256, 192, 160, 128, 96, 64, 32];\ntype qualityType = 'low' | 'medium' | 'high';\nconst INCORRECT_INPUT_PATH = 'Incorrect input path. Please provide a valid one';\nconst INCORRECT_OUTPUT_PATH =\n 'Incorrect output path. Please provide a valid one';\nconst ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE =\n 'An error occur while generating output file';\ntype audioCompresssionType = {\n bitrate?: number;\n quality: qualityType;\n outputFilePath?: string | undefined | null;\n};\n\nexport type defaultResultType = {\n outputFilePath: string | undefined | null;\n isCorrect: boolean;\n message: string;\n};\n\nexport const DEFAULT_COMPRESS_AUDIO_OPTIONS: audioCompresssionType = {\n bitrate: 96,\n quality: 'medium',\n outputFilePath: '',\n};\n\nexport type AudioType = {\n compress(value: string, options?: audioCompresssionType): Promise<string>;\n};\n\nconst generateFile: any = (extension: string) => {\n return new Promise((resolve, reject) => {\n Compressor.generateFile(extension)\n .then((result: any) => resolve('file://' + result))\n .catch((error: any) => reject(error));\n });\n};\n\nconst isValidUrl = (url: string) =>\n /^(?:\\w+:)?\\/\\/([^\\s\\.]+\\.\\S{2}|localhost[\\:?\\d]*)\\S*$/.test(url);\n\nconst getFullFilename = (path: string | null) => {\n if (typeof path === 'string') {\n let _path = path;\n\n // In case of remote media, check if the url would be valid one\n if (path.includes('http') && !isValidUrl(path)) {\n return INCORRECT_INPUT_PATH;\n }\n\n // In case of url, check if it ends with \"/\" and do not consider it furthermore\n if (_path[_path.length - 1] === '/')\n _path = _path.substring(0, path.length - 1);\n\n const array = _path.split('/');\n return array.length > 1 ? array[array.length - 1] : INCORRECT_INPUT_PATH;\n }\n return INCORRECT_INPUT_PATH;\n};\n\nconst isFileNameError = (filename: string) => {\n return filename === INCORRECT_INPUT_PATH;\n};\n\nconst getFilename = (path: string | null) => {\n const fullFilename = getFullFilename(path);\n if (!isFileNameError(fullFilename)) {\n const array = fullFilename.split('.');\n return array.length > 1 ? array.slice(0, -1).join('') : array.join('');\n }\n return fullFilename;\n};\n\nconst isRemoteMedia = (path: string | null) => {\n return typeof path === 'string' ? path.split(':/')[0].includes('http') : null;\n};\n\nexport const getDetails = (\n mediaFullPath: string,\n extesnion: 'mp3' | 'mp4' = 'mp3'\n): Promise<any | null> => {\n return new Promise(async (resolve, reject) => {\n try {\n // Since we used \"-v error\", a work around is to call first this command before the following\n const result: any = {};\n if (result !== 0) {\n throw new Error('Failed to execute command');\n }\n\n // get the output result of the command\n // example of output {\"programs\": [], \"streams\": [{\"width\": 640,\"height\": 360}], \"format\": {\"size\": \"15804433\"}}\n let mediaInfo: any = await {};\n mediaInfo = JSON.parse(mediaInfo);\n\n // execute second command\n const mediaInformation: any = await {};\n\n // treat both results\n mediaInformation.filename = getFilename(mediaFullPath);\n mediaInformation.bitrate = mediaInformation.getMediaProperties().bit_rate;\n mediaInformation.extension = extesnion;\n mediaInformation.isRemoteMedia = isRemoteMedia(mediaFullPath);\n mediaInformation.size = Number(mediaInfo.format.size);\n\n resolve(mediaInformation);\n } catch (e) {\n reject(e);\n }\n });\n};\n\nexport const checkUrlAndOptions = async (\n url: string,\n options: audioCompresssionType\n): Promise<defaultResultType> => {\n if (!url) {\n throw new Error(\n 'Compression url is empty, please provide a url for compression.'\n );\n }\n const defaultResult: defaultResultType = {\n outputFilePath: '',\n isCorrect: true,\n message: '',\n };\n\n // Check if output file is correct\n let outputFilePath: string | undefined | null;\n try {\n // use default output file\n // or use new file from cache folder\n if (options.outputFilePath) {\n outputFilePath = options.outputFilePath;\n defaultResult.outputFilePath = outputFilePath;\n } else {\n outputFilePath = await generateFile('mp3');\n defaultResult.outputFilePath = outputFilePath;\n }\n if (outputFilePath === undefined || outputFilePath === null) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n }\n } catch (e) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n } finally {\n return defaultResult;\n }\n};\n"]}
1
+ {"version":3,"sources":["index.tsx"],"names":["NativeModules","Compressor","AUDIO_BITRATE","INCORRECT_INPUT_PATH","INCORRECT_OUTPUT_PATH","ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE","DEFAULT_COMPRESS_AUDIO_OPTIONS","bitrate","quality","outputFilePath","generateFile","extension","Promise","resolve","reject","then","result","catch","error","isValidUrl","url","test","getFullFilename","path","_path","includes","length","substring","array","split","isFileNameError","filename","getFilename","fullFilename","slice","join","isRemoteMedia","getDetails","mediaFullPath","extesnion","Error","mediaInfo","JSON","parse","mediaInformation","getMediaProperties","bit_rate","size","Number","format","e","checkUrlAndOptions","options","defaultResult","isCorrect","message","undefined","uuidv4","replace","c","r","parseFloat","Math","random","toString","Date","getTime","v"],"mappings":"AAAA;AACA,SAASA,aAAT,QAA8B,cAA9B;AACA,MAAM;AAAEC,EAAAA;AAAF,IAAiBD,aAAvB;AACA,OAAO,MAAME,aAAa,GAAG,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,EAAgB,GAAhB,EAAqB,EAArB,EAAyB,EAAzB,EAA6B,EAA7B,CAAtB;AAEP,MAAMC,oBAAoB,GAAG,kDAA7B;AACA,MAAMC,qBAAqB,GACzB,mDADF;AAEA,MAAMC,wCAAwC,GAC5C,6CADF;AAcA,OAAO,MAAMC,8BAAqD,GAAG;AACnEC,EAAAA,OAAO,EAAE,EAD0D;AAEnEC,EAAAA,OAAO,EAAE,QAF0D;AAGnEC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AAA,aAAa,CAACC,SAAd,GAA0B,KAA1B;AACAD,IAAAA,aAAa,CAACE,OAAd,GAAwBH,OAAO,CAAC3C,cAAR,GACpBL,qBADoB,GAEpBC,wCAFJ;AAGD,GArBD,SAqBU;AACR,WAAOgD,aAAP;AACD;AACF,CAzCM;AA2CP,OAAO,MAAMI,MAAM,GAAG,MAAM;AAC1B,SAAO,uCAAuCC,OAAvC,CAA+C,OAA/C,EAAwD,UAAUC,CAAV,EAAa;AAC1E,UAAMC,CAAC,GACFC,UAAU,CACT,OACEC,IAAI,CAACC,MAAL,GAAcC,QAAd,GAAyBN,OAAzB,CAAiC,IAAjC,EAAuC,EAAvC,CADF,GAEE,IAAIO,IAAJ,GAAWC,OAAX,EAHO,CAAV,GAKC,EALF,GAMA,CAPJ;AAAA,UAQE;AACAC,IAAAA,CAAC,GAAGR,CAAC,IAAI,GAAL,GAAWC,CAAX,GAAgBA,CAAC,GAAG,GAAL,GAAY,GATjC;AAUA,WAAOO,CAAC,CAACH,QAAF,CAAW,EAAX,CAAP;AACD,GAZM,CAAP;AAaD,CAdM","sourcesContent":["/* eslint-disable no-bitwise */\nimport { NativeModules } from 'react-native';\nconst { Compressor } = NativeModules;\nexport const AUDIO_BITRATE = [256, 192, 160, 128, 96, 64, 32];\ntype qualityType = 'low' | 'medium' | 'high';\nconst INCORRECT_INPUT_PATH = 'Incorrect input path. Please provide a valid one';\nconst INCORRECT_OUTPUT_PATH =\n 'Incorrect output path. Please provide a valid one';\nconst ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE =\n 'An error occur while generating output file';\ntype audioCompresssionType = {\n bitrate?: number;\n quality: qualityType;\n outputFilePath?: string | undefined | null;\n};\n\nexport type defaultResultType = {\n outputFilePath: string | undefined | null;\n isCorrect: boolean;\n message: string;\n};\n\nexport const DEFAULT_COMPRESS_AUDIO_OPTIONS: audioCompresssionType = {\n bitrate: 96,\n quality: 'medium',\n outputFilePath: '',\n};\n\nexport type AudioType = {\n compress(value: string, options?: audioCompresssionType): Promise<string>;\n};\n\nconst generateFile: any = (extension: string) => {\n return new Promise((resolve, reject) => {\n Compressor.generateFile(extension)\n .then((result: any) => resolve('file://' + result))\n .catch((error: any) => reject(error));\n });\n};\n\nconst isValidUrl = (url: string) =>\n /^(?:\\w+:)?\\/\\/([^\\s\\.]+\\.\\S{2}|localhost[\\:?\\d]*)\\S*$/.test(url);\n\nconst getFullFilename = (path: string | null) => {\n if (typeof path === 'string') {\n let _path = path;\n\n // In case of remote media, check if the url would be valid one\n if (path.includes('http') && !isValidUrl(path)) {\n return INCORRECT_INPUT_PATH;\n }\n\n // In case of url, check if it ends with \"/\" and do not consider it furthermore\n if (_path[_path.length - 1] === '/')\n _path = _path.substring(0, path.length - 1);\n\n const array = _path.split('/');\n return array.length > 1 ? array[array.length - 1] : INCORRECT_INPUT_PATH;\n }\n return INCORRECT_INPUT_PATH;\n};\n\nconst isFileNameError = (filename: string) => {\n return filename === INCORRECT_INPUT_PATH;\n};\n\nconst getFilename = (path: string | null) => {\n const fullFilename = getFullFilename(path);\n if (!isFileNameError(fullFilename)) {\n const array = fullFilename.split('.');\n return array.length > 1 ? array.slice(0, -1).join('') : array.join('');\n }\n return fullFilename;\n};\n\nconst isRemoteMedia = (path: string | null) => {\n return typeof path === 'string' ? path.split(':/')[0].includes('http') : null;\n};\n\nexport const getDetails = (\n mediaFullPath: string,\n extesnion: 'mp3' | 'mp4' = 'mp3'\n): Promise<any | null> => {\n return new Promise(async (resolve, reject) => {\n try {\n // Since we used \"-v error\", a work around is to call first this command before the following\n const result: any = {};\n if (result !== 0) {\n throw new Error('Failed to execute command');\n }\n\n // get the output result of the command\n // example of output {\"programs\": [], \"streams\": [{\"width\": 640,\"height\": 360}], \"format\": {\"size\": \"15804433\"}}\n let mediaInfo: any = await {};\n mediaInfo = JSON.parse(mediaInfo);\n\n // execute second command\n const mediaInformation: any = await {};\n\n // treat both results\n mediaInformation.filename = getFilename(mediaFullPath);\n mediaInformation.bitrate = mediaInformation.getMediaProperties().bit_rate;\n mediaInformation.extension = extesnion;\n mediaInformation.isRemoteMedia = isRemoteMedia(mediaFullPath);\n mediaInformation.size = Number(mediaInfo.format.size);\n\n resolve(mediaInformation);\n } catch (e) {\n reject(e);\n }\n });\n};\n\nexport const checkUrlAndOptions = async (\n url: string,\n options: audioCompresssionType\n): Promise<defaultResultType> => {\n if (!url) {\n throw new Error(\n 'Compression url is empty, please provide a url for compression.'\n );\n }\n const defaultResult: defaultResultType = {\n outputFilePath: '',\n isCorrect: true,\n message: '',\n };\n\n // Check if output file is correct\n let outputFilePath: string | undefined | null;\n try {\n // use default output file\n // or use new file from cache folder\n if (options.outputFilePath) {\n outputFilePath = options.outputFilePath;\n defaultResult.outputFilePath = outputFilePath;\n } else {\n outputFilePath = await generateFile('mp3');\n defaultResult.outputFilePath = outputFilePath;\n }\n if (outputFilePath === undefined || outputFilePath === null) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n }\n } catch (e) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n } finally {\n return defaultResult;\n }\n};\n\nexport const uuidv4 = () => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {\n const r =\n (parseFloat(\n '0.' +\n Math.random().toString().replace('0.', '') +\n new Date().getTime()\n ) *\n 16) |\n 0,\n // eslint-disable-next-line eqeqeq\n v = c == 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n};\n"]}
@@ -1,4 +1,3 @@
1
- import 'react-native-get-random-values';
2
1
  export declare enum FileSystemUploadType {
3
2
  BINARY_CONTENT = 0,
4
3
  MULTIPART = 1
@@ -7,7 +6,9 @@ export declare type FileSystemAcceptedUploadHttpMethod = 'POST' | 'PUT' | 'PATCH
7
6
  export declare type compressionMethod = 'auto' | 'manual';
8
7
  declare type videoCompresssionType = {
9
8
  bitrate?: number;
9
+ maxSize?: number;
10
10
  compressionMethod?: compressionMethod;
11
+ minimumFileSizeForCompress?: number;
11
12
  };
12
13
  export declare enum FileSystemSessionType {
13
14
  BACKGROUND = 0,
@@ -0,0 +1,4 @@
1
+ import { ConfigPlugin } from '@expo/config-plugins';
2
+ declare type Props = {};
3
+ declare const _default: ConfigPlugin<Props>;
4
+ export default _default;
@@ -1,8 +1,8 @@
1
1
  import Video, { VideoCompressorType, backgroundUpload } from './Video';
2
2
  import Audio from './Audio';
3
3
  import Image from './Image';
4
- import { getDetails } from './utils';
5
- export { Video, Audio, Image, backgroundUpload, VideoCompressorType, getDetails, };
4
+ import { getDetails, uuidv4 } from './utils';
5
+ export { Video, Audio, Image, backgroundUpload, VideoCompressorType, getDetails, uuidv4, };
6
6
  declare const _default: {
7
7
  Video: VideoCompressorType;
8
8
  Audio: import("./utils").AudioType;
@@ -11,5 +11,6 @@ declare const _default: {
11
11
  };
12
12
  backgroundUpload: (url: string, fileUrl: string, options: import("./Video").FileSystemUploadOptions, onProgress?: ((writtem: number, total: number) => void) | undefined) => Promise<any>;
13
13
  getDetails: (mediaFullPath: string, extesnion?: "mp3" | "mp4") => Promise<any>;
14
+ uuidv4: () => string;
14
15
  };
15
16
  export default _default;
@@ -16,4 +16,5 @@ export declare type AudioType = {
16
16
  };
17
17
  export declare const getDetails: (mediaFullPath: string, extesnion?: 'mp3' | 'mp4') => Promise<any | null>;
18
18
  export declare const checkUrlAndOptions: (url: string, options: audioCompresssionType) => Promise<defaultResultType>;
19
+ export declare const uuidv4: () => string;
19
20
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-compressor",
3
- "version": "1.0.3",
3
+ "version": "1.2.1",
4
4
  "description": "This library compress image, video and audio",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -13,6 +13,7 @@
13
13
  "android",
14
14
  "ios",
15
15
  "cpp",
16
+ "app.plugin.js",
16
17
  "react-native-compressor.podspec",
17
18
  "!lib/typescript/example",
18
19
  "!android/build",
@@ -59,12 +60,12 @@
59
60
  },
60
61
  "devDependencies": {
61
62
  "@commitlint/config-conventional": "^11.0.0",
63
+ "@expo/config-plugins": "^4.0.14",
62
64
  "@react-native-community/eslint-config": "^2.0.0",
63
65
  "@release-it/conventional-changelog": "^2.0.0",
64
66
  "@types/jest": "^26.0.0",
65
67
  "@types/react": "^17.0.8",
66
68
  "@types/react-native": "^0.64.7",
67
- "@types/uuid": "^8.0.0",
68
69
  "commitlint": "^11.0.0",
69
70
  "eslint": "^7.2.0",
70
71
  "eslint-config-prettier": "^7.0.0",
@@ -81,8 +82,7 @@
81
82
  },
82
83
  "peerDependencies": {
83
84
  "react": "*",
84
- "react-native": "*",
85
- "uuid": "*"
85
+ "react-native": "*"
86
86
  },
87
87
  "jest": {
88
88
  "preset": "react-native",
@@ -162,8 +162,5 @@
162
162
  }
163
163
  ]
164
164
  ]
165
- },
166
- "dependencies": {
167
- "react-native-get-random-values": "^1.7.0"
168
165
  }
169
166
  }
@@ -4,8 +4,7 @@ import {
4
4
  Platform,
5
5
  NativeEventSubscription,
6
6
  } from 'react-native';
7
- import 'react-native-get-random-values';
8
- import { v4 as uuidv4 } from 'uuid';
7
+ import { uuidv4 } from '../utils';
9
8
 
10
9
  export declare enum FileSystemUploadType {
11
10
  BINARY_CONTENT = 0,
@@ -19,7 +18,9 @@ export declare type FileSystemAcceptedUploadHttpMethod =
19
18
  export type compressionMethod = 'auto' | 'manual';
20
19
  type videoCompresssionType = {
21
20
  bitrate?: number;
21
+ maxSize?: number;
22
22
  compressionMethod?: compressionMethod;
23
+ minimumFileSizeForCompress?: number;
23
24
  };
24
25
 
25
26
  export declare enum FileSystemSessionType {
@@ -115,6 +116,7 @@ const Video: VideoCompressorType = {
115
116
  bitrate?: number;
116
117
  compressionMethod?: compressionMethod;
117
118
  maxSize?: number;
119
+ minimumFileSizeForCompress?: number;
118
120
  },
119
121
  onProgress?: (progress: number) => void
120
122
  ) => {
@@ -136,6 +138,7 @@ const Video: VideoCompressorType = {
136
138
  bitrate?: number;
137
139
  compressionMethod?: compressionMethod;
138
140
  maxSize?: number;
141
+ minimumFileSizeForCompress?: number;
139
142
  } = { uuid };
140
143
  if (options?.bitrate) modifiedOptions.bitrate = options?.bitrate;
141
144
  if (options?.compressionMethod) {
@@ -148,6 +151,10 @@ const Video: VideoCompressorType = {
148
151
  } else {
149
152
  modifiedOptions.maxSize = 640;
150
153
  }
154
+ if (options?.minimumFileSizeForCompress) {
155
+ modifiedOptions.minimumFileSizeForCompress =
156
+ options?.minimumFileSizeForCompress;
157
+ }
151
158
  const result = await NativeVideoCompressor.compress(
152
159
  fileUrl,
153
160
  modifiedOptions
@@ -0,0 +1,8 @@
1
+ import { ConfigPlugin, createRunOncePlugin } from '@expo/config-plugins';
2
+ const pkg = require('../../../package.json');
3
+
4
+ type Props = {};
5
+
6
+ const withCompressor: ConfigPlugin<Props> = (config) => config;
7
+
8
+ export default createRunOncePlugin(withCompressor, pkg.name, pkg.version);
package/src/index.tsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import Video, { VideoCompressorType, backgroundUpload } from './Video';
2
2
  import Audio from './Audio';
3
3
  import Image from './Image';
4
- import { getDetails } from './utils';
4
+ import { getDetails, uuidv4 } from './utils';
5
5
 
6
6
  export {
7
7
  Video,
@@ -11,6 +11,7 @@ export {
11
11
  //type
12
12
  VideoCompressorType,
13
13
  getDetails,
14
+ uuidv4,
14
15
  };
15
16
  export default {
16
17
  Video,
@@ -18,4 +19,5 @@ export default {
18
19
  Image,
19
20
  backgroundUpload,
20
21
  getDetails,
22
+ uuidv4,
21
23
  };
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-bitwise */
1
2
  import { NativeModules } from 'react-native';
2
3
  const { Compressor } = NativeModules;
3
4
  export const AUDIO_BITRATE = [256, 192, 160, 128, 96, 64, 32];
@@ -152,3 +153,19 @@ export const checkUrlAndOptions = async (
152
153
  return defaultResult;
153
154
  }
154
155
  };
156
+
157
+ export const uuidv4 = () => {
158
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
159
+ const r =
160
+ (parseFloat(
161
+ '0.' +
162
+ Math.random().toString().replace('0.', '') +
163
+ new Date().getTime()
164
+ ) *
165
+ 16) |
166
+ 0,
167
+ // eslint-disable-next-line eqeqeq
168
+ v = c == 'x' ? r : (r & 0x3) | 0x8;
169
+ return v.toString(16);
170
+ });
171
+ };