react-native-compressor 1.3.5-alpha → 1.4.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 +23 -0
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/reactnativecompressor/CompressorModule.java +14 -1
- package/android/src/main/java/com/reactnativecompressor/Utils/Utils.java +26 -1
- package/android/src/main/java/com/reactnativecompressor/Video/VideoModule.java +2 -11
- package/ios/.DS_Store +0 -0
- package/ios/Compressor-Bridging-Header.h +1 -1
- package/ios/Compressor.m +37 -12
- package/ios/Image/ImageCompressor.h +2 -0
- package/ios/Image/ImageCompressor.m +152 -1
- package/ios/Video/VideoCompressor.swift +34 -34
- package/lib/commonjs/Video/index.js +1 -1
- package/lib/commonjs/Video/index.js.map +1 -1
- package/lib/commonjs/index.js +15 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/index.js +12 -4
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/module/Video/index.js +1 -1
- package/lib/module/Video/index.js.map +1 -1
- package/lib/module/index.js +5 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/index.js +6 -4
- package/lib/module/utils/index.js.map +1 -1
- package/lib/typescript/index.d.ts +4 -2
- package/lib/typescript/utils/index.d.ts +2 -0
- package/package.json +1 -1
- package/src/Video/index.tsx +1 -1
- package/src/index.tsx +5 -1
- package/src/utils/index.tsx +7 -3
package/README.md
CHANGED
|
@@ -334,6 +334,29 @@ type FileSystemUploadOptions = (
|
|
|
334
334
|
};
|
|
335
335
|
```
|
|
336
336
|
|
|
337
|
+
# Get Real Path
|
|
338
|
+
if you want to convert
|
|
339
|
+
|
|
340
|
+
- `content://` to `file:///` for android
|
|
341
|
+
- `ph://` to `file:///` for IOS
|
|
342
|
+
|
|
343
|
+
the you can you `getRealPath` function like this
|
|
344
|
+
```js
|
|
345
|
+
import { getRealPath } from 'react-native-compressor';
|
|
346
|
+
|
|
347
|
+
const realPath = await getRealPath(fileUri, 'video'); // file://file_path.extension
|
|
348
|
+
```
|
|
349
|
+
- ###### `getRealPath(path: string, type: string = 'video'|'image')`
|
|
350
|
+
|
|
351
|
+
# Get Temp file Path
|
|
352
|
+
if you wanna make random file path in cache folder then you can use this method like this
|
|
353
|
+
|
|
354
|
+
```js
|
|
355
|
+
import { getRealPath } from 'react-native-compressor';
|
|
356
|
+
|
|
357
|
+
const realPath = await generateFilePath(fileUri, 'video'); // file://file_path.extension
|
|
358
|
+
```
|
|
359
|
+
|
|
337
360
|
## Contributing
|
|
338
361
|
|
|
339
362
|
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
package/android/build.gradle
CHANGED
|
@@ -57,6 +57,6 @@ dependencies {
|
|
|
57
57
|
//noinspection GradleDynamicVersion
|
|
58
58
|
implementation "com.facebook.react:react-native:+" // From node_modules
|
|
59
59
|
implementation 'io.github.lizhangqu:coreprogress:1.0.2'
|
|
60
|
-
implementation 'com.github.nomi9995:VideoCompressor:
|
|
60
|
+
implementation 'com.github.nomi9995:VideoCompressor:715bcc16e9'
|
|
61
61
|
// implementation project(path: ':videocompressor')
|
|
62
62
|
}
|
|
@@ -20,8 +20,10 @@ import com.facebook.react.module.annotations.ReactModule;
|
|
|
20
20
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
21
21
|
import com.reactnativecompressor.Image.ImageCompressor;
|
|
22
22
|
import com.reactnativecompressor.Image.utils.ImageCompressorOptions;
|
|
23
|
+
import com.reactnativecompressor.Utils.Utils;
|
|
23
24
|
import com.reactnativecompressor.Video.VideoCompressorHelper;
|
|
24
25
|
import static com.reactnativecompressor.Utils.Utils.generateCacheFilePath;
|
|
26
|
+
|
|
25
27
|
import com.reactnativecompressor.Audio.AudioCompressor;
|
|
26
28
|
|
|
27
29
|
@ReactModule(name = CompressorModule.NAME)
|
|
@@ -54,6 +56,7 @@ public class CompressorModule extends ReactContextBaseJavaModule {
|
|
|
54
56
|
ReadableMap optionMap,
|
|
55
57
|
Promise promise) {
|
|
56
58
|
try {
|
|
59
|
+
imagePath=Utils.getRealPath(imagePath,reactContext);
|
|
57
60
|
final ImageCompressorOptions options = ImageCompressorOptions.fromMap(optionMap);
|
|
58
61
|
|
|
59
62
|
if(options.compressionMethod==ImageCompressorOptions.CompressionMethod.auto)
|
|
@@ -98,7 +101,7 @@ public class CompressorModule extends ReactContextBaseJavaModule {
|
|
|
98
101
|
|
|
99
102
|
//General
|
|
100
103
|
@ReactMethod
|
|
101
|
-
public void
|
|
104
|
+
public void generateFilePath(String extension, Promise promise) {
|
|
102
105
|
try {
|
|
103
106
|
final String outputUri =generateCacheFilePath(extension,reactContext);
|
|
104
107
|
promise.resolve(outputUri);
|
|
@@ -106,4 +109,14 @@ public class CompressorModule extends ReactContextBaseJavaModule {
|
|
|
106
109
|
promise.reject(e);
|
|
107
110
|
}
|
|
108
111
|
}
|
|
112
|
+
|
|
113
|
+
@ReactMethod
|
|
114
|
+
public void getRealPath(String path,String type, Promise promise) {
|
|
115
|
+
try {
|
|
116
|
+
final String realPath =Utils.getRealPath(path,reactContext);
|
|
117
|
+
promise.resolve("file://"+realPath);
|
|
118
|
+
} catch (Exception e) {
|
|
119
|
+
promise.reject(e);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
109
122
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
package com.reactnativecompressor.Utils;
|
|
2
2
|
|
|
3
|
+
import android.net.Uri;
|
|
4
|
+
import android.util.Log;
|
|
5
|
+
|
|
3
6
|
import androidx.annotation.Nullable;
|
|
4
7
|
|
|
5
8
|
import com.facebook.react.bridge.Arguments;
|
|
@@ -17,6 +20,7 @@ import java.util.UUID;
|
|
|
17
20
|
|
|
18
21
|
public class Utils {
|
|
19
22
|
static int videoCompressionThreshold=10;
|
|
23
|
+
private static final String TAG = "react-native-compessor";
|
|
20
24
|
static Map<String, VideoCompressTask> compressorExports = new HashMap<>();
|
|
21
25
|
|
|
22
26
|
public static String generateCacheFilePath(String extension, ReactApplicationContext reactContext){
|
|
@@ -43,7 +47,14 @@ public class Utils {
|
|
|
43
47
|
|
|
44
48
|
@Override
|
|
45
49
|
public void onError(String errorMessage) {
|
|
46
|
-
|
|
50
|
+
if(errorMessage.equals(("class java.lang.AssertionError")))
|
|
51
|
+
{
|
|
52
|
+
promise.resolve(srcPath);
|
|
53
|
+
}
|
|
54
|
+
else
|
|
55
|
+
{
|
|
56
|
+
promise.reject("Compression has canncelled");
|
|
57
|
+
}
|
|
47
58
|
}
|
|
48
59
|
|
|
49
60
|
@Override
|
|
@@ -85,4 +96,18 @@ public class Utils {
|
|
|
85
96
|
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
86
97
|
.emit(eventName, params);
|
|
87
98
|
}
|
|
99
|
+
|
|
100
|
+
public static String getRealPath(String fileUrl,ReactApplicationContext reactContext){
|
|
101
|
+
if(fileUrl.startsWith("content://"))
|
|
102
|
+
{
|
|
103
|
+
try {
|
|
104
|
+
Uri uri= Uri.parse(fileUrl);
|
|
105
|
+
fileUrl= RealPathUtil.getRealPath(reactContext,uri);
|
|
106
|
+
}
|
|
107
|
+
catch (Exception ex) {
|
|
108
|
+
Log.d(TAG, " Please see this issue: https://github.com/Shobbak/react-native-compressor/issues/25");
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return fileUrl;
|
|
112
|
+
}
|
|
88
113
|
}
|
|
@@ -17,6 +17,7 @@ import com.facebook.react.module.annotations.ReactModule;
|
|
|
17
17
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
18
18
|
import com.reactnativecompressor.Utils.RealPathUtil;
|
|
19
19
|
|
|
20
|
+
import static com.reactnativecompressor.Utils.Utils.getRealPath;
|
|
20
21
|
import static com.reactnativecompressor.Video.VideoCompressorHelper.video_activateBackgroundTask_helper;
|
|
21
22
|
import static com.reactnativecompressor.Video.VideoCompressorHelper.video_deactivateBackgroundTask_helper;
|
|
22
23
|
import static com.reactnativecompressor.Video.VideoCompressorHelper.video_upload_helper;
|
|
@@ -53,17 +54,7 @@ public class VideoModule extends ReactContextBaseJavaModule {
|
|
|
53
54
|
ReadableMap optionMap,
|
|
54
55
|
Promise promise) {
|
|
55
56
|
final VideoCompressorHelper options = VideoCompressorHelper.fromMap(optionMap);
|
|
56
|
-
|
|
57
|
-
if(fileUrl.startsWith("content://"))
|
|
58
|
-
{
|
|
59
|
-
try {
|
|
60
|
-
Uri uri= Uri.parse(fileUrl);
|
|
61
|
-
fileUrl= RealPathUtil.getRealPath(reactContext,uri);
|
|
62
|
-
}
|
|
63
|
-
catch (Exception ex) {
|
|
64
|
-
Log.d(TAG, " Please see this issue: https://github.com/Shobbak/react-native-compressor/issues/25");
|
|
65
|
-
}
|
|
66
|
-
}
|
|
57
|
+
fileUrl=getRealPath(fileUrl,reactContext);
|
|
67
58
|
|
|
68
59
|
if(options.compressionMethod==VideoCompressorHelper.CompressionMethod.auto)
|
|
69
60
|
{
|
package/ios/.DS_Store
CHANGED
|
Binary file
|
package/ios/Compressor.m
CHANGED
|
@@ -20,17 +20,19 @@ RCT_EXPORT_METHOD(
|
|
|
20
20
|
rejecter: (RCTPromiseRejectBlock) reject) {
|
|
21
21
|
@try {
|
|
22
22
|
ImageCompressorOptions *options = [ImageCompressorOptions fromDictionary:optionsDict];
|
|
23
|
+
[ImageCompressor getAbsoluteImagePath:imagePath completionHandler:^(NSString* absoluteImagePath){
|
|
24
|
+
if(options.autoCompress)
|
|
25
|
+
{
|
|
26
|
+
NSString *result = [ImageCompressor autoCompressHandler:absoluteImagePath options:options];
|
|
27
|
+
resolve(result);
|
|
28
|
+
}
|
|
29
|
+
else
|
|
30
|
+
{
|
|
31
|
+
NSString *result = [ImageCompressor manualCompressHandler:absoluteImagePath options:options];
|
|
32
|
+
resolve(result);
|
|
33
|
+
}
|
|
34
|
+
}];
|
|
23
35
|
|
|
24
|
-
if(options.autoCompress)
|
|
25
|
-
{
|
|
26
|
-
NSString *result = [ImageCompressor autoCompressHandler:imagePath options:options];
|
|
27
|
-
resolve(result);
|
|
28
|
-
}
|
|
29
|
-
else
|
|
30
|
-
{
|
|
31
|
-
NSString *result = [ImageCompressor manualCompressHandler:imagePath options:options];
|
|
32
|
-
resolve(result);
|
|
33
|
-
}
|
|
34
36
|
}
|
|
35
37
|
@catch (NSException *exception) {
|
|
36
38
|
reject(exception.name, exception.reason, nil);
|
|
@@ -176,7 +178,7 @@ RCT_EXPORT_METHOD(
|
|
|
176
178
|
|
|
177
179
|
//general
|
|
178
180
|
RCT_EXPORT_METHOD(
|
|
179
|
-
|
|
181
|
+
generateFilePath: (NSString*) extension
|
|
180
182
|
resolver: (RCTPromiseResolveBlock) resolve
|
|
181
183
|
rejecter: (RCTPromiseRejectBlock) reject) {
|
|
182
184
|
@try {
|
|
@@ -188,6 +190,30 @@ RCT_EXPORT_METHOD(
|
|
|
188
190
|
}
|
|
189
191
|
}
|
|
190
192
|
|
|
193
|
+
RCT_EXPORT_METHOD(
|
|
194
|
+
getRealPath: (NSString*) path
|
|
195
|
+
type: (NSString*) type
|
|
196
|
+
resolver: (RCTPromiseResolveBlock) resolve
|
|
197
|
+
rejecter: (RCTPromiseRejectBlock) reject) {
|
|
198
|
+
@try {
|
|
199
|
+
if([type isEqualToString:@"video"])
|
|
200
|
+
{
|
|
201
|
+
[ImageCompressor getAbsoluteVideoPath:path completionHandler:^(NSString* absoluteImagePath){
|
|
202
|
+
resolve(absoluteImagePath);
|
|
203
|
+
}];
|
|
204
|
+
}
|
|
205
|
+
else
|
|
206
|
+
{
|
|
207
|
+
[ImageCompressor getAbsoluteImagePath:path completionHandler:^(NSString* absoluteImagePath){
|
|
208
|
+
resolve(absoluteImagePath);
|
|
209
|
+
}];
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
@catch (NSException *exception) {
|
|
213
|
+
reject(exception.name, exception.reason, nil);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
191
217
|
//general
|
|
192
218
|
RCT_EXPORT_METHOD(
|
|
193
219
|
getFileSize: (NSString*) filePath
|
|
@@ -242,4 +268,3 @@ RCT_EXTERN_METHOD(deactivateBackgroundTask: (NSDictionary *)options
|
|
|
242
268
|
RCT_EXTERN_METHOD(cancelCompression:(NSString *)uuid)
|
|
243
269
|
|
|
244
270
|
@end
|
|
245
|
-
|
|
@@ -12,4 +12,6 @@
|
|
|
12
12
|
+(NSString *)autoCompressHandler:(NSString *)imagePath options:(ImageCompressorOptions*)options;
|
|
13
13
|
+ (NSString *)manualCompress:(UIImage *)image output:(enum OutputType)output quality:(float)quality outputExtension:(NSString*)outputExtension isBase64:(Boolean)isBase64;
|
|
14
14
|
+ (UIImage *)scaleAndRotateImage:(UIImage *)image;
|
|
15
|
+
+ (void)getAbsoluteImagePath:(NSString *)imagePath completionHandler:(void (^)(NSString *absoluteImagePath))completionHandler;
|
|
16
|
+
+(void)getAbsoluteVideoPath:(NSString *)videoPath completionHandler:(void (^)(NSString *absoluteImagePath))completionHandler;
|
|
15
17
|
@end
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
#import <Accelerate/Accelerate.h>
|
|
2
2
|
#import <CoreGraphics/CoreGraphics.h>
|
|
3
|
-
|
|
3
|
+
#import <Photos/Photos.h>
|
|
4
|
+
#import <React/RCTUtils.h>
|
|
5
|
+
#import <React/RCTImageLoader.h>
|
|
4
6
|
#import "ImageCompressor.h"
|
|
7
|
+
#import <React/RCTConvert.h>
|
|
8
|
+
#import <Foundation/Foundation.h>
|
|
9
|
+
#import <MobileCoreServices/MobileCoreServices.h>
|
|
5
10
|
|
|
6
11
|
@implementation ImageCompressor
|
|
7
12
|
+ (CGSize) findTargetSize: (UIImage *) image maxWidth: (int) maxWidth maxHeight: (int) maxHeight {
|
|
@@ -288,4 +293,150 @@
|
|
|
288
293
|
return returnablePath;
|
|
289
294
|
}
|
|
290
295
|
|
|
296
|
+
+(void)getAbsoluteImagePath:(NSString *)imagePath completionHandler:(void (^)(NSString *absoluteImagePath))completionHandler
|
|
297
|
+
{
|
|
298
|
+
if (![imagePath containsString:@"ph://"]) {
|
|
299
|
+
completionHandler(imagePath);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
NSURL *imageURL = [NSURL URLWithString:[imagePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"]];
|
|
303
|
+
CGSize size = CGSizeZero;
|
|
304
|
+
CGFloat scale = 1;
|
|
305
|
+
RCTResizeMode resizeMode = RCTResizeModeContain;
|
|
306
|
+
NSString *assetID = @"";
|
|
307
|
+
PHFetchResult *results;
|
|
308
|
+
if (!imageURL) {
|
|
309
|
+
NSString *errorText = @"Cannot load a photo library asset with no URL";
|
|
310
|
+
@throw([NSException exceptionWithName:errorText reason:errorText userInfo:nil]);
|
|
311
|
+
} else if ([imageURL.scheme caseInsensitiveCompare:@"assets-library"] == NSOrderedSame) {
|
|
312
|
+
assetID = [imageURL absoluteString];
|
|
313
|
+
results = [PHAsset fetchAssetsWithALAssetURLs:@[imageURL] options:nil];
|
|
314
|
+
} else {
|
|
315
|
+
assetID = [imageURL.absoluteString substringFromIndex:@"ph://".length];
|
|
316
|
+
results = [PHAsset fetchAssetsWithLocalIdentifiers:@[assetID] options:nil];
|
|
317
|
+
}
|
|
318
|
+
if (results.count == 0) {
|
|
319
|
+
NSString *errorText = [NSString stringWithFormat:@"Failed to fetch PHAsset with local identifier %@ with no error message.", assetID];
|
|
320
|
+
@throw([NSException exceptionWithName:errorText reason:errorText userInfo:nil]);
|
|
321
|
+
}
|
|
322
|
+
PHAsset *asset = [results firstObject]; // <-- WE GOT THE ASSET
|
|
323
|
+
PHImageRequestOptions *imageOptions = [PHImageRequestOptions new];
|
|
324
|
+
imageOptions.networkAccessAllowed = YES;
|
|
325
|
+
imageOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
|
|
326
|
+
|
|
327
|
+
BOOL useMaximumSize = CGSizeEqualToSize(size, CGSizeZero);
|
|
328
|
+
CGSize targetSize;
|
|
329
|
+
if (useMaximumSize) {
|
|
330
|
+
targetSize = PHImageManagerMaximumSize;
|
|
331
|
+
imageOptions.resizeMode = PHImageRequestOptionsResizeModeNone;
|
|
332
|
+
} else {
|
|
333
|
+
targetSize = CGSizeApplyAffineTransform(size, CGAffineTransformMakeScale(scale, scale));
|
|
334
|
+
imageOptions.resizeMode = PHImageRequestOptionsResizeModeFast;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
PHImageContentMode contentMode = PHImageContentModeAspectFill;
|
|
338
|
+
if (resizeMode == RCTResizeModeContain) {
|
|
339
|
+
contentMode = PHImageContentModeAspectFit;
|
|
340
|
+
}
|
|
341
|
+
[[PHImageManager defaultManager] requestImageForAsset:asset
|
|
342
|
+
targetSize:targetSize
|
|
343
|
+
contentMode:contentMode
|
|
344
|
+
options:imageOptions
|
|
345
|
+
resultHandler:^(UIImage *result, NSDictionary<NSString *, id> *info) {
|
|
346
|
+
// WE GOT THE IMAGE
|
|
347
|
+
if (result) {
|
|
348
|
+
UIImage *image = result;
|
|
349
|
+
NSString *imageName = [assetID stringByReplacingOccurrencesOfString:@"/" withString:@"_"];
|
|
350
|
+
NSString *imagePath = [self saveImageIntoCache:image withName:imageName];
|
|
351
|
+
completionHandler(imagePath);
|
|
352
|
+
} else {
|
|
353
|
+
@throw([NSException exceptionWithName:@"image not found" reason:@"image not found" userInfo:nil]);
|
|
354
|
+
}
|
|
355
|
+
}];
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
+(NSString*) saveImageIntoCache:(UIImage *)image withName:(NSString *)name {
|
|
359
|
+
NSData *imageData = UIImageJPEGRepresentation(image, 1);
|
|
360
|
+
NSString *path =[self generateCacheFilePath:@"jpg"];
|
|
361
|
+
[[NSFileManager defaultManager] createFileAtPath:path contents:imageData attributes:NULL];
|
|
362
|
+
return path;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/// for vide
|
|
366
|
+
|
|
367
|
+
+(void)getAbsoluteVideoPath:(NSString *)videoPath completionHandler:(void (^)(NSString *absoluteImagePath))completionHandler
|
|
368
|
+
{
|
|
369
|
+
if (![videoPath containsString:@"ph://"]) {
|
|
370
|
+
completionHandler(videoPath);
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
NSString *assetId =[videoPath stringByReplacingOccurrencesOfString:@"ph://"
|
|
374
|
+
withString:@""];
|
|
375
|
+
AVFileType outputFileType = AVFileTypeMPEG4;
|
|
376
|
+
NSString *pressetType = AVAssetExportPresetPassthrough;
|
|
377
|
+
|
|
378
|
+
// Throwing some errors to the user if he is not careful enough
|
|
379
|
+
if ([assetId isEqualToString:@""]) {
|
|
380
|
+
NSError *error = [NSError errorWithDomain:@"RNGalleryManager" code: -91 userInfo:nil];
|
|
381
|
+
@throw([NSException exceptionWithName:error reason:error userInfo:nil]);
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// Getting Video Asset
|
|
386
|
+
NSArray* localIds = [NSArray arrayWithObjects: assetId, nil];
|
|
387
|
+
PHAsset * _Nullable videoAsset = [PHAsset fetchAssetsWithLocalIdentifiers:localIds options:nil].firstObject;
|
|
388
|
+
|
|
389
|
+
// Getting information from the asset
|
|
390
|
+
NSString *mimeType = (NSString *)CFBridgingRelease(UTTypeCopyPreferredTagWithClass((__bridge CFStringRef _Nonnull)(outputFileType), kUTTagClassMIMEType));
|
|
391
|
+
CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (__bridge CFStringRef _Nonnull)(mimeType), NULL);
|
|
392
|
+
NSString *extension = (NSString *)CFBridgingRelease(UTTypeCopyPreferredTagWithClass(uti, kUTTagClassFilenameExtension));
|
|
393
|
+
|
|
394
|
+
// Creating output url and temp file name
|
|
395
|
+
NSString *path =[self generateCacheFilePath:extension];
|
|
396
|
+
NSURL *outputUrl = [NSURL URLWithString:[@"file://" stringByAppendingString:path]];
|
|
397
|
+
|
|
398
|
+
// Setting video export session options
|
|
399
|
+
PHVideoRequestOptions *videoRequestOptions = [[PHVideoRequestOptions alloc] init];
|
|
400
|
+
videoRequestOptions.networkAccessAllowed = YES;
|
|
401
|
+
videoRequestOptions.deliveryMode = PHVideoRequestOptionsDeliveryModeHighQualityFormat;
|
|
402
|
+
|
|
403
|
+
// Creating new export session
|
|
404
|
+
[[PHImageManager defaultManager] requestExportSessionForVideo:videoAsset options:videoRequestOptions exportPreset:pressetType resultHandler:^(AVAssetExportSession * _Nullable exportSession, NSDictionary * _Nullable info) {
|
|
405
|
+
|
|
406
|
+
exportSession.shouldOptimizeForNetworkUse = YES;
|
|
407
|
+
exportSession.outputFileType = outputFileType;
|
|
408
|
+
exportSession.outputURL = outputUrl;
|
|
409
|
+
// Converting the video and waiting to see whats going to happen
|
|
410
|
+
[exportSession exportAsynchronouslyWithCompletionHandler:^{
|
|
411
|
+
switch ([exportSession status])
|
|
412
|
+
{
|
|
413
|
+
case AVAssetExportSessionStatusFailed:
|
|
414
|
+
{
|
|
415
|
+
NSError* error = exportSession.error;
|
|
416
|
+
NSString *codeWithDomain = [NSString stringWithFormat:@"E%@%zd", error.domain.uppercaseString, error.code];
|
|
417
|
+
@throw([NSException exceptionWithName:error reason:error userInfo:nil]);
|
|
418
|
+
break;
|
|
419
|
+
}
|
|
420
|
+
case AVAssetExportSessionStatusCancelled:
|
|
421
|
+
{
|
|
422
|
+
NSError *error = [NSError errorWithDomain:@"RNGalleryManager" code: -91 userInfo:nil];
|
|
423
|
+
@throw([NSException exceptionWithName:error reason:error userInfo:nil]);
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
case AVAssetExportSessionStatusCompleted:
|
|
427
|
+
{
|
|
428
|
+
completionHandler(outputUrl.absoluteString);
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
default:
|
|
432
|
+
{
|
|
433
|
+
NSError *error = [NSError errorWithDomain:@"RNGalleryManager" code: -91 userInfo:nil];
|
|
434
|
+
@throw([NSException exceptionWithName:@"Unknown status" reason:@"Unknown status" userInfo:nil]);
|
|
435
|
+
break;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}];
|
|
439
|
+
}];
|
|
440
|
+
}
|
|
441
|
+
|
|
291
442
|
@end
|
|
@@ -2,6 +2,7 @@ import Foundation
|
|
|
2
2
|
import AssetsLibrary
|
|
3
3
|
import AVFoundation
|
|
4
4
|
import NextLevelSessionExporter
|
|
5
|
+
import Photos
|
|
5
6
|
|
|
6
7
|
struct CompressionError: Error {
|
|
7
8
|
private let message: String
|
|
@@ -205,45 +206,45 @@ func makeValidUri(filePath: String) -> String {
|
|
|
205
206
|
|
|
206
207
|
|
|
207
208
|
func compressVideo(url: URL, options: [String: Any], onProgress: @escaping (Float) -> Void, onCompletion: @escaping (URL) -> Void, onFailure: @escaping (Error) -> Void){
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
if(fileSize>minimumFileSizeForCompress)
|
|
215
|
-
{
|
|
216
|
-
if(options["compressionMethod"] as! String=="auto")
|
|
209
|
+
ImageCompressor.getAbsoluteVideoPath(url.absoluteString) { absoluteVideoPath in
|
|
210
|
+
var minimumFileSizeForCompress:Double=16.0;
|
|
211
|
+
let videoURL = URL(string: absoluteVideoPath!)
|
|
212
|
+
let fileSize=self.getfileSize(forURL: videoURL!);
|
|
213
|
+
if((options["minimumFileSizeForCompress"]) != nil)
|
|
217
214
|
{
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
215
|
+
minimumFileSizeForCompress=options["minimumFileSizeForCompress"] as! Double;
|
|
216
|
+
}
|
|
217
|
+
if(fileSize>minimumFileSizeForCompress)
|
|
218
|
+
{
|
|
219
|
+
if(options["compressionMethod"] as! String=="auto")
|
|
220
|
+
{
|
|
221
|
+
self.autoCompressionHelper(url: videoURL!, options:options) { progress in
|
|
222
|
+
onProgress(progress)
|
|
223
|
+
} onCompletion: { outputURL in
|
|
224
|
+
onCompletion(outputURL)
|
|
225
|
+
} onFailure: { error in
|
|
226
|
+
onFailure(error)
|
|
227
|
+
}
|
|
224
228
|
}
|
|
229
|
+
else
|
|
230
|
+
{
|
|
231
|
+
self.manualCompressionHelper(url: videoURL!, options:options) { progress in
|
|
232
|
+
onProgress(progress)
|
|
233
|
+
} onCompletion: { outputURL in
|
|
234
|
+
onCompletion(outputURL)
|
|
235
|
+
} onFailure: { error in
|
|
236
|
+
onFailure(error)
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
225
242
|
}
|
|
226
243
|
else
|
|
227
244
|
{
|
|
228
|
-
|
|
229
|
-
onProgress(progress)
|
|
230
|
-
} onCompletion: { outputURL in
|
|
231
|
-
onCompletion(outputURL)
|
|
232
|
-
} onFailure: { error in
|
|
233
|
-
onFailure(error)
|
|
234
|
-
}
|
|
245
|
+
onCompletion(url)
|
|
235
246
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
else
|
|
241
|
-
{
|
|
242
|
-
onCompletion(url)
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
+
}
|
|
247
248
|
}
|
|
248
249
|
|
|
249
250
|
|
|
@@ -412,5 +413,4 @@ func makeValidUri(filePath: String) -> String {
|
|
|
412
413
|
return track;
|
|
413
414
|
}
|
|
414
415
|
|
|
415
|
-
|
|
416
416
|
}
|
|
@@ -82,7 +82,7 @@ const Video = {
|
|
|
82
82
|
modifiedOptions.maxSize = 640;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
if (options
|
|
85
|
+
if ((options === null || options === void 0 ? void 0 : options.minimumFileSizeForCompress) !== undefined) {
|
|
86
86
|
modifiedOptions.minimumFileSizeForCompress = options === null || options === void 0 ? void 0 : options.minimumFileSizeForCompress;
|
|
87
87
|
}
|
|
88
88
|
|
|
@@ -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","cancelCompression","cancellationId","Video","compress","progress","modifiedOptions","bitrate","compressionMethod","maxSize","minimumFileSizeForCompress","getCancellationId","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners"],"mappings":";;;;;;;AAAA;;AAMA;;AAgEA,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,oBAAb;AACA,MAAIC,YAAJ;;AACA,MAAI;AACF,QAAIF,UAAJ,EAAgB;AACdE,MAAAA,YAAY,GAAGX,yBAAyB,CAACY,WAA1B,CACb,yBADa,EAEZC,KAAD,IAAgB;AACd,YAAIA,KAAK,CAACH,IAAN,KAAeA,IAAnB,EAAyB;AACvBD,UAAAA,UAAU,CAACI,KAAK,CAACC,IAAN,CAAWC,OAAZ,EAAqBF,KAAK,CAACC,IAAN,CAAWE,KAAhC,CAAV;AACD;AACF,OANY,CAAf;AAQD;;AACD,QAAIC,sBAASC,EAAT,KAAgB,SAAhB,IAA6BX,OAAO,CAACY,QAAR,CAAiB,SAAjB,CAAjC,EAA8D;AAC5DZ,MAAAA,OAAO,GAAGA,OAAO,CAACa,OAAR,CAAgB,SAAhB,EAA2B,EAA3B,CAAV;AACD;;AACD,UAAMC,MAAM,GAAG,MAAMjB,qBAAqB,CAACkB,MAAtB,CAA6Bf,OAA7B,EAAsC;AACzDG,MAAAA,IADyD;AAEzDa,MAAAA,MAAM,EAAEf,OAAO,CAACgB,UAFyC;AAGzDC,MAAAA,OAAO,EAAEjB,OAAO,C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,QAAAA,eAAe,CAACG,OAAhB,GAA0B3B,OAA1B,aAA0BA,OAA1B,uBAA0BA,OAAO,CAAE2B,OAAnC;AACD,OAFD,MAEO;AACLH,QAAAA,eAAe,CAACG,OAAhB,GAA0B,GAA1B;AACD;;AACD,
|
|
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","cancelCompression","cancellationId","Video","compress","progress","modifiedOptions","bitrate","compressionMethod","maxSize","minimumFileSizeForCompress","undefined","getCancellationId","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners"],"mappings":";;;;;;;AAAA;;AAMA;;AAgEA,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,oBAAb;AACA,MAAIC,YAAJ;;AACA,MAAI;AACF,QAAIF,UAAJ,EAAgB;AACdE,MAAAA,YAAY,GAAGX,yBAAyB,CAACY,WAA1B,CACb,yBADa,EAEZC,KAAD,IAAgB;AACd,YAAIA,KAAK,CAACH,IAAN,KAAeA,IAAnB,EAAyB;AACvBD,UAAAA,UAAU,CAACI,KAAK,CAACC,IAAN,CAAWC,OAAZ,EAAqBF,KAAK,CAACC,IAAN,CAAWE,KAAhC,CAAV;AACD;AACF,OANY,CAAf;AAQD;;AACD,QAAIC,sBAASC,EAAT,KAAgB,SAAhB,IAA6BX,OAAO,CAACY,QAAR,CAAiB,SAAjB,CAAjC,EAA8D;AAC5DZ,MAAAA,OAAO,GAAGA,OAAO,CAACa,OAAR,CAAgB,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EAAkB;AAChBA,UAAAA,YAAY,CAACe,MAAb;AACD;AACF,OAPH,CADF;AAUD;;AACD,WAAOtB,qBAAqB,CAACmC,sBAAtB,CAA6C,EAA7C,CAAP;AACD,GAxEgC;;AAyEjCE,EAAAA,wBAAwB,GAAG;AACzBzC,IAAAA,yBAAyB,CAAC0C,kBAA1B,CAA6C,uBAA7C;AACA,WAAOtC,qBAAqB,CAACqC,wBAAtB,CAA+C,EAA/C,CAAP;AACD;;AA5EgC,CAAnC;eA+EeZ,K","sourcesContent":["import {\n NativeModules,\n NativeEventEmitter,\n Platform,\n NativeEventSubscription,\n} from 'react-native';\nimport { uuidv4 } from '../utils';\n\nexport declare enum FileSystemUploadType {\n BINARY_CONTENT = 0,\n MULTIPART = 1,\n}\n\nexport declare type FileSystemAcceptedUploadHttpMethod =\n | 'POST'\n | 'PUT'\n | 'PATCH';\nexport type compressionMethod = 'auto' | 'manual';\ntype videoCompresssionType = {\n bitrate?: number;\n maxSize?: number;\n compressionMethod?: compressionMethod;\n minimumFileSizeForCompress?: number;\n getCancellationId?: (cancellationId: string) => void;\n};\n\nexport declare enum FileSystemSessionType {\n BACKGROUND = 0,\n FOREGROUND = 1,\n}\n\nexport declare type HTTPResponse = {\n status: number;\n headers: Record<string, string>;\n body: string;\n};\n\nexport declare type FileSystemUploadOptions = (\n | {\n uploadType?: FileSystemUploadType.BINARY_CONTENT;\n }\n | {\n uploadType: FileSystemUploadType.MULTIPART;\n fieldName?: string;\n mimeType?: string;\n parameters?: Record<string, string>;\n }\n) & {\n headers?: Record<string, string>;\n httpMethod?: FileSystemAcceptedUploadHttpMethod;\n sessionType?: FileSystemSessionType;\n};\n\nexport type VideoCompressorType = {\n compress(\n fileUrl: string,\n options?: videoCompresssionType,\n onProgress?: (progress: number) => void\n ): Promise<string>;\n cancelCompression(cancellationId: string): void;\n backgroundUpload(\n url: string,\n fileUrl: string,\n options: FileSystemUploadOptions,\n onProgress?: (writtem: number, total: number) => void\n ): Promise<any>;\n activateBackgroundTask(onExpired?: (data: any) => void): Promise<any>;\n deactivateBackgroundTask(): Promise<any>;\n};\n\nconst VideoCompressEventEmitter = new NativeEventEmitter(\n NativeModules.VideoCompressor\n);\n\nconst NativeVideoCompressor = NativeModules.VideoCompressor;\n\nexport const backgroundUpload = async (\n url: string,\n fileUrl: string,\n options: FileSystemUploadOptions,\n onProgress?: (writtem: number, total: number) => void\n): Promise<any> => {\n const uuid = uuidv4();\n let subscription: 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\nexport const cancelCompression = (cancellationId: string) => {\n return NativeVideoCompressor.cancelCompression(cancellationId);\n};\n\nconst Video: VideoCompressorType = {\n compress: async (\n fileUrl: string,\n options?: videoCompresssionType,\n onProgress?: (progress: number) => void\n ) => {\n const uuid = uuidv4();\n let subscription: 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 !== undefined) {\n modifiedOptions.minimumFileSizeForCompress =\n options?.minimumFileSizeForCompress;\n }\n if (options?.getCancellationId) {\n options?.getCancellationId(uuid);\n }\n const result = await NativeVideoCompressor.compress(\n fileUrl,\n modifiedOptions\n );\n return result;\n } finally {\n // @ts-ignore\n if (subscription) {\n subscription.remove();\n }\n }\n },\n backgroundUpload,\n cancelCompression,\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"]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -45,6 +45,18 @@ Object.defineProperty(exports, "uuidv4", {
|
|
|
45
45
|
return _utils.uuidv4;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
|
+
Object.defineProperty(exports, "generateFilePath", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _utils.generateFilePath;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "getRealPath", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _utils.getRealPath;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
48
60
|
exports.default = void 0;
|
|
49
61
|
|
|
50
62
|
var _Video = _interopRequireWildcard(require("./Video"));
|
|
@@ -67,7 +79,9 @@ var _default = {
|
|
|
67
79
|
Image: _Image.default,
|
|
68
80
|
backgroundUpload: _Video.backgroundUpload,
|
|
69
81
|
getDetails: _utils.getDetails,
|
|
70
|
-
uuidv4: _utils.uuidv4
|
|
82
|
+
uuidv4: _utils.uuidv4,
|
|
83
|
+
generateFilePath: _utils.generateFilePath,
|
|
84
|
+
getRealPath: _utils.getRealPath
|
|
71
85
|
};
|
|
72
86
|
exports.default = _default;
|
|
73
87
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["Video","Audio","Image","backgroundUpload","getDetails","uuidv4"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["Video","Audio","Image","backgroundUpload","getDetails","uuidv4","generateFilePath","getRealPath"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;;;eAce;AACbA,EAAAA,KAAK,EAALA,cADa;AAEbC,EAAAA,KAAK,EAALA,cAFa;AAGbC,EAAAA,KAAK,EAALA,cAHa;AAIbC,EAAAA,gBAAgB,EAAhBA,uBAJa;AAKbC,EAAAA,UAAU,EAAVA,iBALa;AAMbC,EAAAA,MAAM,EAANA,aANa;AAObC,EAAAA,gBAAgB,EAAhBA,uBAPa;AAQbC,EAAAA,WAAW,EAAXA;AARa,C","sourcesContent":["import Video, { VideoCompressorType, backgroundUpload } from './Video';\nimport Audio from './Audio';\nimport Image from './Image';\nimport { getDetails, uuidv4, generateFilePath, getRealPath } from './utils';\n\nexport {\n Video,\n Audio,\n Image,\n backgroundUpload,\n //type\n VideoCompressorType,\n getDetails,\n uuidv4,\n generateFilePath,\n getRealPath,\n};\nexport default {\n Video,\n Audio,\n Image,\n backgroundUpload,\n getDetails,\n uuidv4,\n generateFilePath,\n getRealPath,\n};\n"]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.uuidv4 = exports.checkUrlAndOptions = exports.getDetails = exports.DEFAULT_COMPRESS_AUDIO_OPTIONS = exports.AUDIO_BITRATE = void 0;
|
|
6
|
+
exports.uuidv4 = exports.checkUrlAndOptions = exports.getDetails = exports.getRealPath = exports.generateFilePath = exports.DEFAULT_COMPRESS_AUDIO_OPTIONS = exports.AUDIO_BITRATE = void 0;
|
|
7
7
|
|
|
8
8
|
var _reactNative = require("react-native");
|
|
9
9
|
|
|
@@ -23,12 +23,20 @@ const DEFAULT_COMPRESS_AUDIO_OPTIONS = {
|
|
|
23
23
|
};
|
|
24
24
|
exports.DEFAULT_COMPRESS_AUDIO_OPTIONS = DEFAULT_COMPRESS_AUDIO_OPTIONS;
|
|
25
25
|
|
|
26
|
-
const
|
|
26
|
+
const generateFilePath = extension => {
|
|
27
27
|
return new Promise((resolve, reject) => {
|
|
28
|
-
Compressor.
|
|
28
|
+
Compressor.generateFilePath(extension).then(result => resolve('file://' + result)).catch(error => reject(error));
|
|
29
29
|
});
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
exports.generateFilePath = generateFilePath;
|
|
33
|
+
|
|
34
|
+
const getRealPath = (path, type = '') => {
|
|
35
|
+
return Compressor.getRealPath(path, type);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.getRealPath = getRealPath;
|
|
39
|
+
|
|
32
40
|
const isValidUrl = url => /^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/.test(url);
|
|
33
41
|
|
|
34
42
|
const getFullFilename = path => {
|
|
@@ -120,7 +128,7 @@ const checkUrlAndOptions = async (url, options) => {
|
|
|
120
128
|
outputFilePath = options.outputFilePath;
|
|
121
129
|
defaultResult.outputFilePath = outputFilePath;
|
|
122
130
|
} else {
|
|
123
|
-
outputFilePath = await
|
|
131
|
+
outputFilePath = await generateFilePath('mp3');
|
|
124
132
|
defaultResult.outputFilePath = outputFilePath;
|
|
125
133
|
}
|
|
126
134
|
|
|
@@ -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","uuidv4","replace","c","r","parseFloat","Math","random","toString","Date","getTime","v"],"mappings":";;;;;;;AACA;;AADA;AAEA,MAAM;AAAEA,EAAAA;AAAF,IAAiBC,0BAAvB;AACO,MAAMC,aAAa,GAAG,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,EAAgB,GAAhB,EAAqB,EAArB,EAAyB,EAAzB,EAA6B,EAA7B,CAAtB;;AAEP,MAAMC,oBAAoB,GAAG,kDAA7B;AACA,MAAMC,qBAAqB,GACzB,mDADF;AAEA,MAAMC,wCAAwC,GAC5C,6CADF;AAcO,MAAMC,8BAAqD,GAAG;AACnEC,EAAAA,OAAO,EAAE,EAD0D;AAEnEC,EAAAA,OAAO,EAAE,QAF0D;AAGnEC,EAAAA,cAAc,EAAE;AAHmD,CAA9D;;;AAUP,MAAMC,YAAiB,GAAIC,SAAD,IAAuB;AAC/C,SAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;AACtCd,IAAAA,UAAU,CAACU,YAAX,CAAwBC,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,GA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HO,CAAV,GAKC,EALF,GAMA,CAPJ;AAAA,UAQE;AACAC,IAAAA,CAAC,GAAGR,CAAC,IAAI,GAAL,GAAWC,CAAX,GAAgBA,CAAC,GAAG,GAAL,GAAY,GATjC;AAUA,WAAOO,CAAC,CAACH,QAAF,CAAW,EAAX,CAAP;AACD,GAZM,CAAP;AAaD,CAdM","sourcesContent":["/* eslint-disable no-bitwise */\nimport { NativeModules } from 'react-native';\nconst { Compressor } = NativeModules;\nexport const AUDIO_BITRATE = [256, 192, 160, 128, 96, 64, 32];\ntype qualityType = 'low' | 'medium' | 'high';\nconst INCORRECT_INPUT_PATH = 'Incorrect input path. Please provide a valid one';\nconst INCORRECT_OUTPUT_PATH =\n 'Incorrect output path. Please provide a valid one';\nconst ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE =\n 'An error occur while generating output file';\ntype audioCompresssionType = {\n bitrate?: number;\n quality: qualityType;\n outputFilePath?: string | undefined | null;\n};\n\nexport type defaultResultType = {\n outputFilePath: string | undefined | null;\n isCorrect: boolean;\n message: string;\n};\n\nexport const DEFAULT_COMPRESS_AUDIO_OPTIONS: audioCompresssionType = {\n bitrate: 96,\n quality: 'medium',\n outputFilePath: '',\n};\n\nexport type AudioType = {\n compress(value: string, options?: audioCompresssionType): Promise<string>;\n};\n\nconst generateFile: any = (extension: string) => {\n return new Promise((resolve, reject) => {\n Compressor.generateFile(extension)\n .then((result: any) => resolve('file://' + result))\n .catch((error: any) => reject(error));\n });\n};\n\nconst isValidUrl = (url: string) =>\n /^(?:\\w+:)?\\/\\/([^\\s\\.]+\\.\\S{2}|localhost[\\:?\\d]*)\\S*$/.test(url);\n\nconst getFullFilename = (path: string | null) => {\n if (typeof path === 'string') {\n let _path = path;\n\n // In case of remote media, check if the url would be valid one\n if (path.includes('http') && !isValidUrl(path)) {\n return INCORRECT_INPUT_PATH;\n }\n\n // In case of url, check if it ends with \"/\" and do not consider it furthermore\n if (_path[_path.length - 1] === '/')\n _path = _path.substring(0, path.length - 1);\n\n const array = _path.split('/');\n return array.length > 1 ? array[array.length - 1] : INCORRECT_INPUT_PATH;\n }\n return INCORRECT_INPUT_PATH;\n};\n\nconst isFileNameError = (filename: string) => {\n return filename === INCORRECT_INPUT_PATH;\n};\n\nconst getFilename = (path: string | null) => {\n const fullFilename = getFullFilename(path);\n if (!isFileNameError(fullFilename)) {\n const array = fullFilename.split('.');\n return array.length > 1 ? array.slice(0, -1).join('') : array.join('');\n }\n return fullFilename;\n};\n\nconst isRemoteMedia = (path: string | null) => {\n return typeof path === 'string' ? path.split(':/')[0].includes('http') : null;\n};\n\nexport const getDetails = (\n mediaFullPath: string,\n extesnion: 'mp3' | 'mp4' = 'mp3'\n): Promise<any | null> => {\n return new Promise(async (resolve, reject) => {\n try {\n // Since we used \"-v error\", a work around is to call first this command before the following\n const result: any = {};\n if (result !== 0) {\n throw new Error('Failed to execute command');\n }\n\n // get the output result of the command\n // example of output {\"programs\": [], \"streams\": [{\"width\": 640,\"height\": 360}], \"format\": {\"size\": \"15804433\"}}\n let mediaInfo: any = await {};\n mediaInfo = JSON.parse(mediaInfo);\n\n // execute second command\n const mediaInformation: any = await {};\n\n // treat both results\n mediaInformation.filename = getFilename(mediaFullPath);\n mediaInformation.bitrate = mediaInformation.getMediaProperties().bit_rate;\n mediaInformation.extension = extesnion;\n mediaInformation.isRemoteMedia = isRemoteMedia(mediaFullPath);\n mediaInformation.size = Number(mediaInfo.format.size);\n\n resolve(mediaInformation);\n } catch (e) {\n reject(e);\n }\n });\n};\n\nexport const checkUrlAndOptions = async (\n url: string,\n options: audioCompresssionType\n): Promise<defaultResultType> => {\n if (!url) {\n throw new Error(\n 'Compression url is empty, please provide a url for compression.'\n );\n }\n const defaultResult: defaultResultType = {\n outputFilePath: '',\n isCorrect: true,\n message: '',\n };\n\n // Check if output file is correct\n let outputFilePath: string | undefined | null;\n try {\n // use default output file\n // or use new file from cache folder\n if (options.outputFilePath) {\n outputFilePath = options.outputFilePath;\n defaultResult.outputFilePath = outputFilePath;\n } else {\n outputFilePath = await generateFile('mp3');\n defaultResult.outputFilePath = outputFilePath;\n }\n if (outputFilePath === undefined || outputFilePath === null) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n }\n } catch (e) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n } finally {\n return defaultResult;\n }\n};\n\nexport const uuidv4 = () => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {\n const r =\n (parseFloat(\n '0.' +\n Math.random().toString().replace('0.', '') +\n new Date().getTime()\n ) *\n 16) |\n 0,\n // eslint-disable-next-line eqeqeq\n v = c == 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["Compressor","NativeModules","AUDIO_BITRATE","INCORRECT_INPUT_PATH","INCORRECT_OUTPUT_PATH","ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE","DEFAULT_COMPRESS_AUDIO_OPTIONS","bitrate","quality","outputFilePath","generateFilePath","extension","Promise","resolve","reject","then","result","catch","error","getRealPath","path","type","isValidUrl","url","test","getFullFilename","_path","includes","length","substring","array","split","isFileNameError","filename","getFilename","fullFilename","slice","join","isRemoteMedia","getDetails","mediaFullPath","extesnion","Error","mediaInfo","JSON","parse","mediaInformation","getMediaProperties","bit_rate","size","Number","format","e","checkUrlAndOptions","options","defaultResult","isCorrect","message","undefined","uuidv4","replace","c","r","parseFloat","Math","random","toString","Date","getTime","v"],"mappings":";;;;;;;AACA;;AADA;AAEA,MAAM;AAAEA,EAAAA;AAAF,IAAiBC,0BAAvB;AACO,MAAMC,aAAa,GAAG,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,E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AC9C,cAAd,GAA+BA,cAA/B;AACD,KAHD,MAGO;AACLA,MAAAA,cAAc,GAAG,MAAMC,gBAAgB,CAAC,KAAD,CAAvC;AACA6C,MAAAA,aAAa,CAAC9C,cAAd,GAA+BA,cAA/B;AACD;;AACD,QAAIA,cAAc,KAAKiD,SAAnB,IAAgCjD,cAAc,KAAK,IAAvD,EAA6D;AAC3D8C,MAAAA,aAAa,CAACC,SAAd,GAA0B,KAA1B;AACAD,MAAAA,aAAa,CAACE,OAAd,GAAwBH,OAAO,CAAC7C,cAAR,GACpBL,qBADoB,GAEpBC,wCAFJ;AAGD;AACF,GAhBD,CAgBE,OAAO+C,CAAP,EAAU;AACVG,IAAAA,aAAa,CAACC,SAAd,GAA0B,KAA1B;AACAD,IAAAA,aAAa,CAACE,OAAd,GAAwBH,OAAO,CAAC7C,cAAR,GACpBL,qBADoB,GAEpBC,wCAFJ;AAGD,GArBD,SAqBU;AACR,WAAOkD,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\nexport const generateFilePath: any = (extension: string) => {\n return new Promise((resolve, reject) => {\n Compressor.generateFilePath(extension)\n .then((result: any) => resolve('file://' + result))\n .catch((error: any) => reject(error));\n });\n};\n\nexport const getRealPath: any = (path: string, type: string = '') => {\n return Compressor.getRealPath(path, type);\n};\n\nconst isValidUrl = (url: string) =>\n /^(?:\\w+:)?\\/\\/([^\\s\\.]+\\.\\S{2}|localhost[\\:?\\d]*)\\S*$/.test(url);\n\nconst getFullFilename = (path: string | null) => {\n if (typeof path === 'string') {\n let _path = path;\n\n // In case of remote media, check if the url would be valid one\n if (path.includes('http') && !isValidUrl(path)) {\n return INCORRECT_INPUT_PATH;\n }\n\n // In case of url, check if it ends with \"/\" and do not consider it furthermore\n if (_path[_path.length - 1] === '/')\n _path = _path.substring(0, path.length - 1);\n\n const array = _path.split('/');\n return array.length > 1 ? array[array.length - 1] : INCORRECT_INPUT_PATH;\n }\n return INCORRECT_INPUT_PATH;\n};\n\nconst isFileNameError = (filename: string) => {\n return filename === INCORRECT_INPUT_PATH;\n};\n\nconst getFilename = (path: string | null) => {\n const fullFilename = getFullFilename(path);\n if (!isFileNameError(fullFilename)) {\n const array = fullFilename.split('.');\n return array.length > 1 ? array.slice(0, -1).join('') : array.join('');\n }\n return fullFilename;\n};\n\nconst isRemoteMedia = (path: string | null) => {\n return typeof path === 'string' ? path.split(':/')[0].includes('http') : null;\n};\n\nexport const getDetails = (\n mediaFullPath: string,\n extesnion: 'mp3' | 'mp4' = 'mp3'\n): Promise<any | null> => {\n return new Promise(async (resolve, reject) => {\n try {\n // Since we used \"-v error\", a work around is to call first this command before the following\n const result: any = {};\n if (result !== 0) {\n throw new Error('Failed to execute command');\n }\n\n // get the output result of the command\n // example of output {\"programs\": [], \"streams\": [{\"width\": 640,\"height\": 360}], \"format\": {\"size\": \"15804433\"}}\n let mediaInfo: any = await {};\n mediaInfo = JSON.parse(mediaInfo);\n\n // execute second command\n const mediaInformation: any = await {};\n\n // treat both results\n mediaInformation.filename = getFilename(mediaFullPath);\n mediaInformation.bitrate = mediaInformation.getMediaProperties().bit_rate;\n mediaInformation.extension = extesnion;\n mediaInformation.isRemoteMedia = isRemoteMedia(mediaFullPath);\n mediaInformation.size = Number(mediaInfo.format.size);\n\n resolve(mediaInformation);\n } catch (e) {\n reject(e);\n }\n });\n};\n\nexport const checkUrlAndOptions = async (\n url: string,\n options: audioCompresssionType\n): Promise<defaultResultType> => {\n if (!url) {\n throw new Error(\n 'Compression url is empty, please provide a url for compression.'\n );\n }\n const defaultResult: defaultResultType = {\n outputFilePath: '',\n isCorrect: true,\n message: '',\n };\n\n // Check if output file is correct\n let outputFilePath: string | undefined | null;\n try {\n // use default output file\n // or use new file from cache folder\n if (options.outputFilePath) {\n outputFilePath = options.outputFilePath;\n defaultResult.outputFilePath = outputFilePath;\n } else {\n outputFilePath = await generateFilePath('mp3');\n defaultResult.outputFilePath = outputFilePath;\n }\n if (outputFilePath === undefined || outputFilePath === null) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n }\n } catch (e) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n } finally {\n return defaultResult;\n }\n};\n\nexport const uuidv4 = () => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {\n const r =\n (parseFloat(\n '0.' +\n Math.random().toString().replace('0.', '') +\n new Date().getTime()\n ) *\n 16) |\n 0,\n // eslint-disable-next-line eqeqeq\n v = c == 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n};\n"]}
|
|
@@ -67,7 +67,7 @@ const Video = {
|
|
|
67
67
|
modifiedOptions.maxSize = 640;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
if (options
|
|
70
|
+
if ((options === null || options === void 0 ? void 0 : options.minimumFileSizeForCompress) !== undefined) {
|
|
71
71
|
modifiedOptions.minimumFileSizeForCompress = options === null || options === void 0 ? void 0 : options.minimumFileSizeForCompress;
|
|
72
72
|
}
|
|
73
73
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["NativeModules","NativeEventEmitter","Platform","uuidv4","VideoCompressEventEmitter","VideoCompressor","NativeVideoCompressor","backgroundUpload","url","fileUrl","options","onProgress","uuid","subscription","addListener","event","data","written","total","OS","includes","replace","result","upload","method","httpMethod","headers","remove","cancelCompression","cancellationId","Video","compress","progress","modifiedOptions","bitrate","compressionMethod","maxSize","minimumFileSizeForCompress","getCancellationId","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners"],"mappings":"AAAA,SACEA,aADF,EAEEC,kBAFF,EAGEC,QAHF,QAKO,cALP;AAMA,SAASC,MAAT,QAAuB,UAAvB;AAgEA,MAAMC,yBAAyB,GAAG,IAAIH,kBAAJ,CAChCD,aAAa,CAACK,eADkB,CAAlC;AAIA,MAAMC,qBAAqB,GAAGN,aAAa,CAACK,eAA5C;AAEA,OAAO,MAAME,gBAAgB,GAAG,OAC9BC,GAD8B,EAE9BC,OAF8B,EAG9BC,OA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AACF,UAAIF,UAAJ,EAAgB;AACdE,QAAAA,YAAY,GAAGT,yBAAyB,CAACU,WAA1B,CACb,uBADa,EAEZC,KAAD,IAAgB;AACd,cAAIA,KAAK,CAACH,IAAN,KAAeA,IAAnB,EAAyB;AACvBD,YAAAA,UAAU,CAACI,KAAK,CAACC,IAAN,CAAWgB,QAAZ,CAAV;AACD;AACF,SANY,CAAf;AAQD;;AACD,YAAMC,eAML,GAAG;AAAErB,QAAAA;AAAF,OANJ;AAOA,UAAIF,OAAJ,aAAIA,OAAJ,eAAIA,OAAO,CAAEwB,OAAb,EAAsBD,eAAe,CAACC,OAAhB,GAA0BxB,OAA1B,aAA0BA,OAA1B,uBAA0BA,OAAO,CAAEwB,OAAnC;;AACtB,UAAIxB,OAAJ,aAAIA,OAAJ,eAAIA,OAAO,CAAEyB,iBAAb,EAAgC;AAC9BF,QAAAA,eAAe,CAACE,iBAAhB,GAAoCzB,OAApC,aAAoCA,OAApC,uBAAoCA,OAAO,CAAEyB,iBAA7C;AACD,OAFD,MAEO;AACLF,QAAAA,eAAe,CAACE,iBAAhB,GAAoC,QAApC;AACD;;AACD,UAAIzB,OAAJ,aAAIA,OAAJ,eAAIA,OAAO,CAAE0B,OAAb,EAAsB;AACpBH,QAAAA,eAAe,CAACG,OAAhB,GAA0B1B,OAA1B,aAA0BA,OAA1B,uBAA0BA,OAAO,CAAE0B,OAAnC;AACD,OAFD,MAEO;AACLH,QAAAA,eAAe,CAACG,OAAhB,GAA0B,GAA1B;AACD;;AACD,
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["NativeModules","NativeEventEmitter","Platform","uuidv4","VideoCompressEventEmitter","VideoCompressor","NativeVideoCompressor","backgroundUpload","url","fileUrl","options","onProgress","uuid","subscription","addListener","event","data","written","total","OS","includes","replace","result","upload","method","httpMethod","headers","remove","cancelCompression","cancellationId","Video","compress","progress","modifiedOptions","bitrate","compressionMethod","maxSize","minimumFileSizeForCompress","undefined","getCancellationId","activateBackgroundTask","on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EventEmitter,\n Platform,\n NativeEventSubscription,\n} from 'react-native';\nimport { uuidv4 } from '../utils';\n\nexport declare enum FileSystemUploadType {\n BINARY_CONTENT = 0,\n MULTIPART = 1,\n}\n\nexport declare type FileSystemAcceptedUploadHttpMethod =\n | 'POST'\n | 'PUT'\n | 'PATCH';\nexport type compressionMethod = 'auto' | 'manual';\ntype videoCompresssionType = {\n bitrate?: number;\n maxSize?: number;\n compressionMethod?: compressionMethod;\n minimumFileSizeForCompress?: number;\n getCancellationId?: (cancellationId: string) => void;\n};\n\nexport declare enum FileSystemSessionType {\n BACKGROUND = 0,\n FOREGROUND = 1,\n}\n\nexport declare type HTTPResponse = {\n status: number;\n headers: Record<string, string>;\n body: string;\n};\n\nexport declare type FileSystemUploadOptions = (\n | {\n uploadType?: FileSystemUploadType.BINARY_CONTENT;\n }\n | {\n uploadType: FileSystemUploadType.MULTIPART;\n fieldName?: string;\n mimeType?: string;\n parameters?: Record<string, string>;\n }\n) & {\n headers?: Record<string, string>;\n httpMethod?: FileSystemAcceptedUploadHttpMethod;\n sessionType?: FileSystemSessionType;\n};\n\nexport type VideoCompressorType = {\n compress(\n fileUrl: string,\n options?: videoCompresssionType,\n onProgress?: (progress: number) => void\n ): Promise<string>;\n cancelCompression(cancellationId: string): void;\n backgroundUpload(\n url: string,\n fileUrl: string,\n options: FileSystemUploadOptions,\n onProgress?: (writtem: number, total: number) => void\n ): Promise<any>;\n activateBackgroundTask(onExpired?: (data: any) => void): Promise<any>;\n deactivateBackgroundTask(): Promise<any>;\n};\n\nconst VideoCompressEventEmitter = new NativeEventEmitter(\n NativeModules.VideoCompressor\n);\n\nconst NativeVideoCompressor = NativeModules.VideoCompressor;\n\nexport const backgroundUpload = async (\n url: string,\n fileUrl: string,\n options: FileSystemUploadOptions,\n onProgress?: (writtem: number, total: number) => void\n): Promise<any> => {\n const uuid = uuidv4();\n let subscription: 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\nexport const cancelCompression = (cancellationId: string) => {\n return NativeVideoCompressor.cancelCompression(cancellationId);\n};\n\nconst Video: VideoCompressorType = {\n compress: async (\n fileUrl: string,\n options?: videoCompresssionType,\n onProgress?: (progress: number) => void\n ) => {\n const uuid = uuidv4();\n let subscription: 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 !== undefined) {\n modifiedOptions.minimumFileSizeForCompress =\n options?.minimumFileSizeForCompress;\n }\n if (options?.getCancellationId) {\n options?.getCancellationId(uuid);\n }\n const result = await NativeVideoCompressor.compress(\n fileUrl,\n modifiedOptions\n );\n return result;\n } finally {\n // @ts-ignore\n if (subscription) {\n subscription.remove();\n }\n }\n },\n backgroundUpload,\n cancelCompression,\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"]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import Video, { VideoCompressorType, backgroundUpload } from './Video';
|
|
2
2
|
import Audio from './Audio';
|
|
3
3
|
import Image from './Image';
|
|
4
|
-
import { getDetails, uuidv4 } from './utils';
|
|
4
|
+
import { getDetails, uuidv4, generateFilePath, getRealPath } from './utils';
|
|
5
5
|
export { Video, Audio, Image, backgroundUpload //type
|
|
6
|
-
, VideoCompressorType, getDetails, uuidv4 };
|
|
6
|
+
, VideoCompressorType, getDetails, uuidv4, generateFilePath, getRealPath };
|
|
7
7
|
export default {
|
|
8
8
|
Video,
|
|
9
9
|
Audio,
|
|
10
10
|
Image,
|
|
11
11
|
backgroundUpload,
|
|
12
12
|
getDetails,
|
|
13
|
-
uuidv4
|
|
13
|
+
uuidv4,
|
|
14
|
+
generateFilePath,
|
|
15
|
+
getRealPath
|
|
14
16
|
};
|
|
15
17
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["Video","VideoCompressorType","backgroundUpload","Audio","Image","getDetails","uuidv4"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,mBAAhB,EAAqCC,gBAArC,QAA6D,SAA7D;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,SAASC,UAAT,EAAqBC,MAArB,
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["Video","VideoCompressorType","backgroundUpload","Audio","Image","getDetails","uuidv4","generateFilePath","getRealPath"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,mBAAhB,EAAqCC,gBAArC,QAA6D,SAA7D;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,SAASC,UAAT,EAAqBC,MAArB,EAA6BC,gBAA7B,EAA+CC,WAA/C,QAAkE,SAAlE;AAEA,SACER,KADF,EAEEG,KAFF,EAGEC,KAHF,EAIEF,gBAJF,CAKE;AALF,EAMED,mBANF,EAOEI,UAPF,EAQEC,MARF,EASEC,gBATF,EAUEC,WAVF;AAYA,eAAe;AACbR,EAAAA,KADa;AAEbG,EAAAA,KAFa;AAGbC,EAAAA,KAHa;AAIbF,EAAAA,gBAJa;AAKbG,EAAAA,UALa;AAMbC,EAAAA,MANa;AAObC,EAAAA,gBAPa;AAQbC,EAAAA;AARa,CAAf","sourcesContent":["import Video, { VideoCompressorType, backgroundUpload } from './Video';\nimport Audio from './Audio';\nimport Image from './Image';\nimport { getDetails, uuidv4, generateFilePath, getRealPath } from './utils';\n\nexport {\n Video,\n Audio,\n Image,\n backgroundUpload,\n //type\n VideoCompressorType,\n getDetails,\n uuidv4,\n generateFilePath,\n getRealPath,\n};\nexport default {\n Video,\n Audio,\n Image,\n backgroundUpload,\n getDetails,\n uuidv4,\n generateFilePath,\n getRealPath,\n};\n"]}
|
|
@@ -12,12 +12,14 @@ export const DEFAULT_COMPRESS_AUDIO_OPTIONS = {
|
|
|
12
12
|
quality: 'medium',
|
|
13
13
|
outputFilePath: ''
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
const generateFile = extension => {
|
|
15
|
+
export const generateFilePath = extension => {
|
|
17
16
|
return new Promise((resolve, reject) => {
|
|
18
|
-
Compressor.
|
|
17
|
+
Compressor.generateFilePath(extension).then(result => resolve('file://' + result)).catch(error => reject(error));
|
|
19
18
|
});
|
|
20
19
|
};
|
|
20
|
+
export const getRealPath = (path, type = '') => {
|
|
21
|
+
return Compressor.getRealPath(path, type);
|
|
22
|
+
};
|
|
21
23
|
|
|
22
24
|
const isValidUrl = url => /^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/.test(url);
|
|
23
25
|
|
|
@@ -107,7 +109,7 @@ export const checkUrlAndOptions = async (url, options) => {
|
|
|
107
109
|
outputFilePath = options.outputFilePath;
|
|
108
110
|
defaultResult.outputFilePath = outputFilePath;
|
|
109
111
|
} else {
|
|
110
|
-
outputFilePath = await
|
|
112
|
+
outputFilePath = await generateFilePath('mp3');
|
|
111
113
|
defaultResult.outputFilePath = outputFilePath;
|
|
112
114
|
}
|
|
113
115
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["NativeModules","Compressor","AUDIO_BITRATE","INCORRECT_INPUT_PATH","INCORRECT_OUTPUT_PATH","ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE","DEFAULT_COMPRESS_AUDIO_OPTIONS","bitrate","quality","outputFilePath","generateFile","extension","Promise","resolve","reject","then","result","catch","error","isValidUrl","url","test","getFullFilename","path","_path","includes","length","substring","array","split","isFileNameError","filename","getFilename","fullFilename","slice","join","isRemoteMedia","getDetails","mediaFullPath","extesnion","Error","mediaInfo","JSON","parse","mediaInformation","getMediaProperties","bit_rate","size","Number","format","e","checkUrlAndOptions","options","defaultResult","isCorrect","message","undefined","uuidv4","replace","c","r","parseFloat","Math","random","toString","Date","getTime","v"],"mappings":"AAAA;AACA,SAASA,aAAT,QAA8B,cAA9B;AACA,MAAM;AAAEC,EAAAA;AAAF,IAAiBD,aAAvB;AACA,OAAO,MAAME,aAAa,GAAG,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,EAAgB,GAAhB,EAAqB,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,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EpBC,wCAFJ;AAGD;AACF,GAhBD,CAgBE,OAAO6C,CAAP,EAAU;AACVG,IAAAA,aAAa,CAACC,SAAd,GAA0B,KAA1B;AACAD,IAAAA,aAAa,CAACE,OAAd,GAAwBH,OAAO,CAAC3C,cAAR,GACpBL,qBADoB,GAEpBC,wCAFJ;AAGD,GArBD,SAqBU;AACR,WAAOgD,aAAP;AACD;AACF,CAzCM;AA2CP,OAAO,MAAMI,MAAM,GAAG,MAAM;AAC1B,SAAO,uCAAuCC,OAAvC,CAA+C,OAA/C,EAAwD,UAAUC,CAAV,EAAa;AAC1E,UAAMC,CAAC,GACFC,UAAU,CACT,OACEC,IAAI,CAACC,MAAL,GAAcC,QAAd,GAAyBN,OAAzB,CAAiC,IAAjC,EAAuC,EAAvC,CADF,GAEE,IAAIO,IAAJ,GAAWC,OAAX,EAHO,CAAV,GAKC,EALF,GAMA,CAPJ;AAAA,UAQE;AACAC,IAAAA,CAAC,GAAGR,CAAC,IAAI,GAAL,GAAWC,CAAX,GAAgBA,CAAC,GAAG,GAAL,GAAY,GATjC;AAUA,WAAOO,CAAC,CAACH,QAAF,CAAW,EAAX,CAAP;AACD,GAZM,CAAP;AAaD,CAdM","sourcesContent":["/* eslint-disable no-bitwise */\nimport { NativeModules } from 'react-native';\nconst { Compressor } = NativeModules;\nexport const AUDIO_BITRATE = [256, 192, 160, 128, 96, 64, 32];\ntype qualityType = 'low' | 'medium' | 'high';\nconst INCORRECT_INPUT_PATH = 'Incorrect input path. Please provide a valid one';\nconst INCORRECT_OUTPUT_PATH =\n 'Incorrect output path. Please provide a valid one';\nconst ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE =\n 'An error occur while generating output file';\ntype audioCompresssionType = {\n bitrate?: number;\n quality: qualityType;\n outputFilePath?: string | undefined | null;\n};\n\nexport type defaultResultType = {\n outputFilePath: string | undefined | null;\n isCorrect: boolean;\n message: string;\n};\n\nexport const DEFAULT_COMPRESS_AUDIO_OPTIONS: audioCompresssionType = {\n bitrate: 96,\n quality: 'medium',\n outputFilePath: '',\n};\n\nexport type AudioType = {\n compress(value: string, options?: audioCompresssionType): Promise<string>;\n};\n\nconst generateFile: any = (extension: string) => {\n return new Promise((resolve, reject) => {\n Compressor.generateFile(extension)\n .then((result: any) => resolve('file://' + result))\n .catch((error: any) => reject(error));\n });\n};\n\nconst isValidUrl = (url: string) =>\n /^(?:\\w+:)?\\/\\/([^\\s\\.]+\\.\\S{2}|localhost[\\:?\\d]*)\\S*$/.test(url);\n\nconst getFullFilename = (path: string | null) => {\n if (typeof path === 'string') {\n let _path = path;\n\n // In case of remote media, check if the url would be valid one\n if (path.includes('http') && !isValidUrl(path)) {\n return INCORRECT_INPUT_PATH;\n }\n\n // In case of url, check if it ends with \"/\" and do not consider it furthermore\n if (_path[_path.length - 1] === '/')\n _path = _path.substring(0, path.length - 1);\n\n const array = _path.split('/');\n return array.length > 1 ? array[array.length - 1] : INCORRECT_INPUT_PATH;\n }\n return INCORRECT_INPUT_PATH;\n};\n\nconst isFileNameError = (filename: string) => {\n return filename === INCORRECT_INPUT_PATH;\n};\n\nconst getFilename = (path: string | null) => {\n const fullFilename = getFullFilename(path);\n if (!isFileNameError(fullFilename)) {\n const array = fullFilename.split('.');\n return array.length > 1 ? array.slice(0, -1).join('') : array.join('');\n }\n return fullFilename;\n};\n\nconst isRemoteMedia = (path: string | null) => {\n return typeof path === 'string' ? path.split(':/')[0].includes('http') : null;\n};\n\nexport const getDetails = (\n mediaFullPath: string,\n extesnion: 'mp3' | 'mp4' = 'mp3'\n): Promise<any | null> => {\n return new Promise(async (resolve, reject) => {\n try {\n // Since we used \"-v error\", a work around is to call first this command before the following\n const result: any = {};\n if (result !== 0) {\n throw new Error('Failed to execute command');\n }\n\n // get the output result of the command\n // example of output {\"programs\": [], \"streams\": [{\"width\": 640,\"height\": 360}], \"format\": {\"size\": \"15804433\"}}\n let mediaInfo: any = await {};\n mediaInfo = JSON.parse(mediaInfo);\n\n // execute second command\n const mediaInformation: any = await {};\n\n // treat both results\n mediaInformation.filename = getFilename(mediaFullPath);\n mediaInformation.bitrate = mediaInformation.getMediaProperties().bit_rate;\n mediaInformation.extension = extesnion;\n mediaInformation.isRemoteMedia = isRemoteMedia(mediaFullPath);\n mediaInformation.size = Number(mediaInfo.format.size);\n\n resolve(mediaInformation);\n } catch (e) {\n reject(e);\n }\n });\n};\n\nexport const checkUrlAndOptions = async (\n url: string,\n options: audioCompresssionType\n): Promise<defaultResultType> => {\n if (!url) {\n throw new Error(\n 'Compression url is empty, please provide a url for compression.'\n );\n }\n const defaultResult: defaultResultType = {\n outputFilePath: '',\n isCorrect: true,\n message: '',\n };\n\n // Check if output file is correct\n let outputFilePath: string | undefined | null;\n try {\n // use default output file\n // or use new file from cache folder\n if (options.outputFilePath) {\n outputFilePath = options.outputFilePath;\n defaultResult.outputFilePath = outputFilePath;\n } else {\n outputFilePath = await generateFile('mp3');\n defaultResult.outputFilePath = outputFilePath;\n }\n if (outputFilePath === undefined || outputFilePath === null) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n }\n } catch (e) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n } finally {\n return defaultResult;\n }\n};\n\nexport const uuidv4 = () => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {\n const r =\n (parseFloat(\n '0.' +\n Math.random().toString().replace('0.', '') +\n new Date().getTime()\n ) *\n 16) |\n 0,\n // eslint-disable-next-line eqeqeq\n v = c == 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["NativeModules","Compressor","AUDIO_BITRATE","INCORRECT_INPUT_PATH","INCORRECT_OUTPUT_PATH","ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE","DEFAULT_COMPRESS_AUDIO_OPTIONS","bitrate","quality","outputFilePath","generateFilePath","extension","Promise","resolve","reject","then","result","catch","error","getRealPath","path","type","isValidUrl","url","test","getFullFilename","_path","includes","length","substring","array","split","isFileNameError","filename","getFilename","fullFilename","slice","join","isRemoteMedia","getDetails","mediaFullPath","extesnion","Error","mediaInfo","JSON","parse","mediaInformation","getMediaProperties","bit_rate","size","Number","format","e","checkUrlAndOptions","options","defaultResult","isCorrect","message","undefined","uuidv4","replace","c","r","parseFloat","Math","random","toString","Date","getTime","v"],"mappings":"AAAA;AACA,SAASA,aAAT,QAA8B,cAA9B;AACA,MAAM;AAAEC,EAAAA;AAAF,IAAiBD,aAAvB;AACA,OAAO,MAAME,aAAa,GAAG,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX,EAAgB,GAAhB,EAAqB,EAArB,EAAyB,EAAzB,EAA6B,EAA7B,CAAtB;AAEP,MAAMC,oBAAoB,GAAG,kDAA7B;AACA,MAAMC,qBAAqB,GACzB,mDADF;AAEA,MAAMC,wCAAwC,GAC5C,6CADF;AAcA,OAAO,MAAMC,8BAAqD,GAAG;AACnEC,EAAAA,OAAO,EAAE,EAD0D;AAEnEC,EAAAA,OAAO,EAAE,QAF0D;AAGnEC,EAAAA,cAAc,EAAE;AAHmD,CAA9D;AAUP,OAAO,MAAMC,gBAAqB,GAAIC,SAAD,IAAuB;AAC1D,SAAO,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;AACtCb,IAAAA,UAAU,CAACS,gBAAX,CAA4BC,SAA5B,EACGI,IADH,CACSC,MAAD,IAAiBH,OAAO,CAAC,YAAYG,MAAb,CADhC,EAEGC,KAFH,CAEUC,KAAD,IAAgBJ,MAAM,CAACI,KAAD,CAF/B;AAGD,GAJM,CAAP;AAKD,CANM;AAQP,OAAO,MAAMC,WAAgB,GAAG,CAACC,IAAD,EAAeC,IAAY,GAA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OAAvC,CAA+C,OAA/C,EAAwD,UAAUC,CAAV,EAAa;AAC1E,UAAMC,CAAC,GACFC,UAAU,CACT,OACEC,IAAI,CAACC,MAAL,GAAcC,QAAd,GAAyBN,OAAzB,CAAiC,IAAjC,EAAuC,EAAvC,CADF,GAEE,IAAIO,IAAJ,GAAWC,OAAX,EAHO,CAAV,GAKC,EALF,GAMA,CAPJ;AAAA,UAQE;AACAC,IAAAA,CAAC,GAAGR,CAAC,IAAI,GAAL,GAAWC,CAAX,GAAgBA,CAAC,GAAG,GAAL,GAAY,GATjC;AAUA,WAAOO,CAAC,CAACH,QAAF,CAAW,EAAX,CAAP;AACD,GAZM,CAAP;AAaD,CAdM","sourcesContent":["/* eslint-disable no-bitwise */\nimport { NativeModules } from 'react-native';\nconst { Compressor } = NativeModules;\nexport const AUDIO_BITRATE = [256, 192, 160, 128, 96, 64, 32];\ntype qualityType = 'low' | 'medium' | 'high';\nconst INCORRECT_INPUT_PATH = 'Incorrect input path. Please provide a valid one';\nconst INCORRECT_OUTPUT_PATH =\n 'Incorrect output path. Please provide a valid one';\nconst ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE =\n 'An error occur while generating output file';\ntype audioCompresssionType = {\n bitrate?: number;\n quality: qualityType;\n outputFilePath?: string | undefined | null;\n};\n\nexport type defaultResultType = {\n outputFilePath: string | undefined | null;\n isCorrect: boolean;\n message: string;\n};\n\nexport const DEFAULT_COMPRESS_AUDIO_OPTIONS: audioCompresssionType = {\n bitrate: 96,\n quality: 'medium',\n outputFilePath: '',\n};\n\nexport type AudioType = {\n compress(value: string, options?: audioCompresssionType): Promise<string>;\n};\n\nexport const generateFilePath: any = (extension: string) => {\n return new Promise((resolve, reject) => {\n Compressor.generateFilePath(extension)\n .then((result: any) => resolve('file://' + result))\n .catch((error: any) => reject(error));\n });\n};\n\nexport const getRealPath: any = (path: string, type: string = '') => {\n return Compressor.getRealPath(path, type);\n};\n\nconst isValidUrl = (url: string) =>\n /^(?:\\w+:)?\\/\\/([^\\s\\.]+\\.\\S{2}|localhost[\\:?\\d]*)\\S*$/.test(url);\n\nconst getFullFilename = (path: string | null) => {\n if (typeof path === 'string') {\n let _path = path;\n\n // In case of remote media, check if the url would be valid one\n if (path.includes('http') && !isValidUrl(path)) {\n return INCORRECT_INPUT_PATH;\n }\n\n // In case of url, check if it ends with \"/\" and do not consider it furthermore\n if (_path[_path.length - 1] === '/')\n _path = _path.substring(0, path.length - 1);\n\n const array = _path.split('/');\n return array.length > 1 ? array[array.length - 1] : INCORRECT_INPUT_PATH;\n }\n return INCORRECT_INPUT_PATH;\n};\n\nconst isFileNameError = (filename: string) => {\n return filename === INCORRECT_INPUT_PATH;\n};\n\nconst getFilename = (path: string | null) => {\n const fullFilename = getFullFilename(path);\n if (!isFileNameError(fullFilename)) {\n const array = fullFilename.split('.');\n return array.length > 1 ? array.slice(0, -1).join('') : array.join('');\n }\n return fullFilename;\n};\n\nconst isRemoteMedia = (path: string | null) => {\n return typeof path === 'string' ? path.split(':/')[0].includes('http') : null;\n};\n\nexport const getDetails = (\n mediaFullPath: string,\n extesnion: 'mp3' | 'mp4' = 'mp3'\n): Promise<any | null> => {\n return new Promise(async (resolve, reject) => {\n try {\n // Since we used \"-v error\", a work around is to call first this command before the following\n const result: any = {};\n if (result !== 0) {\n throw new Error('Failed to execute command');\n }\n\n // get the output result of the command\n // example of output {\"programs\": [], \"streams\": [{\"width\": 640,\"height\": 360}], \"format\": {\"size\": \"15804433\"}}\n let mediaInfo: any = await {};\n mediaInfo = JSON.parse(mediaInfo);\n\n // execute second command\n const mediaInformation: any = await {};\n\n // treat both results\n mediaInformation.filename = getFilename(mediaFullPath);\n mediaInformation.bitrate = mediaInformation.getMediaProperties().bit_rate;\n mediaInformation.extension = extesnion;\n mediaInformation.isRemoteMedia = isRemoteMedia(mediaFullPath);\n mediaInformation.size = Number(mediaInfo.format.size);\n\n resolve(mediaInformation);\n } catch (e) {\n reject(e);\n }\n });\n};\n\nexport const checkUrlAndOptions = async (\n url: string,\n options: audioCompresssionType\n): Promise<defaultResultType> => {\n if (!url) {\n throw new Error(\n 'Compression url is empty, please provide a url for compression.'\n );\n }\n const defaultResult: defaultResultType = {\n outputFilePath: '',\n isCorrect: true,\n message: '',\n };\n\n // Check if output file is correct\n let outputFilePath: string | undefined | null;\n try {\n // use default output file\n // or use new file from cache folder\n if (options.outputFilePath) {\n outputFilePath = options.outputFilePath;\n defaultResult.outputFilePath = outputFilePath;\n } else {\n outputFilePath = await generateFilePath('mp3');\n defaultResult.outputFilePath = outputFilePath;\n }\n if (outputFilePath === undefined || outputFilePath === null) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n }\n } catch (e) {\n defaultResult.isCorrect = false;\n defaultResult.message = options.outputFilePath\n ? INCORRECT_OUTPUT_PATH\n : ERROR_OCCUR_WHILE_GENERATING_OUTPUT_FILE;\n } finally {\n return defaultResult;\n }\n};\n\nexport const uuidv4 = () => {\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {\n const r =\n (parseFloat(\n '0.' +\n Math.random().toString().replace('0.', '') +\n new Date().getTime()\n ) *\n 16) |\n 0,\n // eslint-disable-next-line eqeqeq\n v = c == 'x' ? r : (r & 0x3) | 0x8;\n return v.toString(16);\n });\n};\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import Video, { VideoCompressorType, backgroundUpload } from './Video';
|
|
2
2
|
import Audio from './Audio';
|
|
3
3
|
import Image from './Image';
|
|
4
|
-
import { getDetails, uuidv4 } from './utils';
|
|
5
|
-
export { Video, Audio, Image, backgroundUpload, VideoCompressorType, getDetails, uuidv4, };
|
|
4
|
+
import { getDetails, uuidv4, generateFilePath, getRealPath } from './utils';
|
|
5
|
+
export { Video, Audio, Image, backgroundUpload, VideoCompressorType, getDetails, uuidv4, generateFilePath, getRealPath, };
|
|
6
6
|
declare const _default: {
|
|
7
7
|
Video: VideoCompressorType;
|
|
8
8
|
Audio: import("./utils").AudioType;
|
|
@@ -12,5 +12,7 @@ declare const _default: {
|
|
|
12
12
|
backgroundUpload: (url: string, fileUrl: string, options: import("./Video").FileSystemUploadOptions, onProgress?: ((writtem: number, total: number) => void) | undefined) => Promise<any>;
|
|
13
13
|
getDetails: (mediaFullPath: string, extesnion?: "mp3" | "mp4") => Promise<any>;
|
|
14
14
|
uuidv4: () => string;
|
|
15
|
+
generateFilePath: any;
|
|
16
|
+
getRealPath: any;
|
|
15
17
|
};
|
|
16
18
|
export default _default;
|
|
@@ -14,6 +14,8 @@ export declare const DEFAULT_COMPRESS_AUDIO_OPTIONS: audioCompresssionType;
|
|
|
14
14
|
export declare type AudioType = {
|
|
15
15
|
compress(value: string, options?: audioCompresssionType): Promise<string>;
|
|
16
16
|
};
|
|
17
|
+
export declare const generateFilePath: any;
|
|
18
|
+
export declare const getRealPath: any;
|
|
17
19
|
export declare const getDetails: (mediaFullPath: string, extesnion?: 'mp3' | 'mp4') => Promise<any | null>;
|
|
18
20
|
export declare const checkUrlAndOptions: (url: string, options: audioCompresssionType) => Promise<defaultResultType>;
|
|
19
21
|
export declare const uuidv4: () => string;
|
package/package.json
CHANGED
package/src/Video/index.tsx
CHANGED
|
@@ -152,7 +152,7 @@ const Video: VideoCompressorType = {
|
|
|
152
152
|
} else {
|
|
153
153
|
modifiedOptions.maxSize = 640;
|
|
154
154
|
}
|
|
155
|
-
if (options?.minimumFileSizeForCompress) {
|
|
155
|
+
if (options?.minimumFileSizeForCompress !== undefined) {
|
|
156
156
|
modifiedOptions.minimumFileSizeForCompress =
|
|
157
157
|
options?.minimumFileSizeForCompress;
|
|
158
158
|
}
|
package/src/index.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Video, { VideoCompressorType, backgroundUpload } from './Video';
|
|
2
2
|
import Audio from './Audio';
|
|
3
3
|
import Image from './Image';
|
|
4
|
-
import { getDetails, uuidv4 } from './utils';
|
|
4
|
+
import { getDetails, uuidv4, generateFilePath, getRealPath } from './utils';
|
|
5
5
|
|
|
6
6
|
export {
|
|
7
7
|
Video,
|
|
@@ -12,6 +12,8 @@ export {
|
|
|
12
12
|
VideoCompressorType,
|
|
13
13
|
getDetails,
|
|
14
14
|
uuidv4,
|
|
15
|
+
generateFilePath,
|
|
16
|
+
getRealPath,
|
|
15
17
|
};
|
|
16
18
|
export default {
|
|
17
19
|
Video,
|
|
@@ -20,4 +22,6 @@ export default {
|
|
|
20
22
|
backgroundUpload,
|
|
21
23
|
getDetails,
|
|
22
24
|
uuidv4,
|
|
25
|
+
generateFilePath,
|
|
26
|
+
getRealPath,
|
|
23
27
|
};
|
package/src/utils/index.tsx
CHANGED
|
@@ -30,14 +30,18 @@ export type AudioType = {
|
|
|
30
30
|
compress(value: string, options?: audioCompresssionType): Promise<string>;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
const
|
|
33
|
+
export const generateFilePath: any = (extension: string) => {
|
|
34
34
|
return new Promise((resolve, reject) => {
|
|
35
|
-
Compressor.
|
|
35
|
+
Compressor.generateFilePath(extension)
|
|
36
36
|
.then((result: any) => resolve('file://' + result))
|
|
37
37
|
.catch((error: any) => reject(error));
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
+
export const getRealPath: any = (path: string, type: string = '') => {
|
|
42
|
+
return Compressor.getRealPath(path, type);
|
|
43
|
+
};
|
|
44
|
+
|
|
41
45
|
const isValidUrl = (url: string) =>
|
|
42
46
|
/^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/.test(url);
|
|
43
47
|
|
|
@@ -135,7 +139,7 @@ export const checkUrlAndOptions = async (
|
|
|
135
139
|
outputFilePath = options.outputFilePath;
|
|
136
140
|
defaultResult.outputFilePath = outputFilePath;
|
|
137
141
|
} else {
|
|
138
|
-
outputFilePath = await
|
|
142
|
+
outputFilePath = await generateFilePath('mp3');
|
|
139
143
|
defaultResult.outputFilePath = outputFilePath;
|
|
140
144
|
}
|
|
141
145
|
if (outputFilePath === undefined || outputFilePath === null) {
|