react-native-compressor 0.5.12 → 0.5.17

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 +74 -1
  2. package/android/.gradle/6.1.1/fileHashes/fileHashes.lock +0 -0
  3. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  4. package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
  5. package/android/.gradle/checksums/checksums.lock +0 -0
  6. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  7. package/android/build.gradle +40 -44
  8. package/android/src/main/java/com/.DS_Store +0 -0
  9. package/android/src/main/java/com/reactnativecompressor/.DS_Store +0 -0
  10. package/android/src/main/java/com/reactnativecompressor/Audio/AudioCompressor.java +0 -6
  11. package/android/src/main/java/com/reactnativecompressor/CompressorModule.java +46 -37
  12. package/android/src/main/java/com/reactnativecompressor/Utils/RealPathUtil.java +210 -0
  13. package/android/src/main/java/com/reactnativecompressor/Utils/Utils.java +32 -1
  14. package/android/src/main/java/com/reactnativecompressor/Video/AutoVideoCompression/AutoVideoCompression.java +24 -58
  15. package/android/src/main/java/com/reactnativecompressor/Video/VideoCompressorHelper.java +6 -42
  16. package/android/src/main/java/com/reactnativecompressor/Video/VideoModule.java +23 -15
  17. package/ios/.DS_Store +0 -0
  18. package/ios/Compressor-Bridging-Header.h +1 -1
  19. package/ios/Compressor.m +120 -12
  20. package/ios/Image/ImageCompressor.h +2 -0
  21. package/ios/Image/ImageCompressor.m +153 -1
  22. package/ios/Video/VideoCompressor.swift +56 -59
  23. package/lib/commonjs/Audio/index.js.map +1 -1
  24. package/lib/commonjs/Video/index.js +46 -31
  25. package/lib/commonjs/Video/index.js.map +1 -1
  26. package/lib/commonjs/index.js +22 -1
  27. package/lib/commonjs/index.js.map +1 -1
  28. package/lib/commonjs/utils/index.js +18 -4
  29. package/lib/commonjs/utils/index.js.map +1 -1
  30. package/lib/module/Audio/index.js.map +1 -1
  31. package/lib/module/Video/index.js +39 -30
  32. package/lib/module/Video/index.js.map +1 -1
  33. package/lib/module/index.js +6 -3
  34. package/lib/module/index.js.map +1 -1
  35. package/lib/module/utils/index.js +9 -4
  36. package/lib/module/utils/index.js.map +1 -1
  37. package/lib/typescript/Video/index.d.ts +4 -0
  38. package/lib/typescript/index.d.ts +5 -2
  39. package/lib/typescript/utils/index.d.ts +3 -0
  40. package/package.json +1 -1
  41. package/react-native-compressor.podspec +1 -1
  42. package/src/Audio/index.tsx +1 -1
  43. package/src/Video/index.tsx +49 -37
  44. package/src/index.tsx +13 -1
  45. package/src/utils/index.tsx +14 -3
@@ -2,6 +2,39 @@ import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
2
2
  import { uuidv4 } from '../utils';
3
3
  const VideoCompressEventEmitter = new NativeEventEmitter(NativeModules.VideoCompressor);
4
4
  const NativeVideoCompressor = NativeModules.VideoCompressor;
5
+ export const backgroundUpload = async (url, fileUrl, options, onProgress) => {
6
+ const uuid = uuidv4();
7
+ let subscription = null;
8
+
9
+ try {
10
+ if (onProgress) {
11
+ subscription = VideoCompressEventEmitter.addListener('VideoCompressorProgress', event => {
12
+ if (event.uuid === uuid) {
13
+ onProgress(event.data.written, event.data.total);
14
+ }
15
+ });
16
+ }
17
+
18
+ if (Platform.OS === 'android' && fileUrl.includes('file://')) {
19
+ fileUrl = fileUrl.replace('file://', '');
20
+ }
21
+
22
+ const result = await NativeVideoCompressor.upload(fileUrl, {
23
+ uuid,
24
+ method: options.httpMethod,
25
+ headers: options.headers,
26
+ url
27
+ });
28
+ return result;
29
+ } finally {
30
+ if (subscription) {
31
+ VideoCompressEventEmitter.removeSubscription(subscription);
32
+ }
33
+ }
34
+ };
35
+ export const cancelCompression = cancellationId => {
36
+ return NativeVideoCompressor.cancelCompression(cancellationId);
37
+ };
5
38
  const Video = {
6
39
  compress: async (fileUrl, options, onProgress) => {
7
40
  const uuid = uuidv4();
@@ -33,41 +66,15 @@ const Video = {
33
66
  modifiedOptions.maxSize = 640;
34
67
  }
35
68
 
36
- if (options !== null && options !== void 0 && options.minimumFileSizeForCompress) {
69
+ if ((options === null || options === void 0 ? void 0 : options.minimumFileSizeForCompress) !== undefined) {
37
70
  modifiedOptions.minimumFileSizeForCompress = options === null || options === void 0 ? void 0 : options.minimumFileSizeForCompress;
38
71
  }
39
72
 
40
- const result = await NativeVideoCompressor.compress(fileUrl, modifiedOptions);
41
- return result;
42
- } finally {
43
- if (subscription) {
44
- VideoCompressEventEmitter.removeSubscription(subscription);
45
- }
46
- }
47
- },
48
- backgroundUpload: async (url, fileUrl, options, onProgress) => {
49
- const uuid = uuidv4();
50
- let subscription = null;
51
-
52
- try {
53
- if (onProgress) {
54
- subscription = VideoCompressEventEmitter.addListener('VideoCompressorProgress', event => {
55
- if (event.uuid === uuid) {
56
- onProgress(event.data.written, event.data.total);
57
- }
58
- });
73
+ if (options !== null && options !== void 0 && options.getCancellationId) {
74
+ options === null || options === void 0 ? void 0 : options.getCancellationId(uuid);
59
75
  }
60
76
 
61
- if (Platform.OS === 'android' && fileUrl.includes('file://')) {
62
- fileUrl = fileUrl.replace('file://', '');
63
- }
64
-
65
- const result = await NativeVideoCompressor.upload(fileUrl, {
66
- uuid,
67
- method: options.httpMethod,
68
- headers: options.headers,
69
- url
70
- });
77
+ const result = await NativeVideoCompressor.compress(fileUrl, modifiedOptions);
71
78
  return result;
72
79
  } finally {
73
80
  if (subscription) {
@@ -75,6 +82,8 @@ const Video = {
75
82
  }
76
83
  }
77
84
  },
85
+ backgroundUpload: backgroundUpload,
86
+ cancelCompression,
78
87
 
79
88
  activateBackgroundTask(onExpired) {
80
89
  if (onExpired) {
@@ -1 +1 @@
1
- {"version":3,"sources":["index.tsx"],"names":["NativeModules","NativeEventEmitter","Platform","uuidv4","VideoCompressEventEmitter","VideoCompressor","NativeVideoCompressor","Video","compress","fileUrl","options","onProgress","uuid","subscription","addListener","event","data","progress","modifiedOptions","bitrate","compressionMethod","maxSize","minimumFileSizeForCompress","result","removeSubscription","backgroundUpload","url","written","total","OS","includes","replace","upload","method","httpMethod","headers","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners"],"mappings":"AAAA,SAASA,aAAT,EAAwBC,kBAAxB,EAA4CC,QAA5C,QAA4D,cAA5D;AACA,SAASC,MAAT,QAAuB,UAAvB;AA8DA,MAAMC,yBAAyB,GAAG,IAAIH,kBAAJ,CAChCD,aAAa,CAACK,eADkB,CAAlC;AAIA,MAAMC,qBAAqB,GAAGN,aAAa,CAACK,eAA5C;AAEA,MAAME,KAA0B,GAAG;AACjCC,EAAAA,QAAQ,EAAE,OACRC,OADQ,EAERC,OAFQ,EAQRC,UARQ,KASL;AACH,UAAMC,IAAI,GAAGT,MAAM,EAAnB;AACA,QAAIU,YAAY,GAAG,IAAnB;;AACA,QAAI;AACF,UAAIF,UAAJ,EAAgB;AACdE,QAAAA,YAAY,GAAGT,yBAAyB,CAACU,WAA1B,CACb,uBADa,EAEZC,KAAD,IAAgB;AACd,cAAIA,KAAK,CAACH,IAAN,KAAeA,IAAnB,EAAyB;AACvBD,YAAAA,UAAU,CAACI,KAAK,CAACC,IAAN,CAAWC,QAAZ,CAAV;AACD;AACF,SANY,CAAf;AAQD;;AACD,YAAMC,eAML,GAAG;AAAEN,QAAAA;AAAF,OANJ;AAOA,UAAIF,OAAJ,aAAIA,OAAJ,eAAIA,OAAO,CAAES,OAAb,EAAsBD,eAAe,CAACC,OAAhB,GAA0BT,OAA1B,aAA0BA,OAA1B,uBAA0BA,OAAO,CAAES,OAAnC;;AACtB,UAAIT,OAAJ,aAAIA,OAAJ,eAAIA,OAAO,CAAEU,iBAAb,EAAgC;AAC9BF,QAAAA,eAAe,CAACE,iBAAhB,GAAoCV,OAApC,aAAoCA,OAApC,uBAAoCA,OAAO,CAAEU,iBAA7C;AACD,OAFD,MAEO;AACLF,QAAAA,eAAe,CAACE,iBAAhB,GAAoC,QAApC;AACD;;AACD,UAAIV,OAAJ,aAAIA,OAAJ,eAAIA,OAA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AA3B,CAAV;AACD;;AACD,YAAMR,MAAM,GAAG,MAAMjB,qBAAqB,CAAC0B,MAAtB,CAA6BvB,OAA7B,EAAsC;AACzDG,QAAAA,IADyD;AAEzDqB,QAAAA,MAAM,EAAEvB,OAAO,CAACwB,UAFyC;AAGzDC,QAAAA,OAAO,EAAEzB,OAAO,CAACyB,OAHwC;AAIzDT,QAAAA;AAJyD,OAAtC,CAArB;AAMA,aAAOH,MAAP;AACD,KArBD,SAqBU;AACR,UAAIV,YAAJ,EAAkB;AAChBT,QAAAA,yBAAyB,CAACoB,kBAA1B,CAA6CX,YAA7C;AACD;AACF;AACF,GAtFgC;;AAuFjCuB,EAAAA,sBAAsB,CAACC,SAAD,EAAa;AACjC,QAAIA,SAAJ,EAAe;AACb,YAAMxB,YAAY,GAAGT,yBAAyB,CAACU,WAA1B,CACnB,uBADmB,EAElBC,KAAD,IAAgB;AACdsB,QAAAA,SAAS,CAACtB,KAAD,CAAT;AACAX,QAAAA,yBAAyB,CAACoB,kBAA1B,CAA6CX,YAA7C;AACD,OALkB,CAArB;AAOD;;AACD,WAAOP,qBAAqB,CAAC8B,sBAAtB,CAA6C,EAA7C,CAAP;AACD,GAlGgC;;AAmGjCE,EAAAA,wBAAwB,GAAG;AACzBlC,IAAAA,yBAAyB,CAACmC,kBAA1B,CAA6C,uBAA7C;AACA,WAAOjC,qBAAqB,CAACgC,wBAAtB,CAA+C,EAA/C,CAAP;AACD;;AAtGgC,CAAnC;AAyGA,eAAe/B,KAAf","sourcesContent":["import { NativeModules, NativeEventEmitter, Platform } 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\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 = null;\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 if (subscription) {\n VideoCompressEventEmitter.removeSubscription(subscription);\n }\n }\n },\n backgroundUpload: async (url, fileUrl, options, onProgress) => {\n const uuid = uuidv4();\n let subscription = null;\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 if (subscription) {\n VideoCompressEventEmitter.removeSubscription(subscription);\n }\n }\n },\n activateBackgroundTask(onExpired?) {\n if (onExpired) {\n const subscription = VideoCompressEventEmitter.addListener(\n 'backgroundTaskExpired',\n (event: any) => {\n onExpired(event);\n VideoCompressEventEmitter.removeSubscription(subscription);\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","removeSubscription","cancelCompression","cancellationId","Video","compress","progress","modifiedOptions","bitrate","compressionMethod","maxSize","minimumFileSizeForCompress","undefined","getCancellationId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,EAA/C,CAAP;AACD;;AAxEgC,CAAnC;AA2EA,eAAeZ,KAAf","sourcesContent":["import { NativeModules, NativeEventEmitter, Platform } 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 getCancellationId?: (cancellationId: string) => void;\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 cancelCompression(cancellationId: string): void;\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 = null;\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 if (subscription) {\n VideoCompressEventEmitter.removeSubscription(subscription);\n }\n }\n};\n\nexport const cancelCompression = (cancellationId: string) => {\n return NativeVideoCompressor.cancelCompression(cancellationId);\n};\n\nconst Video: VideoCompressorType = {\n compress: async (\n fileUrl: string,\n options?: videoCompresssionType,\n onProgress?: (progress: number) => void\n ) => {\n const uuid = uuidv4();\n let subscription = null;\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 !== undefined) {\n modifiedOptions.minimumFileSizeForCompress =\n options?.minimumFileSizeForCompress;\n }\n if (options?.getCancellationId) {\n options?.getCancellationId(uuid);\n }\n const result = await NativeVideoCompressor.compress(\n fileUrl,\n modifiedOptions\n );\n return result;\n } finally {\n if (subscription) {\n VideoCompressEventEmitter.removeSubscription(subscription);\n }\n }\n },\n backgroundUpload: backgroundUpload,\n cancelCompression,\n activateBackgroundTask(onExpired?) {\n if (onExpired) {\n const subscription = VideoCompressEventEmitter.addListener(\n 'backgroundTaskExpired',\n (event: any) => {\n onExpired(event);\n VideoCompressEventEmitter.removeSubscription(subscription);\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,14 +1,17 @@
1
1
  import Video, { VideoCompressorType } from './Video';
2
2
  import Audio from './Audio';
3
3
  import Image from './Image';
4
- import { getDetails, uuidv4 } from './utils';
4
+ import { getDetails, uuidv4, generateFilePath, getRealPath, getVideoMetaData } from './utils';
5
5
  export { Video, Audio, Image //type
6
- , VideoCompressorType, getDetails, uuidv4 };
6
+ , VideoCompressorType, getDetails, uuidv4, generateFilePath, getRealPath, getVideoMetaData };
7
7
  export default {
8
8
  Video,
9
9
  Audio,
10
10
  Image,
11
11
  getDetails,
12
- uuidv4
12
+ uuidv4,
13
+ generateFilePath,
14
+ getRealPath,
15
+ getVideoMetaData
13
16
  };
14
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["index.tsx"],"names":["Video","VideoCompressorType","Audio","Image","getDetails","uuidv4"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,mBAAhB,QAA2C,SAA3C;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,SAASC,UAAT,EAAqBC,MAArB,QAAmC,SAAnC;AAEA,SACEL,KADF,EAEEE,KAFF,EAGEC,KAHF,CAIE;AAJF,EAKEF,mBALF,EAMEG,UANF,EAOEC,MAPF;AASA,eAAe;AACbL,EAAAA,KADa;AAEbE,EAAAA,KAFa;AAGbC,EAAAA,KAHa;AAIbC,EAAAA,UAJa;AAKbC,EAAAA;AALa,CAAf","sourcesContent":["import Video, { VideoCompressorType } from './Video';\nimport Audio from './Audio';\nimport Image from './Image';\nimport { getDetails, uuidv4 } from './utils';\n\nexport {\n Video,\n Audio,\n Image,\n //type\n VideoCompressorType,\n getDetails,\n uuidv4,\n};\nexport default {\n Video,\n Audio,\n Image,\n getDetails,\n uuidv4,\n};\n"]}
1
+ {"version":3,"sources":["index.tsx"],"names":["Video","VideoCompressorType","Audio","Image","getDetails","uuidv4","generateFilePath","getRealPath","getVideoMetaData"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,mBAAhB,QAA2C,SAA3C;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,SACEC,UADF,EAEEC,MAFF,EAGEC,gBAHF,EAIEC,WAJF,EAKEC,gBALF,QAMO,SANP;AAQA,SACER,KADF,EAEEE,KAFF,EAGEC,KAHF,CAIE;AAJF,EAKEF,mBALF,EAMEG,UANF,EAOEC,MAPF,EAQEC,gBARF,EASEC,WATF,EAUEC,gBAVF;AAYA,eAAe;AACbR,EAAAA,KADa;AAEbE,EAAAA,KAFa;AAGbC,EAAAA,KAHa;AAIbC,EAAAA,UAJa;AAKbC,EAAAA,MALa;AAMbC,EAAAA,gBANa;AAObC,EAAAA,WAPa;AAQbC,EAAAA;AARa,CAAf","sourcesContent":["import Video, { VideoCompressorType } from './Video';\nimport Audio from './Audio';\nimport Image from './Image';\nimport {\n getDetails,\n uuidv4,\n generateFilePath,\n getRealPath,\n getVideoMetaData,\n} from './utils';\n\nexport {\n Video,\n Audio,\n Image,\n //type\n VideoCompressorType,\n getDetails,\n uuidv4,\n generateFilePath,\n getRealPath,\n getVideoMetaData,\n};\nexport default {\n Video,\n Audio,\n Image,\n getDetails,\n uuidv4,\n generateFilePath,\n getRealPath,\n getVideoMetaData,\n};\n"]}
@@ -12,12 +12,17 @@ export const DEFAULT_COMPRESS_AUDIO_OPTIONS = {
12
12
  quality: 'medium',
13
13
  outputFilePath: ''
14
14
  };
15
-
16
- const generateFile = extension => {
15
+ export const generateFilePath = extension => {
17
16
  return new Promise((resolve, reject) => {
18
- Compressor.generateFile(extension).then(result => resolve('file://' + result)).catch(error => reject(error));
17
+ Compressor.generateFilePath(extension).then(result => resolve('file://' + result)).catch(error => reject(error));
19
18
  });
20
19
  };
20
+ export const getRealPath = (path, type = 'video') => {
21
+ return Compressor.getRealPath(path, type);
22
+ };
23
+ export const getVideoMetaData = path => {
24
+ return Compressor.getVideoMetaData(path);
25
+ };
21
26
 
22
27
  const isValidUrl = url => /^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/.test(url);
23
28
 
@@ -107,7 +112,7 @@ export const checkUrlAndOptions = async (url, options) => {
107
112
  outputFilePath = options.outputFilePath;
108
113
  defaultResult.outputFilePath = outputFilePath;
109
114
  } else {
110
- outputFilePath = await generateFile('mp3');
115
+ outputFilePath = await generateFilePath('mp3');
111
116
  defaultResult.outputFilePath = outputFilePath;
112
117
  }
113
118
 
@@ -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","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,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A,cAAc,KAAK+C,SAAnB,IAAgC/C,cAAc,KAAK,IAAvD,EAA6D;AAC3D4C,MAAAA,aAAa,CAACC,SAAd,GAA0B,KAA1B;AACAD,MAAAA,aAAa,CAACE,OAAd,GAAwBH,OAAO,CAAC3C,cAAR,GACpBL,qBADoB,GAEpBC,wCAFJ;AAGD;AACF,GAhBD,CAgBE,OAAO6C,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;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
+ {"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","generateFilePath","extension","Promise","resolve","reject","then","result","catch","error","getRealPath","path","type","getVideoMetaData","isValidUrl","url","test","getFullFilename","_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,EAAAA,cAAc,EAAE;AAHmD,CAA9D;AAUP,OAAO,MAAMC,gBAAqB,GAAIC,SAAD,IAAuB;AAC1D,SAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;AACtCb,IAAAA,UAAU,CAACS,gBAAX,CAA4BC,SAA5B,EACGI,IADH,CACSC,MAAD,I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wCAFJ;AAGD;AACF,GAhBD,CAgBE,OAAOgD,CAAP,EAAU;AACVG,IAAAA,aAAa,CAACC,SAAd,GAA0B,KAA1B;AACAD,IAAAA,aAAa,CAACE,OAAd,GAAwBH,OAAO,CAAC9C,cAAR,GACpBL,qBADoB,GAEpBC,wCAFJ;AAGD,GArBD,SAqBU;AACR,WAAOmD,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\nexport const generateFilePath: any = (extension: string) => {\n return new Promise((resolve, reject) => {\n Compressor.generateFilePath(extension)\n .then((result: any) => resolve('file://' + result))\n .catch((error: any) => reject(error));\n });\n};\n\nexport const getRealPath: any = (\n path: string,\n type: 'video' | 'imaage' = 'video'\n) => {\n return Compressor.getRealPath(path, type);\n};\n\nexport const getVideoMetaData: any = (path: string) => {\n return Compressor.getVideoMetaData(path);\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 generateFilePath('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"]}
@@ -9,6 +9,7 @@ declare type videoCompresssionType = {
9
9
  maxSize?: number;
10
10
  compressionMethod?: compressionMethod;
11
11
  minimumFileSizeForCompress?: number;
12
+ getCancellationId?: (cancellationId: string) => void;
12
13
  };
13
14
  export declare enum FileSystemSessionType {
14
15
  BACKGROUND = 0,
@@ -33,9 +34,12 @@ export declare type FileSystemUploadOptions = ({
33
34
  };
34
35
  export declare type VideoCompressorType = {
35
36
  compress(fileUrl: string, options?: videoCompresssionType, onProgress?: (progress: number) => void): Promise<string>;
37
+ cancelCompression(cancellationId: string): void;
36
38
  backgroundUpload(url: string, fileUrl: string, options: FileSystemUploadOptions, onProgress?: (writtem: number, total: number) => void): Promise<any>;
37
39
  activateBackgroundTask(onExpired?: (data: any) => void): Promise<any>;
38
40
  deactivateBackgroundTask(): Promise<any>;
39
41
  };
42
+ export declare const backgroundUpload: (url: string, fileUrl: string, options: FileSystemUploadOptions, onProgress?: ((writtem: number, total: number) => void) | undefined) => Promise<any>;
43
+ export declare const cancelCompression: (cancellationId: string) => any;
40
44
  declare const Video: VideoCompressorType;
41
45
  export default Video;
@@ -1,8 +1,8 @@
1
1
  import Video, { VideoCompressorType } from './Video';
2
2
  import Audio from './Audio';
3
3
  import Image from './Image';
4
- import { getDetails, uuidv4 } from './utils';
5
- export { Video, Audio, Image, VideoCompressorType, getDetails, uuidv4, };
4
+ import { getDetails, uuidv4, generateFilePath, getRealPath, getVideoMetaData } from './utils';
5
+ export { Video, Audio, Image, VideoCompressorType, getDetails, uuidv4, generateFilePath, getRealPath, getVideoMetaData, };
6
6
  declare const _default: {
7
7
  Video: VideoCompressorType;
8
8
  Audio: import("./utils").AudioType;
@@ -11,5 +11,8 @@ declare const _default: {
11
11
  };
12
12
  getDetails: (mediaFullPath: string, extesnion?: "mp3" | "mp4") => Promise<any>;
13
13
  uuidv4: () => string;
14
+ generateFilePath: any;
15
+ getRealPath: any;
16
+ getVideoMetaData: any;
14
17
  };
15
18
  export default _default;
@@ -14,6 +14,9 @@ export declare const DEFAULT_COMPRESS_AUDIO_OPTIONS: audioCompresssionType;
14
14
  export declare type AudioType = {
15
15
  compress(value: string, options?: audioCompresssionType): Promise<string>;
16
16
  };
17
+ export declare const generateFilePath: any;
18
+ export declare const getRealPath: any;
19
+ export declare const getVideoMetaData: any;
17
20
  export declare const getDetails: (mediaFullPath: string, extesnion?: 'mp3' | 'mp4') => Promise<any | null>;
18
21
  export declare const checkUrlAndOptions: (url: string, options: audioCompresssionType) => Promise<defaultResultType>;
19
22
  export declare const uuidv4: () => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-compressor",
3
- "version": "0.5.12",
3
+ "version": "0.5.17",
4
4
  "description": "This library compress image, video and audio",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
10
10
  s.license = package["license"]
11
11
  s.authors = package["author"]
12
12
 
13
- s.platforms = { :ios => "10.0" }
13
+ s.platforms = { :ios => "11.0" }
14
14
  s.source = { :git => "https://github.com/Shobbak/react-native-compressor.git", :tag => "#{s.version}" }
15
15
 
16
16
  s.source_files = "ios/**/*.{h,m,mm,swift}"
@@ -59,7 +59,7 @@ const Audio: AudioType = {
59
59
  quality: options.quality,
60
60
  });
61
61
  }
62
- } catch (error) {
62
+ } catch (error: any) {
63
63
  throw error.message;
64
64
  }
65
65
  },
@@ -16,6 +16,7 @@ type videoCompresssionType = {
16
16
  maxSize?: number;
17
17
  compressionMethod?: compressionMethod;
18
18
  minimumFileSizeForCompress?: number;
19
+ getCancellationId?: (cancellationId: string) => void;
19
20
  };
20
21
 
21
22
  export declare enum FileSystemSessionType {
@@ -51,6 +52,7 @@ export type VideoCompressorType = {
51
52
  options?: videoCompresssionType,
52
53
  onProgress?: (progress: number) => void
53
54
  ): Promise<string>;
55
+ cancelCompression(cancellationId: string): void;
54
56
  backgroundUpload(
55
57
  url: string,
56
58
  fileUrl: string,
@@ -67,15 +69,50 @@ const VideoCompressEventEmitter = new NativeEventEmitter(
67
69
 
68
70
  const NativeVideoCompressor = NativeModules.VideoCompressor;
69
71
 
72
+ export const backgroundUpload = async (
73
+ url: string,
74
+ fileUrl: string,
75
+ options: FileSystemUploadOptions,
76
+ onProgress?: (writtem: number, total: number) => void
77
+ ): Promise<any> => {
78
+ const uuid = uuidv4();
79
+ let subscription = null;
80
+ try {
81
+ if (onProgress) {
82
+ subscription = VideoCompressEventEmitter.addListener(
83
+ 'VideoCompressorProgress',
84
+ (event: any) => {
85
+ if (event.uuid === uuid) {
86
+ onProgress(event.data.written, event.data.total);
87
+ }
88
+ }
89
+ );
90
+ }
91
+ if (Platform.OS === 'android' && fileUrl.includes('file://')) {
92
+ fileUrl = fileUrl.replace('file://', '');
93
+ }
94
+ const result = await NativeVideoCompressor.upload(fileUrl, {
95
+ uuid,
96
+ method: options.httpMethod,
97
+ headers: options.headers,
98
+ url,
99
+ });
100
+ return result;
101
+ } finally {
102
+ if (subscription) {
103
+ VideoCompressEventEmitter.removeSubscription(subscription);
104
+ }
105
+ }
106
+ };
107
+
108
+ export const cancelCompression = (cancellationId: string) => {
109
+ return NativeVideoCompressor.cancelCompression(cancellationId);
110
+ };
111
+
70
112
  const Video: VideoCompressorType = {
71
113
  compress: async (
72
114
  fileUrl: string,
73
- options?: {
74
- bitrate?: number;
75
- compressionMethod?: compressionMethod;
76
- maxSize?: number;
77
- minimumFileSizeForCompress?: number;
78
- },
115
+ options?: videoCompresssionType,
79
116
  onProgress?: (progress: number) => void
80
117
  ) => {
81
118
  const uuid = uuidv4();
@@ -109,10 +146,13 @@ const Video: VideoCompressorType = {
109
146
  } else {
110
147
  modifiedOptions.maxSize = 640;
111
148
  }
112
- if (options?.minimumFileSizeForCompress) {
149
+ if (options?.minimumFileSizeForCompress !== undefined) {
113
150
  modifiedOptions.minimumFileSizeForCompress =
114
151
  options?.minimumFileSizeForCompress;
115
152
  }
153
+ if (options?.getCancellationId) {
154
+ options?.getCancellationId(uuid);
155
+ }
116
156
  const result = await NativeVideoCompressor.compress(
117
157
  fileUrl,
118
158
  modifiedOptions
@@ -124,36 +164,8 @@ const Video: VideoCompressorType = {
124
164
  }
125
165
  }
126
166
  },
127
- backgroundUpload: async (url, fileUrl, options, onProgress) => {
128
- const uuid = uuidv4();
129
- let subscription = null;
130
- try {
131
- if (onProgress) {
132
- subscription = VideoCompressEventEmitter.addListener(
133
- 'VideoCompressorProgress',
134
- (event: any) => {
135
- if (event.uuid === uuid) {
136
- onProgress(event.data.written, event.data.total);
137
- }
138
- }
139
- );
140
- }
141
- if (Platform.OS === 'android' && fileUrl.includes('file://')) {
142
- fileUrl = fileUrl.replace('file://', '');
143
- }
144
- const result = await NativeVideoCompressor.upload(fileUrl, {
145
- uuid,
146
- method: options.httpMethod,
147
- headers: options.headers,
148
- url,
149
- });
150
- return result;
151
- } finally {
152
- if (subscription) {
153
- VideoCompressEventEmitter.removeSubscription(subscription);
154
- }
155
- }
156
- },
167
+ backgroundUpload: backgroundUpload,
168
+ cancelCompression,
157
169
  activateBackgroundTask(onExpired?) {
158
170
  if (onExpired) {
159
171
  const subscription = VideoCompressEventEmitter.addListener(
package/src/index.tsx CHANGED
@@ -1,7 +1,13 @@
1
1
  import Video, { VideoCompressorType } from './Video';
2
2
  import Audio from './Audio';
3
3
  import Image from './Image';
4
- import { getDetails, uuidv4 } from './utils';
4
+ import {
5
+ getDetails,
6
+ uuidv4,
7
+ generateFilePath,
8
+ getRealPath,
9
+ getVideoMetaData,
10
+ } from './utils';
5
11
 
6
12
  export {
7
13
  Video,
@@ -11,6 +17,9 @@ export {
11
17
  VideoCompressorType,
12
18
  getDetails,
13
19
  uuidv4,
20
+ generateFilePath,
21
+ getRealPath,
22
+ getVideoMetaData,
14
23
  };
15
24
  export default {
16
25
  Video,
@@ -18,4 +27,7 @@ export default {
18
27
  Image,
19
28
  getDetails,
20
29
  uuidv4,
30
+ generateFilePath,
31
+ getRealPath,
32
+ getVideoMetaData,
21
33
  };
@@ -30,14 +30,25 @@ export type AudioType = {
30
30
  compress(value: string, options?: audioCompresssionType): Promise<string>;
31
31
  };
32
32
 
33
- const generateFile: any = (extension: string) => {
33
+ export const generateFilePath: any = (extension: string) => {
34
34
  return new Promise((resolve, reject) => {
35
- Compressor.generateFile(extension)
35
+ Compressor.generateFilePath(extension)
36
36
  .then((result: any) => resolve('file://' + result))
37
37
  .catch((error: any) => reject(error));
38
38
  });
39
39
  };
40
40
 
41
+ export const getRealPath: any = (
42
+ path: string,
43
+ type: 'video' | 'imaage' = 'video'
44
+ ) => {
45
+ return Compressor.getRealPath(path, type);
46
+ };
47
+
48
+ export const getVideoMetaData: any = (path: string) => {
49
+ return Compressor.getVideoMetaData(path);
50
+ };
51
+
41
52
  const isValidUrl = (url: string) =>
42
53
  /^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/.test(url);
43
54
 
@@ -135,7 +146,7 @@ export const checkUrlAndOptions = async (
135
146
  outputFilePath = options.outputFilePath;
136
147
  defaultResult.outputFilePath = outputFilePath;
137
148
  } else {
138
- outputFilePath = await generateFile('mp3');
149
+ outputFilePath = await generateFilePath('mp3');
139
150
  defaultResult.outputFilePath = outputFilePath;
140
151
  }
141
152
  if (outputFilePath === undefined || outputFilePath === null) {