react-native-compressor 0.5.6-alpha.0 → 0.5.11
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.
- package/README.md +29 -2
- package/android/.gradle/6.9/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/{6.1.1 → 6.9}/fileChanges/last-build.bin +0 -0
- package/android/.gradle/6.9/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/{6.1.1 → 6.9}/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/src/main/java/com/reactnativecompressor/Image/ImageCompressor.java +6 -14
- package/android/src/main/java/com/reactnativecompressor/Video/AutoVideoCompression/AutoVideoCompression.java +3 -2
- package/android/src/main/java/com/reactnativecompressor/Video/VideoCompressorHelper.java +4 -0
- package/app.plugin.js +1 -0
- package/ios/Video/VideoCompressor.swift +9 -9
- package/lib/commonjs/Video/index.js +7 -3
- package/lib/commonjs/Video/index.js.map +1 -1
- package/lib/commonjs/expo-plugin/compressor.js +17 -0
- package/lib/commonjs/expo-plugin/compressor.js.map +1 -0
- package/lib/commonjs/index.js +8 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/index.js +13 -1
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/module/Video/index.js +5 -1
- package/lib/module/Video/index.js.map +1 -1
- package/lib/module/expo-plugin/compressor.js +8 -0
- package/lib/module/expo-plugin/compressor.js.map +1 -0
- package/lib/module/index.js +4 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/index.js +9 -0
- package/lib/module/utils/index.js.map +1 -1
- package/lib/typescript/Video/index.d.ts +2 -0
- package/lib/typescript/expo-plugin/compressor.d.ts +4 -0
- package/lib/typescript/index.d.ts +3 -2
- package/lib/typescript/utils/index.d.ts +1 -0
- package/package.json +4 -4
- package/src/Video/index.tsx +9 -1
- package/src/expo-plugin/compressor.ts +8 -0
- package/src/index.tsx +3 -1
- package/src/utils/index.tsx +17 -0
- package/android/.gradle/6.1.1/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/6.1.1/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/6.1.1/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/6.1.1/fileHashes/fileHashes.lock +0 -0
- 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 -->
|
|
@@ -20,10 +26,12 @@
|
|
|
20
26
|
|
|
21
27
|
## Installation
|
|
22
28
|
|
|
23
|
-
|
|
29
|
+
### React Native
|
|
30
|
+
|
|
31
|
+
#### For React Native<0.65
|
|
24
32
|
|
|
25
33
|
```sh
|
|
26
|
-
yarn add react-native-compressor
|
|
34
|
+
yarn add react-native-compressor@0.5.9
|
|
27
35
|
```
|
|
28
36
|
|
|
29
37
|
Using Npm
|
|
@@ -32,6 +40,21 @@ Using Npm
|
|
|
32
40
|
npm install react-native-compressor --save
|
|
33
41
|
```
|
|
34
42
|
|
|
43
|
+
### Managed Expo
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
expo install react-native-compressor
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Add the Compressor plugin to your Expo config (`app.json`, `app.config.json` or `app.config.js`):
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"name": "my app",
|
|
54
|
+
"plugins": ["react-native-compressor"]
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
35
58
|
### Automatic linking (for React Native >= 0.60 only)
|
|
36
59
|
|
|
37
60
|
Automatic linking is supported for both `Android` and `IOS`
|
|
@@ -204,8 +227,12 @@ const result = await Audio.compress(
|
|
|
204
227
|
The maximum size can be height in case of portrait video or can be width in case of landscape video.
|
|
205
228
|
|
|
206
229
|
- ###### `bitrate: string`
|
|
230
|
+
|
|
207
231
|
bitrate of video which reduce or increase video size. if compressionMethod will auto then this prop will not work
|
|
208
232
|
|
|
233
|
+
- ###### `minimumFileSizeForCompress: number` (default: 16)
|
|
234
|
+
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)
|
|
235
|
+
|
|
209
236
|
## Audio
|
|
210
237
|
|
|
211
238
|
- ###### `compress(url: string, options?: audioCompresssionType): Promise<string>`
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#
|
|
2
|
-
gradle.version=6.
|
|
1
|
+
#Mon Dec 20 15:53:04 PKT 2021
|
|
2
|
+
gradle.version=6.9
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -66,7 +66,7 @@ public class ImageCompressor {
|
|
|
66
66
|
|
|
67
67
|
|
|
68
68
|
|
|
69
|
-
public static String encodeImage(ByteArrayOutputStream imageDataByteArrayOutputStream, Boolean isBase64,
|
|
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,
|
|
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
|
-
|
|
229
|
-
|
|
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>
|
|
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
|
-
|
|
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 /
|
|
247
|
-
remeasuredBitrate = remeasuredBitrate*
|
|
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,13 +7,13 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _utils = require("../utils");
|
|
11
11
|
|
|
12
12
|
const VideoCompressEventEmitter = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.VideoCompressor);
|
|
13
13
|
const NativeVideoCompressor = _reactNative.NativeModules.VideoCompressor;
|
|
14
14
|
const Video = {
|
|
15
15
|
compress: async (fileUrl, options, onProgress) => {
|
|
16
|
-
const uuid = (0,
|
|
16
|
+
const uuid = (0, _utils.uuidv4)();
|
|
17
17
|
let subscription = null;
|
|
18
18
|
|
|
19
19
|
try {
|
|
@@ -42,6 +42,10 @@ const Video = {
|
|
|
42
42
|
modifiedOptions.maxSize = 640;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
if (options !== null && options !== void 0 && options.minimumFileSizeForCompress) {
|
|
46
|
+
modifiedOptions.minimumFileSizeForCompress = options === null || options === void 0 ? void 0 : options.minimumFileSizeForCompress;
|
|
47
|
+
}
|
|
48
|
+
|
|
45
49
|
const result = await NativeVideoCompressor.compress(fileUrl, modifiedOptions);
|
|
46
50
|
return result;
|
|
47
51
|
} finally {
|
|
@@ -51,7 +55,7 @@ const Video = {
|
|
|
51
55
|
}
|
|
52
56
|
},
|
|
53
57
|
backgroundUpload: async (url, fileUrl, options, onProgress) => {
|
|
54
|
-
const uuid = (0,
|
|
58
|
+
const uuid = (0, _utils.uuidv4)();
|
|
55
59
|
let subscription = null;
|
|
56
60
|
|
|
57
61
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["VideoCompressEventEmitter","NativeEventEmitter","NativeModules","VideoCompressor","NativeVideoCompressor","Video","compress","fileUrl","options","onProgress","uuid","subscription","addListener","event","data","progress","modifiedOptions","bitrate","compressionMethod","maxSize","result","removeSubscription","backgroundUpload","url","written","total","Platform","OS","includes","replace","upload","method","httpMethod","headers","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners"],"mappings":";;;;;;;AAAA;;AACA;;
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["VideoCompressEventEmitter","NativeEventEmitter","NativeModules","VideoCompressor","NativeVideoCompressor","Video","compress","fileUrl","options","onProgress","uuid","subscription","addListener","event","data","progress","modifiedOptions","bitrate","compressionMethod","maxSize","minimumFileSizeForCompress","result","removeSubscription","backgroundUpload","url","written","total","Platform","OS","includes","replace","upload","method","httpMethod","headers","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners"],"mappings":";;;;;;;AAAA;;AACA;;AA8DA,MAAMA,yBAAyB,GAAG,IAAIC,+BAAJ,CAChCC,2BAAcC,eADkB,CAAlC;AAIA,MAAMC,qBAAqB,GAAGF,2BAAcC,eAA5C;AAEA,MAAME,KAA0B,GAAG;AACjCC,EAAAA,QAAQ,EAAE,OACRC,OADQ,EAERC,OAFQ,EAQRC,UARQ,KASL;AACH,UAAMC,IAAI,GAAG,oBAAb;AACA,QAAIC,YAAY,GAAG,IAAnB;;AACA,QAAI;AACF,UAAIF,UAAJ,EAAgB;AACdE,QAAAA,YAAY,GAAGX,yBAAyB,CAACY,WAA1B,CACb,uBADa,EAEZC,KAAD,IAAgB;AACd,cAAIA,KAAK,CAACH,IAAN,KAAeA,IAAnB,EAAyB;AACvBD,YAAAA,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C+B,sBAAtB,CAA6C,EAA7C,CAAP;AACD,GAlGgC;;AAmGjCE,EAAAA,wBAAwB,GAAG;AACzBrC,IAAAA,yBAAyB,CAACsC,kBAA1B,CAA6C,uBAA7C;AACA,WAAOlC,qBAAqB,CAACiC,wBAAtB,CAA+C,EAA/C,CAAP;AACD;;AAtGgC,CAAnC;eAyGehC,K","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"]}
|
|
@@ -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"]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -33,6 +33,12 @@ Object.defineProperty(exports, "getDetails", {
|
|
|
33
33
|
return _utils.getDetails;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
+
Object.defineProperty(exports, "uuidv4", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _utils.uuidv4;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
36
42
|
exports.default = void 0;
|
|
37
43
|
|
|
38
44
|
var _Video = _interopRequireWildcard(require("./Video"));
|
|
@@ -53,7 +59,8 @@ var _default = {
|
|
|
53
59
|
Video: _Video.default,
|
|
54
60
|
Audio: _Audio.default,
|
|
55
61
|
Image: _Image.default,
|
|
56
|
-
getDetails: _utils.getDetails
|
|
62
|
+
getDetails: _utils.getDetails,
|
|
63
|
+
uuidv4: _utils.uuidv4
|
|
57
64
|
};
|
|
58
65
|
exports.default = _default;
|
|
59
66
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["Video","Audio","Image","getDetails"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["Video","Audio","Image","getDetails","uuidv4"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;;;eAWe;AACbA,EAAAA,KAAK,EAALA,cADa;AAEbC,EAAAA,KAAK,EAALA,cAFa;AAGbC,EAAAA,KAAK,EAALA,cAHa;AAIbC,EAAAA,UAAU,EAAVA,iBAJa;AAKbC,EAAAA,MAAM,EAANA;AALa,C","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"]}
|
|
@@ -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,EAAUC,MAAV,KAAqB;AACtCd,IAAAA,UAAU,CAACU,YAAX,CAAwBC,SAAxB,EACGI,IADH,CACSC,MAAD,IAAiBH,OAAO,CAAC,YAAYG,MAAb,CADhC,EAEGC,KAFH,CAEUC,KAAD,IAAgBJ,MAAM,CAACI,KAAD,CAF/B;AAGD,GAJM,CAAP;AAKD,CAND;;AAQA,MAAMC,UAAU,GAAIC,GAAD,IACjB,wDAAwDC,IAAxD,CAA6DD,GAA7D,CADF;;AAGA,MAAME,eAAe,GAAIC,IAAD,IAAyB;AAC/C,MAAI,OAAOA,IAAP,KAAgB,QAApB,EAA8B;AAC5B,QAAIC,KAAK,GAAGD,IAAZ,CAD4B,CAG5B;;AACA,QAAIA,IAAI,CAACE,QAAL,CAAc,MAAd,KAAyB,CAACN,UAAU,CAACI,IAAD,CAAxC,EAAgD;AAC9C,aAAOpB,oBAAP;AACD,KAN2B,CAQ5B;;;AACA,QAAIqB,KAAK,CAACA,KAAK,CAACE,MAA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,MAAAA,cAAc,GAAG2C,OAAO,CAAC3C,cAAzB;AACA4C,MAAAA,aAAa,CAAC5C,cAAd,GAA+BA,cAA/B;AACD,KAHD,MAGO;AACLA,MAAAA,cAAc,GAAG,MAAMC,YAAY,CAAC,KAAD,CAAnC;AACA2C,MAAAA,aAAa,CAAC5C,cAAd,GAA+BA,cAA/B;AACD;;AACD,QAAIA,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","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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AAAA,aAAa,CAAC5C,cAAd,GAA+BA,cAA/B;AACD,KAHD,MAGO;AACLA,MAAAA,cAAc,GAAG,MAAMC,YAAY,CAAC,KAAD,CAAnC;AACA2C,MAAAA,aAAa,CAAC5C,cAAd,GAA+BA,cAA/B;AACD;;AACD,QAAIA,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;;;;AA2CA,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,5 +1,5 @@
|
|
|
1
1
|
import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
|
|
2
|
-
import {
|
|
2
|
+
import { uuidv4 } from '../utils';
|
|
3
3
|
const VideoCompressEventEmitter = new NativeEventEmitter(NativeModules.VideoCompressor);
|
|
4
4
|
const NativeVideoCompressor = NativeModules.VideoCompressor;
|
|
5
5
|
const Video = {
|
|
@@ -33,6 +33,10 @@ const Video = {
|
|
|
33
33
|
modifiedOptions.maxSize = 640;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
if (options !== null && options !== void 0 && options.minimumFileSizeForCompress) {
|
|
37
|
+
modifiedOptions.minimumFileSizeForCompress = options === null || options === void 0 ? void 0 : options.minimumFileSizeForCompress;
|
|
38
|
+
}
|
|
39
|
+
|
|
36
40
|
const result = await NativeVideoCompressor.compress(fileUrl, modifiedOptions);
|
|
37
41
|
return result;
|
|
38
42
|
} finally {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["NativeModules","NativeEventEmitter","Platform","
|
|
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"],"mapp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ACzDG,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"]}
|
|
@@ -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"]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import Video, { VideoCompressorType } 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 //type
|
|
6
|
-
, VideoCompressorType, getDetails };
|
|
6
|
+
, VideoCompressorType, getDetails, uuidv4 };
|
|
7
7
|
export default {
|
|
8
8
|
Video,
|
|
9
9
|
Audio,
|
|
10
10
|
Image,
|
|
11
|
-
getDetails
|
|
11
|
+
getDetails,
|
|
12
|
+
uuidv4
|
|
12
13
|
};
|
|
13
14
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["Video","VideoCompressorType","Audio","Image","getDetails"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,mBAAhB,QAA2C,SAA3C;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,SAASC,UAAT,
|
|
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,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,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;AACtCb,IAAAA,UAAU,CAACS,YAAX,CAAwBC,SAAxB,EACGI,IADH,CACSC,MAAD,IAAiBH,OAAO,CAAC,YAAYG,MAAb,CADhC,EAEGC,KAFH,CAEUC,KAAD,IAAgBJ,MAAM,CAACI,KAAD,CAF/B;AAGD,GAJM,CAAP;AAKD,CAND;;AAQA,MAAMC,UAAU,GAAIC,GAAD,IACjB,wDAAwDC,IAAxD,CAA6DD,GAA7D,CADF;;AAGA,MAAME,eAAe,GAAIC,IAAD,IAAyB;AAC/C,MAAI,OAA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iEADI,CAAN;AAGD;;AACD,QAAMa,aAAgC,GAAG;AACvC5C,IAAAA,cAAc,EAAE,EADuB;AAEvC6C,IAAAA,SAAS,EAAE,IAF4B;AAGvCC,IAAAA,OAAO,EAAE;AAH8B,GAAzC,CAN+B,CAY/B;;AACA,MAAI9C,cAAJ;;AACA,MAAI;AACF;AACA;AACA,QAAI2C,OAAO,CAAC3C,cAAZ,EAA4B;AAC1BA,MAAAA,cAAc,GAAG2C,OAAO,CAAC3C,cAAzB;AACA4C,MAAAA,aAAa,CAAC5C,cAAd,GAA+BA,cAA/B;AACD,KAHD,MAGO;AACLA,MAAAA,cAAc,GAAG,MAAMC,YAAY,CAAC,KAAD,CAAnC;AACA2C,MAAAA,aAAa,CAAC5C,cAAd,GAA+BA,cAA/B;AACD;;AACD,QAAIA,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","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,EAAAA,cAAc,EAAE;AAHmD,CAA9D;;AAUP,MAAMC,YAAiB,GAAIC,SAAD,IAAuB;AAC/C,SAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;AACtCb,IAAAA,UAAU,CAACS,YAAX,CAAwBC,SAAxB,EACGI,IADH,CACSC,MAAD,IAAiBH,OAAO,CAAC,YAAYG,MAAb,CADhC,EAEGC,KAFH,CAEUC,KAAD,IAAgBJ,MAAM,CAACI,KAAD,CAF/B;AAGD,GAJM,CAAP;AAKD,CAND;;AAQA,MAAMC,UAAU,GAAIC,GAAD,IACjB,wDAAwDC,IAAxD,CAA6DD,GAA7D,CADF;;AAGA,MAAME,eAAe,GAAIC,IAAD,IAAyB;AAC/C,MAAI,OAAOA,IAAP,KAAgB,QA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E;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"]}
|
|
@@ -6,7 +6,9 @@ export declare type FileSystemAcceptedUploadHttpMethod = 'POST' | 'PUT' | 'PATCH
|
|
|
6
6
|
export declare type compressionMethod = 'auto' | 'manual';
|
|
7
7
|
declare type videoCompresssionType = {
|
|
8
8
|
bitrate?: number;
|
|
9
|
+
maxSize?: number;
|
|
9
10
|
compressionMethod?: compressionMethod;
|
|
11
|
+
minimumFileSizeForCompress?: number;
|
|
10
12
|
};
|
|
11
13
|
export declare enum FileSystemSessionType {
|
|
12
14
|
BACKGROUND = 0,
|
|
@@ -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 } from './utils';
|
|
5
|
-
export { Video, Audio, Image, VideoCompressorType, getDetails, };
|
|
4
|
+
import { getDetails, uuidv4 } from './utils';
|
|
5
|
+
export { Video, Audio, Image, VideoCompressorType, getDetails, uuidv4, };
|
|
6
6
|
declare const _default: {
|
|
7
7
|
Video: VideoCompressorType;
|
|
8
8
|
Audio: import("./utils").AudioType;
|
|
@@ -10,5 +10,6 @@ declare const _default: {
|
|
|
10
10
|
compress(value: string, options?: import("./Image").CompressorOptions | undefined): Promise<string>;
|
|
11
11
|
};
|
|
12
12
|
getDetails: (mediaFullPath: string, extesnion?: "mp3" | "mp4") => Promise<any>;
|
|
13
|
+
uuidv4: () => string;
|
|
13
14
|
};
|
|
14
15
|
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": "0.5.
|
|
3
|
+
"version": "0.5.11",
|
|
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",
|
package/src/Video/index.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
|
|
2
|
-
import {
|
|
2
|
+
import { uuidv4 } from '../utils';
|
|
3
3
|
|
|
4
4
|
export declare enum FileSystemUploadType {
|
|
5
5
|
BINARY_CONTENT = 0,
|
|
@@ -13,7 +13,9 @@ export declare type FileSystemAcceptedUploadHttpMethod =
|
|
|
13
13
|
export type compressionMethod = 'auto' | 'manual';
|
|
14
14
|
type videoCompresssionType = {
|
|
15
15
|
bitrate?: number;
|
|
16
|
+
maxSize?: number;
|
|
16
17
|
compressionMethod?: compressionMethod;
|
|
18
|
+
minimumFileSizeForCompress?: number;
|
|
17
19
|
};
|
|
18
20
|
|
|
19
21
|
export declare enum FileSystemSessionType {
|
|
@@ -72,6 +74,7 @@ const Video: VideoCompressorType = {
|
|
|
72
74
|
bitrate?: number;
|
|
73
75
|
compressionMethod?: compressionMethod;
|
|
74
76
|
maxSize?: number;
|
|
77
|
+
minimumFileSizeForCompress?: number;
|
|
75
78
|
},
|
|
76
79
|
onProgress?: (progress: number) => void
|
|
77
80
|
) => {
|
|
@@ -93,6 +96,7 @@ const Video: VideoCompressorType = {
|
|
|
93
96
|
bitrate?: number;
|
|
94
97
|
compressionMethod?: compressionMethod;
|
|
95
98
|
maxSize?: number;
|
|
99
|
+
minimumFileSizeForCompress?: number;
|
|
96
100
|
} = { uuid };
|
|
97
101
|
if (options?.bitrate) modifiedOptions.bitrate = options?.bitrate;
|
|
98
102
|
if (options?.compressionMethod) {
|
|
@@ -105,6 +109,10 @@ const Video: VideoCompressorType = {
|
|
|
105
109
|
} else {
|
|
106
110
|
modifiedOptions.maxSize = 640;
|
|
107
111
|
}
|
|
112
|
+
if (options?.minimumFileSizeForCompress) {
|
|
113
|
+
modifiedOptions.minimumFileSizeForCompress =
|
|
114
|
+
options?.minimumFileSizeForCompress;
|
|
115
|
+
}
|
|
108
116
|
const result = await NativeVideoCompressor.compress(
|
|
109
117
|
fileUrl,
|
|
110
118
|
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 } 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,
|
|
@@ -10,10 +10,12 @@ export {
|
|
|
10
10
|
//type
|
|
11
11
|
VideoCompressorType,
|
|
12
12
|
getDetails,
|
|
13
|
+
uuidv4,
|
|
13
14
|
};
|
|
14
15
|
export default {
|
|
15
16
|
Video,
|
|
16
17
|
Audio,
|
|
17
18
|
Image,
|
|
18
19
|
getDetails,
|
|
20
|
+
uuidv4,
|
|
19
21
|
};
|
package/src/utils/index.tsx
CHANGED
|
@@ -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
|
+
};
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|