react-native-compressor 1.3.2 → 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 +60 -2
- package/android/.gradle/6.1.1/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/6.1.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/6.1.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/6.1.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +1 -1
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/build.gradle +1 -5
- package/android/src/main/java/com/.DS_Store +0 -0
- package/android/src/main/java/com/reactnativecompressor/.DS_Store +0 -0
- package/android/src/main/java/com/reactnativecompressor/Audio/AudioCompressor.java +0 -1
- package/android/src/main/java/com/reactnativecompressor/CompressorModule.java +14 -2
- package/android/src/main/java/com/reactnativecompressor/Utils/RealPathUtil.java +210 -0
- package/android/src/main/java/com/reactnativecompressor/Utils/Utils.java +30 -6
- package/android/src/main/java/com/reactnativecompressor/Video/AutoVideoCompression/AutoVideoCompression.java +3 -37
- package/android/src/main/java/com/reactnativecompressor/Video/VideoCompressorHelper.java +2 -38
- package/android/src/main/java/com/reactnativecompressor/Video/VideoModule.java +23 -15
- package/ios/.DS_Store +0 -0
- package/ios/Compressor-Bridging-Header.h +1 -1
- package/ios/Compressor.m +39 -12
- package/ios/Image/ImageCompressor.h +2 -0
- package/ios/Image/ImageCompressor.m +152 -1
- package/ios/Video/VideoCompressor.swift +57 -47
- package/lib/commonjs/Audio/index.js.map +1 -1
- package/lib/commonjs/Video/index.js +13 -2
- 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/Audio/index.js.map +1 -1
- package/lib/module/Video/index.js +9 -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/Video/index.d.ts +3 -0
- package/lib/typescript/index.d.ts +4 -2
- package/lib/typescript/utils/index.d.ts +2 -0
- package/package.json +2 -1
- package/src/Audio/index.tsx +1 -1
- package/src/Video/index.tsx +12 -7
- package/src/index.tsx +5 -1
- package/src/utils/index.tsx +7 -3
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
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,GAAIC,IAAD,IAAyB;AAC/C,MAAI,OAAOA,IAAP,KAAgB,QAApB,EAA8B;AAC5B,QAAIC,KAAK,GAAGD,IAAZ,CAD4B,CAG5B;;AACA,QAAIA,IAAI,CA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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,EAAgB,GAAhB,EAAqB,EAArB,EAAyB,EAAzB,EAA6B,EAA7B,CAAtB;;AAEP,MAAMC,oBAAoB,GAAG,kDAA7B;AACA,MAAMC,qBAAqB,GACzB,mDADF;AAE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Ad,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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["NativeModules","AUDIO_BITRATE","DEFAULT_COMPRESS_AUDIO_OPTIONS","checkUrlAndOptions","NativeAudio","Compressor","Audio","compress","url","options","checkUrlAndOptionsResult","isCorrect","message","mediaDetails","bitrate","i","length","quality","compress_audio","error"],"mappings":"AAAA,SAASA,aAAT,QAA8B,cAA9B;AACA,SACEC,aADF,EAGEC,8BAHF,EAKEC,kBALF,QAMO,UANP;AAOA,MAAMC,WAAW,GAAGJ,aAAa,CAACK,UAAlC;AAEA,MAAMC,KAAgB,GAAG;AACvBC,EAAAA,QAAQ,EAAE,OAAOC,GAAP,EAAYC,OAAO,GAAGP,8BAAtB,KAAyD;AACjE,QAAI;AACF,YAAMQ,wBAA2C,GAC/C,MAAMP,kBAAkB,CAACK,GAAD,EAAMC,OAAN,CAD1B;;AAEA,UAAI,CAACC,wBAAwB,CAACC,SAA9B,EAAyC;AACvC,cAAMD,wBAAwB,CAACE,OAA/B;AACD,OAFD,MAEO;AACL;AAEA;AACA;AACA,cAAMC,YAAiB,GAAG;AACxBC,UAAAA,OAAO,EAAE;AADe,SAA1B,CALK,CASL;;AACA,YAAIA,OAAY,GAAGZ,8BAA8B,CAACY,OAAlD;;AAEA,YAAID,YAAY,IAAIA,YAAY,CAACC,OAAjC,EAA0C;AACxC;AACA,eAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGd,aAAa,CAACe,MAAlC,EAA0CD,CAAC,EAA3C,EAA+C;AAC7C;AACA,gBAAIF,YAAY,CAACC,OAAb,GAAuBb,aAAa,CAACc,CAAD,CAAxC,EAA6C;AAC3C,kBAAIA,CAAC,GAAG,CAAJ,GAAQd,aAAa,CAACe,MAA1B,EAAkC;AAChC,oBAAIP,OAAO,CAACQ,OAAR,KAAoB,KAAxB,EAA+BH,OAAO,GAAGb,aAAa,CAACc,CAAC,GAAG,CAAL,CAAvB,CAA/B,KACK,IAAIN,OAAO,CAACQ,OAAR,KAAoB,QAAxB,EACHH,OAAO,GAAGb,aAAa,CAACc,CAAC,GAAG,CAAL,CAAvB,CADG,KAEAD,OAAO,GAAGb,aAAa,CAACc,CAAD,CAAvB;AACN,eALD,MAKO,IAAIA,CAAC,GAAG,CAAJ,GAAQd,aAAa,CAACe,MAA1B,EAAkC;AACvC,oBAAIP,OAAO,CAACQ,OAAR,KAAoB,KAAxB,EAA+BH,OAAO,GAAGb,aAAa,CAACc,CAAC,GAAG,CAAL,CAAvB,CAA/B,KACKD,OAAO,GAAGb,aAAa,CAACc,CAAD,CAAvB;AACN,eAHM,MAGAD,OAAO,GAAGb,aAAa,CAACc,CAAD,CAAvB;;AACP;AACD,aAb4C,CAe7C;;;AACA,gBACEF,YAAY,CAACC,OAAb,IAAwBb,aAAa,CAACA,aAAa,CAACe,MAAd,GAAuB,CAAxB,CADvC,EAEE;AACAF,cAAAA,OAAO,GAAGb,aAAa,CAACA,aAAa,CAACe,MAAd,GAAuB,CAAxB,CAAvB;AACA;AACD;AACF;AACF;;AAED,eAAOZ,WAAW,CAACc,cAAZ,CAA2BV,GAA3B,EAAgC;AACrCM,UAAAA,OADqC;AAErCG,UAAAA,OAAO,EAAER,OAAO,CAACQ;AAFoB,SAAhC,CAAP;AAID;AACF,KAjDD,CAiDE,OAAOE,KAAP,
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["NativeModules","AUDIO_BITRATE","DEFAULT_COMPRESS_AUDIO_OPTIONS","checkUrlAndOptions","NativeAudio","Compressor","Audio","compress","url","options","checkUrlAndOptionsResult","isCorrect","message","mediaDetails","bitrate","i","length","quality","compress_audio","error"],"mappings":"AAAA,SAASA,aAAT,QAA8B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AoB,KAAxB,EAA+BH,OAAO,GAAGb,aAAa,CAACc,CAAC,GAAG,CAAL,CAAvB,CAA/B,KACKD,OAAO,GAAGb,aAAa,CAACc,CAAD,CAAvB;AACN,eAHM,MAGAD,OAAO,GAAGb,aAAa,CAACc,CAAD,CAAvB;;AACP;AACD,aAb4C,CAe7C;;;AACA,gBACEF,YAAY,CAACC,OAAb,IAAwBb,aAAa,CAACA,aAAa,CAACe,MAAd,GAAuB,CAAxB,CADvC,EAEE;AACAF,cAAAA,OAAO,GAAGb,aAAa,CAACA,aAAa,CAACe,MAAd,GAAuB,CAAxB,CAAvB;AACA;AACD;AACF;AACF;;AAED,eAAOZ,WAAW,CAACc,cAAZ,CAA2BV,GAA3B,EAAgC;AACrCM,UAAAA,OADqC;AAErCG,UAAAA,OAAO,EAAER,OAAO,CAACQ;AAFoB,SAAhC,CAAP;AAID;AACF,KAjDD,CAiDE,OAAOE,KAAP,EAAmB;AACnB,YAAMA,KAAK,CAACP,OAAZ;AACD;AACF;AAtDsB,CAAzB;AAyDA,eAAeN,KAAf","sourcesContent":["import { NativeModules } from 'react-native';\nimport {\n AUDIO_BITRATE,\n AudioType,\n DEFAULT_COMPRESS_AUDIO_OPTIONS,\n defaultResultType,\n checkUrlAndOptions,\n} from '../utils';\nconst NativeAudio = NativeModules.Compressor;\n\nconst Audio: AudioType = {\n compress: async (url, options = DEFAULT_COMPRESS_AUDIO_OPTIONS) => {\n try {\n const checkUrlAndOptionsResult: defaultResultType =\n await checkUrlAndOptions(url, options);\n if (!checkUrlAndOptionsResult.isCorrect) {\n throw checkUrlAndOptionsResult.message;\n } else {\n // Get resulting output file path\n\n // Get media details\n // const mediaDetails: any = await getDetails(url).catch(() => null);\n const mediaDetails: any = {\n bitrate: 0,\n };\n\n // Initialize bitrate\n let bitrate: any = DEFAULT_COMPRESS_AUDIO_OPTIONS.bitrate;\n\n if (mediaDetails && mediaDetails.bitrate) {\n // Check and return the appropriate bitrate according to quality expected\n for (let i = 0; i < AUDIO_BITRATE.length; i++) {\n // Check a particular bitrate to return its nearest lower according to quality\n if (mediaDetails.bitrate > AUDIO_BITRATE[i]) {\n if (i + 2 < AUDIO_BITRATE.length) {\n if (options.quality === 'low') bitrate = AUDIO_BITRATE[i + 2];\n else if (options.quality === 'medium')\n bitrate = AUDIO_BITRATE[i + 1];\n else bitrate = AUDIO_BITRATE[i];\n } else if (i + 1 < AUDIO_BITRATE.length) {\n if (options.quality === 'low') bitrate = AUDIO_BITRATE[i + 1];\n else bitrate = AUDIO_BITRATE[i];\n } else bitrate = AUDIO_BITRATE[i];\n break;\n }\n\n // Check if the matching bitrate is the last in the array\n if (\n mediaDetails.bitrate <= AUDIO_BITRATE[AUDIO_BITRATE.length - 1]\n ) {\n bitrate = AUDIO_BITRATE[AUDIO_BITRATE.length - 1];\n break;\n }\n }\n }\n\n return NativeAudio.compress_audio(url, {\n bitrate,\n quality: options.quality,\n });\n }\n } catch (error: any) {\n throw error.message;\n }\n },\n};\n\nexport default Audio;\n"]}
|
|
@@ -33,6 +33,9 @@ export const backgroundUpload = async (url, fileUrl, options, onProgress) => {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
|
+
export const cancelCompression = cancellationId => {
|
|
37
|
+
return NativeVideoCompressor.cancelCompression(cancellationId);
|
|
38
|
+
};
|
|
36
39
|
const Video = {
|
|
37
40
|
compress: async (fileUrl, options, onProgress) => {
|
|
38
41
|
const uuid = uuidv4();
|
|
@@ -64,10 +67,14 @@ const Video = {
|
|
|
64
67
|
modifiedOptions.maxSize = 640;
|
|
65
68
|
}
|
|
66
69
|
|
|
67
|
-
if (options
|
|
70
|
+
if ((options === null || options === void 0 ? void 0 : options.minimumFileSizeForCompress) !== undefined) {
|
|
68
71
|
modifiedOptions.minimumFileSizeForCompress = options === null || options === void 0 ? void 0 : options.minimumFileSizeForCompress;
|
|
69
72
|
}
|
|
70
73
|
|
|
74
|
+
if (options !== null && options !== void 0 && options.getCancellationId) {
|
|
75
|
+
options === null || options === void 0 ? void 0 : options.getCancellationId(uuid);
|
|
76
|
+
}
|
|
77
|
+
|
|
71
78
|
const result = await NativeVideoCompressor.compress(fileUrl, modifiedOptions);
|
|
72
79
|
return result;
|
|
73
80
|
} finally {
|
|
@@ -78,6 +85,7 @@ const Video = {
|
|
|
78
85
|
}
|
|
79
86
|
},
|
|
80
87
|
backgroundUpload,
|
|
88
|
+
cancelCompression,
|
|
81
89
|
|
|
82
90
|
activateBackgroundTask(onExpired) {
|
|
83
91
|
if (onExpired) {
|
|
@@ -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","Video","compress","progress","modifiedOptions","bitrate","compressionMethod","maxSize","minimumFileSizeForCompress","activateBackgroundTask","onExpired","deactivateBackgroundTask","removeAllListeners"],"mappings":"AAAA,SACEA,aADF,EAEEC,kBAFF,EAGEC,QAHF,QAKO,cALP;AAMA,SAASC,MAAT,QAAuB,UAAvB;
|
|
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","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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AAE2B,0BADX;AAED;;AACD,UAAI3B,OAAJ,aAAIA,OAAJ,eAAIA,OAAO,CAAE6B,iBAAb,EAAgC;AAC9B7B,QAAAA,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAE6B,iBAAT,CAA2B3B,IAA3B;AACD;;AACD,YAAMU,MAAM,GAAG,MAAMhB,qBAAqB,CAACyB,QAAtB,CACnBtB,OADmB,EAEnBwB,eAFmB,CAArB;AAIA,aAAOX,MAAP;AACD,KAzCD,SAyCU;AACR;AACA,UAAIT,YAAJ,EAAkB;AAChBA,QAAAA,YAAY,CAACc,MAAb;AACD;AACF;AACF,GAvDgC;AAwDjCpB,EAAAA,gBAxDiC;AAyDjCqB,EAAAA,iBAzDiC;;AA0DjCY,EAAAA,sBAAsB,CAACC,SAAD,EAAa;AACjC,QAAIA,SAAJ,EAAe;AACb,YAAM5B,YAAqC,GACzCT,yBAAyB,CAACU,WAA1B,CACE,uBADF,EAEGC,KAAD,IAAgB;AACd0B,QAAAA,SAAS,CAAC1B,KAAD,CAAT;;AACA,YAAIF,YAAJ,EAAkB;AAChBA,UAAAA,YAAY,CAACc,MAAb;AACD;AACF,OAPH,CADF;AAUD;;AACD,WAAOrB,qBAAqB,CAACkC,sBAAtB,CAA6C,EAA7C,CAAP;AACD,GAxEgC;;AAyEjCE,EAAAA,wBAAwB,GAAG;AACzBtC,IAAAA,yBAAyB,CAACuC,kBAA1B,CAA6C,uBAA7C;AACA,WAAOrC,qBAAqB,CAACoC,wBAAtB,CAA+C,EAA/C,CAAP;AACD;;AA5EgC,CAAnC;AA+EA,eAAeZ,KAAf","sourcesContent":["import {\n NativeModules,\n NativeEventEmitter,\n Platform,\n NativeEventSubscription,\n} from 'react-native';\nimport { uuidv4 } from '../utils';\n\nexport declare enum FileSystemUploadType {\n BINARY_CONTENT = 0,\n MULTIPART = 1,\n}\n\nexport declare type FileSystemAcceptedUploadHttpMethod =\n | 'POST'\n | 'PUT'\n | 'PATCH';\nexport type compressionMethod = 'auto' | 'manual';\ntype videoCompresssionType = {\n bitrate?: number;\n maxSize?: number;\n compressionMethod?: compressionMethod;\n minimumFileSizeForCompress?: number;\n 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,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,MA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D,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,GAAG,EAA9B,KAAqC;AACnE,SAAOpB,UAAU,CAACkB,WAAX,CAAuBC,IAAvB,EAA6BC,IAA7B,CAAP;AACD,CAFM;;AAIP,MAAMC,UAAU,GAAIC,GAAD,IACjB,wDAAwDC,IAAxD,CAA6DD,GAA7D,CADF;;AAGA,MAAME,eAAe,GAAIL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AAX,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"]}
|
|
@@ -9,6 +9,7 @@ declare type videoCompresssionType = {
|
|
|
9
9
|
maxSize?: number;
|
|
10
10
|
compressionMethod?: compressionMethod;
|
|
11
11
|
minimumFileSizeForCompress?: number;
|
|
12
|
+
getCancellationId?: (cancellationId: string) => void;
|
|
12
13
|
};
|
|
13
14
|
export declare enum FileSystemSessionType {
|
|
14
15
|
BACKGROUND = 0,
|
|
@@ -33,10 +34,12 @@ export declare type FileSystemUploadOptions = ({
|
|
|
33
34
|
};
|
|
34
35
|
export declare type VideoCompressorType = {
|
|
35
36
|
compress(fileUrl: string, options?: videoCompresssionType, onProgress?: (progress: number) => void): Promise<string>;
|
|
37
|
+
cancelCompression(cancellationId: string): void;
|
|
36
38
|
backgroundUpload(url: string, fileUrl: string, options: FileSystemUploadOptions, onProgress?: (writtem: number, total: number) => void): Promise<any>;
|
|
37
39
|
activateBackgroundTask(onExpired?: (data: any) => void): Promise<any>;
|
|
38
40
|
deactivateBackgroundTask(): Promise<any>;
|
|
39
41
|
};
|
|
40
42
|
export declare const backgroundUpload: (url: string, fileUrl: string, options: FileSystemUploadOptions, onProgress?: ((writtem: number, total: number) => void) | undefined) => Promise<any>;
|
|
43
|
+
export declare const cancelCompression: (cancellationId: string) => any;
|
|
41
44
|
declare const Video: VideoCompressorType;
|
|
42
45
|
export default Video;
|
|
@@ -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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-compressor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "This library compress image, video and audio",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@commitlint/config-conventional": "^11.0.0",
|
|
63
63
|
"@expo/config-plugins": "^4.0.14",
|
|
64
|
+
"@jamesacarr/eslint-formatter-github-actions": "^0.1.0",
|
|
64
65
|
"@react-native-community/eslint-config": "^2.0.0",
|
|
65
66
|
"@release-it/conventional-changelog": "^2.0.0",
|
|
66
67
|
"@types/jest": "^26.0.0",
|
package/src/Audio/index.tsx
CHANGED
package/src/Video/index.tsx
CHANGED
|
@@ -21,6 +21,7 @@ type videoCompresssionType = {
|
|
|
21
21
|
maxSize?: number;
|
|
22
22
|
compressionMethod?: compressionMethod;
|
|
23
23
|
minimumFileSizeForCompress?: number;
|
|
24
|
+
getCancellationId?: (cancellationId: string) => void;
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
export declare enum FileSystemSessionType {
|
|
@@ -56,6 +57,7 @@ export type VideoCompressorType = {
|
|
|
56
57
|
options?: videoCompresssionType,
|
|
57
58
|
onProgress?: (progress: number) => void
|
|
58
59
|
): Promise<string>;
|
|
60
|
+
cancelCompression(cancellationId: string): void;
|
|
59
61
|
backgroundUpload(
|
|
60
62
|
url: string,
|
|
61
63
|
fileUrl: string,
|
|
@@ -109,15 +111,14 @@ export const backgroundUpload = async (
|
|
|
109
111
|
}
|
|
110
112
|
};
|
|
111
113
|
|
|
114
|
+
export const cancelCompression = (cancellationId: string) => {
|
|
115
|
+
return NativeVideoCompressor.cancelCompression(cancellationId);
|
|
116
|
+
};
|
|
117
|
+
|
|
112
118
|
const Video: VideoCompressorType = {
|
|
113
119
|
compress: async (
|
|
114
120
|
fileUrl: string,
|
|
115
|
-
options?:
|
|
116
|
-
bitrate?: number;
|
|
117
|
-
compressionMethod?: compressionMethod;
|
|
118
|
-
maxSize?: number;
|
|
119
|
-
minimumFileSizeForCompress?: number;
|
|
120
|
-
},
|
|
121
|
+
options?: videoCompresssionType,
|
|
121
122
|
onProgress?: (progress: number) => void
|
|
122
123
|
) => {
|
|
123
124
|
const uuid = uuidv4();
|
|
@@ -151,10 +152,13 @@ const Video: VideoCompressorType = {
|
|
|
151
152
|
} else {
|
|
152
153
|
modifiedOptions.maxSize = 640;
|
|
153
154
|
}
|
|
154
|
-
if (options?.minimumFileSizeForCompress) {
|
|
155
|
+
if (options?.minimumFileSizeForCompress !== undefined) {
|
|
155
156
|
modifiedOptions.minimumFileSizeForCompress =
|
|
156
157
|
options?.minimumFileSizeForCompress;
|
|
157
158
|
}
|
|
159
|
+
if (options?.getCancellationId) {
|
|
160
|
+
options?.getCancellationId(uuid);
|
|
161
|
+
}
|
|
158
162
|
const result = await NativeVideoCompressor.compress(
|
|
159
163
|
fileUrl,
|
|
160
164
|
modifiedOptions
|
|
@@ -168,6 +172,7 @@ const Video: VideoCompressorType = {
|
|
|
168
172
|
}
|
|
169
173
|
},
|
|
170
174
|
backgroundUpload,
|
|
175
|
+
cancelCompression,
|
|
171
176
|
activateBackgroundTask(onExpired?) {
|
|
172
177
|
if (onExpired) {
|
|
173
178
|
const subscription: NativeEventSubscription =
|
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) {
|
|
Binary file
|