react-native-compressor 1.0.2 → 1.2.0
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 +72 -2
- 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 +8 -8
- package/lib/commonjs/Video/index.js +6 -0
- 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/module/Video/index.js +5 -0
- 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/typescript/Video/index.d.ts +3 -0
- package/lib/typescript/expo-plugin/compressor.d.ts +4 -0
- package/package.json +6 -1
- package/src/Video/index.tsx +9 -0
- package/src/expo-plugin/compressor.ts +8 -0
package/README.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
### Would you like to support me?
|
|
2
|
+
|
|
3
|
+
<a href="https://www.buymeacoffee.com/numan.dev" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
1
7
|
# react-native-compressor
|
|
2
8
|
|
|
3
9
|
<!-- Title -->
|
|
@@ -18,12 +24,16 @@
|
|
|
18
24
|
|
|
19
25
|
**react-native-compressor** package is a set of functions that allow you compress `Image`,`Audio` and `Video`
|
|
20
26
|
|
|
27
|
+
If you find this package useful hit the star 🌟
|
|
28
|
+
|
|
21
29
|
## Installation
|
|
22
30
|
|
|
23
|
-
|
|
31
|
+
### React Native
|
|
32
|
+
|
|
33
|
+
#### For React Native<0.65
|
|
24
34
|
|
|
25
35
|
```sh
|
|
26
|
-
yarn add react-native-compressor@0.5.
|
|
36
|
+
yarn add react-native-compressor@0.5.9
|
|
27
37
|
```
|
|
28
38
|
|
|
29
39
|
#### For React Native 0.65 or greater
|
|
@@ -32,6 +42,21 @@ yarn add react-native-compressor@0.5.6
|
|
|
32
42
|
yarn add react-native-compressor
|
|
33
43
|
```
|
|
34
44
|
|
|
45
|
+
### Managed Expo
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
expo install react-native-compressor
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Add the Compressor plugin to your Expo config (`app.json`, `app.config.json` or `app.config.js`):
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"name": "my app",
|
|
56
|
+
"plugins": ["react-native-compressor"]
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
35
60
|
### Automatic linking (for React Native >= 0.60 only)
|
|
36
61
|
|
|
37
62
|
Automatic linking is supported for both `Android` and `IOS`
|
|
@@ -150,6 +175,23 @@ const result = await Audio.compress(
|
|
|
150
175
|
);
|
|
151
176
|
```
|
|
152
177
|
|
|
178
|
+
### Background Upload
|
|
179
|
+
|
|
180
|
+
```js
|
|
181
|
+
import { backgroundUpload } from 'react-native-compressor';
|
|
182
|
+
|
|
183
|
+
const headers = {};
|
|
184
|
+
|
|
185
|
+
const uploadResult = await backgroundUpload(
|
|
186
|
+
url,
|
|
187
|
+
fileUrl,
|
|
188
|
+
{ httpMethod: 'PUT', headers },
|
|
189
|
+
(written, total) => {
|
|
190
|
+
console.log(written, total);
|
|
191
|
+
}
|
|
192
|
+
);
|
|
193
|
+
```
|
|
194
|
+
|
|
153
195
|
# API
|
|
154
196
|
|
|
155
197
|
## Image
|
|
@@ -204,8 +246,12 @@ const result = await Audio.compress(
|
|
|
204
246
|
The maximum size can be height in case of portrait video or can be width in case of landscape video.
|
|
205
247
|
|
|
206
248
|
- ###### `bitrate: string`
|
|
249
|
+
|
|
207
250
|
bitrate of video which reduce or increase video size. if compressionMethod will auto then this prop will not work
|
|
208
251
|
|
|
252
|
+
- ###### `minimumFileSizeForCompress: number` (default: 16)
|
|
253
|
+
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)
|
|
254
|
+
|
|
209
255
|
## Audio
|
|
210
256
|
|
|
211
257
|
- ###### `compress(url: string, options?: audioCompresssionType): Promise<string>`
|
|
@@ -217,6 +263,30 @@ const result = await Audio.compress(
|
|
|
217
263
|
|
|
218
264
|
**Note: Audio compression will be add soon**
|
|
219
265
|
|
|
266
|
+
## Background Upload
|
|
267
|
+
|
|
268
|
+
- ###### `backgroundUpload: (url: string, fileUrl: string, options: FileSystemUploadOptions, onProgress?: ((writtem: number, total: number) => void) | undefined) => Promise<any>
|
|
269
|
+
|
|
270
|
+
- ###### ` FileSystemUploadOptions`
|
|
271
|
+
|
|
272
|
+
```js
|
|
273
|
+
type FileSystemUploadOptions = (
|
|
274
|
+
| {
|
|
275
|
+
uploadType?: FileSystemUploadType.BINARY_CONTENT,
|
|
276
|
+
}
|
|
277
|
+
| {
|
|
278
|
+
uploadType: FileSystemUploadType.MULTIPART,
|
|
279
|
+
fieldName?: string,
|
|
280
|
+
mimeType?: string,
|
|
281
|
+
parameters?: Record<string, string>,
|
|
282
|
+
}
|
|
283
|
+
) & {
|
|
284
|
+
headers?: Record<string, string>,
|
|
285
|
+
httpMethod?: FileSystemAcceptedUploadHttpMethod,
|
|
286
|
+
sessionType?: FileSystemSessionType,
|
|
287
|
+
};
|
|
288
|
+
```
|
|
289
|
+
|
|
220
290
|
## Contributing
|
|
221
291
|
|
|
222
292
|
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
|
@@ -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,8 +245,8 @@ 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 /
|
|
248
|
+
let minValue:Float=min(Float(originalHeight)/Float(height),Float(originalWidth)/Float(width))
|
|
249
|
+
var remeasuredBitrate:Int = Int(Float(originalBitrate) / minValue)
|
|
247
250
|
remeasuredBitrate = remeasuredBitrate*Int(compressFactor)
|
|
248
251
|
let minBitrate:Int = self.getVideoBitrateWithFactor(f: minCompressFactor) / (1280 * 720 / (width * height))
|
|
249
252
|
if (originalBitrate < minBitrate) {
|
|
@@ -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,6 +7,8 @@ exports.default = exports.backgroundUpload = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
|
|
10
|
+
require("react-native-get-random-values");
|
|
11
|
+
|
|
10
12
|
var _uuid = require("uuid");
|
|
11
13
|
|
|
12
14
|
const VideoCompressEventEmitter = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.VideoCompressor);
|
|
@@ -76,6 +78,10 @@ const Video = {
|
|
|
76
78
|
modifiedOptions.maxSize = 640;
|
|
77
79
|
}
|
|
78
80
|
|
|
81
|
+
if (options !== null && options !== void 0 && options.minimumFileSizeForCompress) {
|
|
82
|
+
modifiedOptions.minimumFileSizeForCompress = options === null || options === void 0 ? void 0 : options.minimumFileSizeForCompress;
|
|
83
|
+
}
|
|
84
|
+
|
|
79
85
|
const result = await NativeVideoCompressor.compress(fileUrl, modifiedOptions);
|
|
80
86
|
return result;
|
|
81
87
|
} finally {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["VideoCompressEventEmitter","NativeEventEmitter","NativeModules","VideoCompressor","NativeVideoCompressor","backgroundUpload","url","fileUrl","options","onProgress","uuid","subscription","addListener","event","data","written","total","Platform","OS","includes","replace","result","upload","method","httpMethod","headers","remove","Video","compress","progress","modifiedOptions","bitrate","compressionMethod","maxSize","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners"],"mappings":";;;;;;;AAAA;;AAMA;;
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["VideoCompressEventEmitter","NativeEventEmitter","NativeModules","VideoCompressor","NativeVideoCompressor","backgroundUpload","url","fileUrl","options","onProgress","uuid","subscription","addListener","event","data","written","total","Platform","OS","includes","replace","result","upload","method","httpMethod","headers","remove","Video","compress","progress","modifiedOptions","bitrate","compressionMethod","maxSize","minimumFileSizeForCompress","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners"],"mappings":";;;;;;;AAAA;;AAMA;;AACA;;AA8DA,MAAMA,yBAAyB,GAAG,IAAIC,+BAAJ,CAChCC,2BAAcC,eADkB,CAAlC;AAIA,MAAMC,qBAAqB,GAAGF,2BAAcC,eAA5C;;AAEO,MAAME,gBAAgB,GAAG,OAC9BC,GAD8B,EAE9BC,OAF8B,EAG9BC,OAH8B,EAI9BC,UAJ8B,KAKb;AACjB,QAAMC,IAAI,GAAG,eAAb;AACA,MAAIC,YAAJ;;AACA,MAAI;AACF,QAAIF,UAAJ,EAAgB;AACdE,MAAAA,YAAY,GAAGX,yBAAyB,CAACY,WAA1B,CACb,yBADa,EAEZC,KAAD,IAAgB;AACd,YAAIA,KAAK,CAACH,IAAN,KAAeA,IAAnB,EAAyB;AACvBD,UAAAA,UAAU,CAACI,KAAK,CAACC,IAAN,CAAWC,OAAZ,EAAqBF,KAAK,CAACC,IAAN,CAAWE,KAAhC,CAAV;AACD;AACF,OANY,CAAf;AAQD;;AACD,QAAIC,sBAASC,EAAT,KAAgB,SAAh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,qBAAqB,CAACiC,wBAAtB,CAA+C,EAA/C,CAAP;AACD;;AA7EgC,CAAnC;eAgFeV,K","sourcesContent":["import {\n NativeModules,\n NativeEventEmitter,\n Platform,\n NativeEventSubscription,\n} from 'react-native';\nimport 'react-native-get-random-values';\nimport { v4 as uuidv4 } from 'uuid';\n\nexport declare enum FileSystemUploadType {\n BINARY_CONTENT = 0,\n MULTIPART = 1,\n}\n\nexport declare type FileSystemAcceptedUploadHttpMethod =\n | 'POST'\n | 'PUT'\n | 'PATCH';\nexport type compressionMethod = 'auto' | 'manual';\ntype videoCompresssionType = {\n bitrate?: number;\n maxSize?: number;\n compressionMethod?: compressionMethod;\n minimumFileSizeForCompress?: number;\n};\n\nexport declare enum FileSystemSessionType {\n BACKGROUND = 0,\n FOREGROUND = 1,\n}\n\nexport declare type HTTPResponse = {\n status: number;\n headers: Record<string, string>;\n body: string;\n};\n\nexport declare type FileSystemUploadOptions = (\n | {\n uploadType?: FileSystemUploadType.BINARY_CONTENT;\n }\n | {\n uploadType: FileSystemUploadType.MULTIPART;\n fieldName?: string;\n mimeType?: string;\n parameters?: Record<string, string>;\n }\n) & {\n headers?: Record<string, string>;\n httpMethod?: FileSystemAcceptedUploadHttpMethod;\n sessionType?: FileSystemSessionType;\n};\n\nexport type VideoCompressorType = {\n compress(\n fileUrl: string,\n options?: videoCompresssionType,\n onProgress?: (progress: number) => void\n ): Promise<string>;\n backgroundUpload(\n url: string,\n fileUrl: string,\n options: FileSystemUploadOptions,\n onProgress?: (writtem: number, total: number) => void\n ): Promise<any>;\n activateBackgroundTask(onExpired?: (data: any) => void): Promise<any>;\n deactivateBackgroundTask(): Promise<any>;\n};\n\nconst VideoCompressEventEmitter = new NativeEventEmitter(\n NativeModules.VideoCompressor\n);\n\nconst NativeVideoCompressor = NativeModules.VideoCompressor;\n\nexport const backgroundUpload = async (\n url: string,\n fileUrl: string,\n options: FileSystemUploadOptions,\n onProgress?: (writtem: number, total: number) => void\n): Promise<any> => {\n const uuid = uuidv4();\n let subscription: NativeEventSubscription;\n try {\n if (onProgress) {\n subscription = VideoCompressEventEmitter.addListener(\n 'VideoCompressorProgress',\n (event: any) => {\n if (event.uuid === uuid) {\n onProgress(event.data.written, event.data.total);\n }\n }\n );\n }\n if (Platform.OS === 'android' && fileUrl.includes('file://')) {\n fileUrl = fileUrl.replace('file://', '');\n }\n const result = await NativeVideoCompressor.upload(fileUrl, {\n uuid,\n method: options.httpMethod,\n headers: options.headers,\n url,\n });\n return result;\n } finally {\n // @ts-ignore\n if (subscription) {\n subscription.remove();\n }\n }\n};\n\nconst Video: VideoCompressorType = {\n compress: async (\n fileUrl: string,\n options?: {\n bitrate?: number;\n compressionMethod?: compressionMethod;\n maxSize?: number;\n minimumFileSizeForCompress?: number;\n },\n onProgress?: (progress: number) => void\n ) => {\n const uuid = uuidv4();\n let subscription: NativeEventSubscription;\n try {\n if (onProgress) {\n subscription = VideoCompressEventEmitter.addListener(\n 'videoCompressProgress',\n (event: any) => {\n if (event.uuid === uuid) {\n onProgress(event.data.progress);\n }\n }\n );\n }\n const modifiedOptions: {\n uuid: string;\n bitrate?: number;\n compressionMethod?: compressionMethod;\n maxSize?: number;\n minimumFileSizeForCompress?: number;\n } = { uuid };\n if (options?.bitrate) modifiedOptions.bitrate = options?.bitrate;\n if (options?.compressionMethod) {\n modifiedOptions.compressionMethod = options?.compressionMethod;\n } else {\n modifiedOptions.compressionMethod = 'manual';\n }\n if (options?.maxSize) {\n modifiedOptions.maxSize = options?.maxSize;\n } else {\n modifiedOptions.maxSize = 640;\n }\n if (options?.minimumFileSizeForCompress) {\n modifiedOptions.minimumFileSizeForCompress =\n options?.minimumFileSizeForCompress;\n }\n const result = await NativeVideoCompressor.compress(\n fileUrl,\n modifiedOptions\n );\n return result;\n } finally {\n // @ts-ignore\n if (subscription) {\n subscription.remove();\n }\n }\n },\n backgroundUpload,\n activateBackgroundTask(onExpired?) {\n if (onExpired) {\n const subscription: NativeEventSubscription =\n VideoCompressEventEmitter.addListener(\n 'backgroundTaskExpired',\n (event: any) => {\n onExpired(event);\n if (subscription) {\n subscription.remove();\n }\n }\n );\n }\n return NativeVideoCompressor.activateBackgroundTask({});\n },\n deactivateBackgroundTask() {\n VideoCompressEventEmitter.removeAllListeners('backgroundTaskExpired');\n return NativeVideoCompressor.deactivateBackgroundTask({});\n },\n} as VideoCompressorType;\n\nexport default Video;\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _configPlugins = require("@expo/config-plugins");
|
|
9
|
+
|
|
10
|
+
const pkg = require('../../../package.json');
|
|
11
|
+
|
|
12
|
+
const withCompressor = config => config;
|
|
13
|
+
|
|
14
|
+
var _default = (0, _configPlugins.createRunOncePlugin)(withCompressor, pkg.name, pkg.version);
|
|
15
|
+
|
|
16
|
+
exports.default = _default;
|
|
17
|
+
//# sourceMappingURL=compressor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["compressor.ts"],"names":["pkg","require","withCompressor","config","name","version"],"mappings":";;;;;;;AAAA;;AACA,MAAMA,GAAG,GAAGC,OAAO,CAAC,uBAAD,CAAnB;;AAIA,MAAMC,cAAmC,GAAIC,MAAD,IAAYA,MAAxD;;eAEe,wCAAoBD,cAApB,EAAoCF,GAAG,CAACI,IAAxC,EAA8CJ,GAAG,CAACK,OAAlD,C","sourcesContent":["import { ConfigPlugin, createRunOncePlugin } from '@expo/config-plugins';\nconst pkg = require('../../../package.json');\n\ntype Props = {};\n\nconst withCompressor: ConfigPlugin<Props> = (config) => config;\n\nexport default createRunOncePlugin(withCompressor, pkg.name, pkg.version);\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
|
|
2
|
+
import 'react-native-get-random-values';
|
|
2
3
|
import { v4 as uuidv4 } from 'uuid';
|
|
3
4
|
const VideoCompressEventEmitter = new NativeEventEmitter(NativeModules.VideoCompressor);
|
|
4
5
|
const NativeVideoCompressor = NativeModules.VideoCompressor;
|
|
@@ -64,6 +65,10 @@ const Video = {
|
|
|
64
65
|
modifiedOptions.maxSize = 640;
|
|
65
66
|
}
|
|
66
67
|
|
|
68
|
+
if (options !== null && options !== void 0 && options.minimumFileSizeForCompress) {
|
|
69
|
+
modifiedOptions.minimumFileSizeForCompress = options === null || options === void 0 ? void 0 : options.minimumFileSizeForCompress;
|
|
70
|
+
}
|
|
71
|
+
|
|
67
72
|
const result = await NativeVideoCompressor.compress(fileUrl, modifiedOptions);
|
|
68
73
|
return result;
|
|
69
74
|
} finally {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["NativeModules","NativeEventEmitter","Platform","v4","uuidv4","VideoCompressEventEmitter","VideoCompressor","NativeVideoCompressor","backgroundUpload","url","fileUrl","options","onProgress","uuid","subscription","addListener","event","data","written","total","OS","includes","replace","result","upload","method","httpMethod","headers","remove","Video","compress","progress","modifiedOptions","bitrate","compressionMethod","maxSize","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners"],"mappings":"AAAA,SACEA,aADF,EAEEC,kBAFF,EAGEC,QAHF,QAKO,cALP;AAMA,SAASC,EAAE,IAAIC,MAAf,QAA6B,MAA7B;
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["NativeModules","NativeEventEmitter","Platform","v4","uuidv4","VideoCompressEventEmitter","VideoCompressor","NativeVideoCompressor","backgroundUpload","url","fileUrl","options","onProgress","uuid","subscription","addListener","event","data","written","total","OS","includes","replace","result","upload","method","httpMethod","headers","remove","Video","compress","progress","modifiedOptions","bitrate","compressionMethod","maxSize","minimumFileSizeForCompress","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners"],"mappings":"AAAA,SACEA,aADF,EAEEC,kBAFF,EAGEC,Q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,CAAEyB,0BADX;AAED;;AACD,YAAMb,MAAM,GAAG,MAAMhB,qBAAqB,CAACuB,QAAtB,CACnBpB,OADmB,EAEnBsB,eAFmB,CAArB;AAIA,aAAOT,MAAP;AACD,KAtCD,SAsCU;AACR;AACA,UAAIT,YAAJ,EAAkB;AAChBA,QAAAA,YAAY,CAACc,MAAb;AACD;AACF;AACF,GAzDgC;AA0DjCpB,EAAAA,gBA1DiC;;AA2DjC6B,EAAAA,sBAAsB,CAACC,SAAD,EAAa;AACjC,QAAIA,SAAJ,EAAe;AACb,YAAMxB,YAAqC,GACzCT,yBAAyB,CAACU,WAA1B,CACE,uBADF,EAEGC,KAAD,IAAgB;AACdsB,QAAAA,SAAS,CAACtB,KAAD,CAAT;;AACA,YAAIF,YAAJ,EAAkB;AAChBA,UAAAA,YAAY,CAACc,MAAb;AACD;AACF,OAPH,CADF;AAUD;;AACD,WAAOrB,qBAAqB,CAAC8B,sBAAtB,CAA6C,EAA7C,CAAP;AACD,GAzEgC;;AA0EjCE,EAAAA,wBAAwB,GAAG;AACzBlC,IAAAA,yBAAyB,CAACmC,kBAA1B,CAA6C,uBAA7C;AACA,WAAOjC,qBAAqB,CAACgC,wBAAtB,CAA+C,EAA/C,CAAP;AACD;;AA7EgC,CAAnC;AAgFA,eAAeV,KAAf","sourcesContent":["import {\n NativeModules,\n NativeEventEmitter,\n Platform,\n NativeEventSubscription,\n} from 'react-native';\nimport 'react-native-get-random-values';\nimport { v4 as uuidv4 } from 'uuid';\n\nexport declare enum FileSystemUploadType {\n BINARY_CONTENT = 0,\n MULTIPART = 1,\n}\n\nexport declare type FileSystemAcceptedUploadHttpMethod =\n | 'POST'\n | 'PUT'\n | 'PATCH';\nexport type compressionMethod = 'auto' | 'manual';\ntype videoCompresssionType = {\n bitrate?: number;\n maxSize?: number;\n compressionMethod?: compressionMethod;\n minimumFileSizeForCompress?: number;\n};\n\nexport declare enum FileSystemSessionType {\n BACKGROUND = 0,\n FOREGROUND = 1,\n}\n\nexport declare type HTTPResponse = {\n status: number;\n headers: Record<string, string>;\n body: string;\n};\n\nexport declare type FileSystemUploadOptions = (\n | {\n uploadType?: FileSystemUploadType.BINARY_CONTENT;\n }\n | {\n uploadType: FileSystemUploadType.MULTIPART;\n fieldName?: string;\n mimeType?: string;\n parameters?: Record<string, string>;\n }\n) & {\n headers?: Record<string, string>;\n httpMethod?: FileSystemAcceptedUploadHttpMethod;\n sessionType?: FileSystemSessionType;\n};\n\nexport type VideoCompressorType = {\n compress(\n fileUrl: string,\n options?: videoCompresssionType,\n onProgress?: (progress: number) => void\n ): Promise<string>;\n backgroundUpload(\n url: string,\n fileUrl: string,\n options: FileSystemUploadOptions,\n onProgress?: (writtem: number, total: number) => void\n ): Promise<any>;\n activateBackgroundTask(onExpired?: (data: any) => void): Promise<any>;\n deactivateBackgroundTask(): Promise<any>;\n};\n\nconst VideoCompressEventEmitter = new NativeEventEmitter(\n NativeModules.VideoCompressor\n);\n\nconst NativeVideoCompressor = NativeModules.VideoCompressor;\n\nexport const backgroundUpload = async (\n url: string,\n fileUrl: string,\n options: FileSystemUploadOptions,\n onProgress?: (writtem: number, total: number) => void\n): Promise<any> => {\n const uuid = uuidv4();\n let subscription: NativeEventSubscription;\n try {\n if (onProgress) {\n subscription = VideoCompressEventEmitter.addListener(\n 'VideoCompressorProgress',\n (event: any) => {\n if (event.uuid === uuid) {\n onProgress(event.data.written, event.data.total);\n }\n }\n );\n }\n if (Platform.OS === 'android' && fileUrl.includes('file://')) {\n fileUrl = fileUrl.replace('file://', '');\n }\n const result = await NativeVideoCompressor.upload(fileUrl, {\n uuid,\n method: options.httpMethod,\n headers: options.headers,\n url,\n });\n return result;\n } finally {\n // @ts-ignore\n if (subscription) {\n subscription.remove();\n }\n }\n};\n\nconst Video: VideoCompressorType = {\n compress: async (\n fileUrl: string,\n options?: {\n bitrate?: number;\n compressionMethod?: compressionMethod;\n maxSize?: number;\n minimumFileSizeForCompress?: number;\n },\n onProgress?: (progress: number) => void\n ) => {\n const uuid = uuidv4();\n let subscription: NativeEventSubscription;\n try {\n if (onProgress) {\n subscription = VideoCompressEventEmitter.addListener(\n 'videoCompressProgress',\n (event: any) => {\n if (event.uuid === uuid) {\n onProgress(event.data.progress);\n }\n }\n );\n }\n const modifiedOptions: {\n uuid: string;\n bitrate?: number;\n compressionMethod?: compressionMethod;\n maxSize?: number;\n minimumFileSizeForCompress?: number;\n } = { uuid };\n if (options?.bitrate) modifiedOptions.bitrate = options?.bitrate;\n if (options?.compressionMethod) {\n modifiedOptions.compressionMethod = options?.compressionMethod;\n } else {\n modifiedOptions.compressionMethod = 'manual';\n }\n if (options?.maxSize) {\n modifiedOptions.maxSize = options?.maxSize;\n } else {\n modifiedOptions.maxSize = 640;\n }\n if (options?.minimumFileSizeForCompress) {\n modifiedOptions.minimumFileSizeForCompress =\n options?.minimumFileSizeForCompress;\n }\n const result = await NativeVideoCompressor.compress(\n fileUrl,\n modifiedOptions\n );\n return result;\n } finally {\n // @ts-ignore\n if (subscription) {\n subscription.remove();\n }\n }\n },\n backgroundUpload,\n activateBackgroundTask(onExpired?) {\n if (onExpired) {\n const subscription: NativeEventSubscription =\n VideoCompressEventEmitter.addListener(\n 'backgroundTaskExpired',\n (event: any) => {\n onExpired(event);\n if (subscription) {\n subscription.remove();\n }\n }\n );\n }\n return NativeVideoCompressor.activateBackgroundTask({});\n },\n deactivateBackgroundTask() {\n VideoCompressEventEmitter.removeAllListeners('backgroundTaskExpired');\n return NativeVideoCompressor.deactivateBackgroundTask({});\n },\n} as VideoCompressorType;\n\nexport default Video;\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createRunOncePlugin } from '@expo/config-plugins';
|
|
2
|
+
|
|
3
|
+
const pkg = require('../../../package.json');
|
|
4
|
+
|
|
5
|
+
const withCompressor = config => config;
|
|
6
|
+
|
|
7
|
+
export default createRunOncePlugin(withCompressor, pkg.name, pkg.version);
|
|
8
|
+
//# sourceMappingURL=compressor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["compressor.ts"],"names":["createRunOncePlugin","pkg","require","withCompressor","config","name","version"],"mappings":"AAAA,SAAuBA,mBAAvB,QAAkD,sBAAlD;;AACA,MAAMC,GAAG,GAAGC,OAAO,CAAC,uBAAD,CAAnB;;AAIA,MAAMC,cAAmC,GAAIC,MAAD,IAAYA,MAAxD;;AAEA,eAAeJ,mBAAmB,CAACG,cAAD,EAAiBF,GAAG,CAACI,IAArB,EAA2BJ,GAAG,CAACK,OAA/B,CAAlC","sourcesContent":["import { ConfigPlugin, createRunOncePlugin } from '@expo/config-plugins';\nconst pkg = require('../../../package.json');\n\ntype Props = {};\n\nconst withCompressor: ConfigPlugin<Props> = (config) => config;\n\nexport default createRunOncePlugin(withCompressor, pkg.name, pkg.version);\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import 'react-native-get-random-values';
|
|
1
2
|
export declare enum FileSystemUploadType {
|
|
2
3
|
BINARY_CONTENT = 0,
|
|
3
4
|
MULTIPART = 1
|
|
@@ -6,7 +7,9 @@ export declare type FileSystemAcceptedUploadHttpMethod = 'POST' | 'PUT' | 'PATCH
|
|
|
6
7
|
export declare type compressionMethod = 'auto' | 'manual';
|
|
7
8
|
declare type videoCompresssionType = {
|
|
8
9
|
bitrate?: number;
|
|
10
|
+
maxSize?: number;
|
|
9
11
|
compressionMethod?: compressionMethod;
|
|
12
|
+
minimumFileSizeForCompress?: number;
|
|
10
13
|
};
|
|
11
14
|
export declare enum FileSystemSessionType {
|
|
12
15
|
BACKGROUND = 0,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-compressor",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
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,6 +60,7 @@
|
|
|
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",
|
|
@@ -162,5 +164,8 @@
|
|
|
162
164
|
}
|
|
163
165
|
]
|
|
164
166
|
]
|
|
167
|
+
},
|
|
168
|
+
"dependencies": {
|
|
169
|
+
"react-native-get-random-values": "^1.7.0"
|
|
165
170
|
}
|
|
166
171
|
}
|
package/src/Video/index.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
Platform,
|
|
5
5
|
NativeEventSubscription,
|
|
6
6
|
} from 'react-native';
|
|
7
|
+
import 'react-native-get-random-values';
|
|
7
8
|
import { v4 as uuidv4 } from 'uuid';
|
|
8
9
|
|
|
9
10
|
export declare enum FileSystemUploadType {
|
|
@@ -18,7 +19,9 @@ export declare type FileSystemAcceptedUploadHttpMethod =
|
|
|
18
19
|
export type compressionMethod = 'auto' | 'manual';
|
|
19
20
|
type videoCompresssionType = {
|
|
20
21
|
bitrate?: number;
|
|
22
|
+
maxSize?: number;
|
|
21
23
|
compressionMethod?: compressionMethod;
|
|
24
|
+
minimumFileSizeForCompress?: number;
|
|
22
25
|
};
|
|
23
26
|
|
|
24
27
|
export declare enum FileSystemSessionType {
|
|
@@ -114,6 +117,7 @@ const Video: VideoCompressorType = {
|
|
|
114
117
|
bitrate?: number;
|
|
115
118
|
compressionMethod?: compressionMethod;
|
|
116
119
|
maxSize?: number;
|
|
120
|
+
minimumFileSizeForCompress?: number;
|
|
117
121
|
},
|
|
118
122
|
onProgress?: (progress: number) => void
|
|
119
123
|
) => {
|
|
@@ -135,6 +139,7 @@ const Video: VideoCompressorType = {
|
|
|
135
139
|
bitrate?: number;
|
|
136
140
|
compressionMethod?: compressionMethod;
|
|
137
141
|
maxSize?: number;
|
|
142
|
+
minimumFileSizeForCompress?: number;
|
|
138
143
|
} = { uuid };
|
|
139
144
|
if (options?.bitrate) modifiedOptions.bitrate = options?.bitrate;
|
|
140
145
|
if (options?.compressionMethod) {
|
|
@@ -147,6 +152,10 @@ const Video: VideoCompressorType = {
|
|
|
147
152
|
} else {
|
|
148
153
|
modifiedOptions.maxSize = 640;
|
|
149
154
|
}
|
|
155
|
+
if (options?.minimumFileSizeForCompress) {
|
|
156
|
+
modifiedOptions.minimumFileSizeForCompress =
|
|
157
|
+
options?.minimumFileSizeForCompress;
|
|
158
|
+
}
|
|
150
159
|
const result = await NativeVideoCompressor.compress(
|
|
151
160
|
fileUrl,
|
|
152
161
|
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);
|