diff --git a/CHANGELOG.md b/CHANGELOG.md index 782b76e..542b66a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +## [3.0.0] + +### Changed + +* Changed and aligned the error codes for the modules. +* [react-native-videoeditorsdk] Unlocking the SDK via `VESDK.unlockWithLicense` now returns a `Promise`. +* [react-native-photoeditorsdk] Unlocking the SDK via `PESDK.unlockWithLicense` now returns a `Promise`. + +### Fixed + +* [react-native-videoeditorsdk] Fixed unused types exports. + ## [2.17.1] ### Fixed diff --git a/android/src/main/java/ly/img/react_native/vesdk/RNVideoEditorSDKModule.kt b/android/src/main/java/ly/img/react_native/vesdk/RNVideoEditorSDKModule.kt index 97956ca..675b6bb 100644 --- a/android/src/main/java/ly/img/react_native/vesdk/RNVideoEditorSDKModule.kt +++ b/android/src/main/java/ly/img/react_native/vesdk/RNVideoEditorSDKModule.kt @@ -6,6 +6,7 @@ import android.net.Uri import android.util.Log import androidx.annotation.WorkerThread import com.facebook.react.bridge.* +import ly.img.android.AuthorizationException import ly.img.android.IMGLY import ly.img.android.VESDK import ly.img.android.pesdk.VideoEditorSettingsList @@ -48,6 +49,12 @@ class RNVideoEditorSDKModule(reactContext: ReactApplicationContext) : ReactConte reactContext.addActivityEventListener(this) } + /** IMGLY constants for the plugin use. */ + object IMGLYConstants { + const val K_ERROR_UNABLE_TO_UNLOCK = "E_UNABLE_TO_UNLOCK" + const val K_ERROR_UNABLE_TO_LOAD = "E_UNABLE_TO_LOAD" + } + private var currentPromise: Promise? = null private var currentConfig: Configuration? = null private var resolveManually: Boolean = false @@ -55,9 +62,15 @@ class RNVideoEditorSDKModule(reactContext: ReactApplicationContext) : ReactConte private var settingsLists: MutableMap = mutableMapOf() @ReactMethod - fun unlockWithLicense(license: String) { - VESDK.initSDKWithLicenseData(license) - IMGLY.authorize() + fun unlockWithLicense(license: String, promise: Promise) { + try { + VESDK.initSDKWithLicenseData(license) + IMGLY.authorize() + promise.resolve(null) + } catch (e: AuthorizationException) { + promise.reject(IMGLYConstants.K_ERROR_UNABLE_TO_UNLOCK, "Unlocking the SDK failed due to: ${e.message}.") + } + } @ReactMethod @@ -212,7 +225,7 @@ class RNVideoEditorSDKModule(reactContext: ReactApplicationContext) : ReactConte if (videoArray.isNotEmpty()) { if (source == null) { if (size != null) { - promise.reject("VESDK", "Invalid video size: width and height must be greater than zero.") + promise.reject(IMGLYConstants.K_ERROR_UNABLE_TO_LOAD, "Invalid video size: width and height must be greater than zero.") return } val video = videoArray.first() @@ -226,7 +239,7 @@ class RNVideoEditorSDKModule(reactContext: ReactApplicationContext) : ReactConte } } else { if (source == null) { - promise.reject("VESDK", "The editor requires a valid size when initialized without a video.") + promise.reject(IMGLYConstants.K_ERROR_UNABLE_TO_LOAD, "The editor requires a valid size when initialized without a video.") return } } diff --git a/index.d.ts b/index.d.ts index 7338388..7e8af8d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -84,16 +84,6 @@ declare class VESDK { videoSize?: Size ): Promise; - /** - * Releases the result from the editor and deletes the temporary files. - * @note This function needs to be called in case `configuration.export.video.segments` - * is set to `true`. - * - * @param {string} identifier The identifier of the `VideoEditorResult` to release - * the temporary data of. - */ - static releaseTemporaryData(identifier: string): void; - /** * Unlock VideoEditor SDK with a license. * @@ -104,7 +94,7 @@ declare class VESDK { * and `vesdk_license.android.json` for the Android license file in order to get automatically * resolved by the packager. */ - static unlockWithLicense(license: string | object): void; + static unlockWithLicense(license: string | object): Promise; } /** diff --git a/index.js b/index.js index deffd3e..3b1187f 100644 --- a/index.js +++ b/index.js @@ -204,9 +204,9 @@ class VESDK { */ static unlockWithLicense(license) { if (Platform.OS == 'android') { - RNVideoEditorSDK.unlockWithLicense(JSON.stringify(license)); + return RNVideoEditorSDK.unlockWithLicense(JSON.stringify(license)); } else { - RNVideoEditorSDK.unlockWithLicense(license); + return RNVideoEditorSDK.unlockWithLicense(license); } } } diff --git a/ios/RNImglyKit.m b/ios/RNImglyKit.m index 5150cf4..114d46e 100644 --- a/ios/RNImglyKit.m +++ b/ios/RNImglyKit.m @@ -63,11 +63,6 @@ - (void)present:(nonnull IMGLYMediaEditViewControllerBlock)createMediaEditViewCo } dispatch_async(dispatch_get_main_queue(), ^{ - if (self.licenseError != nil) { - reject(RN_IMGLY.kErrorUnableToUnlock, [NSString RN_IMGLY_string:@"Unable to unlock with license." withError:self.licenseError], self.licenseError); - return; - } - PESDKAssetCatalog *assetCatalog = PESDKAssetCatalog.defaultItems; PESDKConfiguration *configuration = [[PESDKConfiguration alloc] initWithBuilder:^(PESDKConfigurationBuilder * _Nonnull builder) { builder.assetCatalog = assetCatalog; @@ -169,34 +164,24 @@ - (void)dismiss:(nullable PESDKMediaEditViewController *)mediaEditViewController }); } -- (void)handleLicenseError:(nullable NSError *)error +- (void)handleLicenseError:(nullable NSError *)error resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject { - self.licenseError = nil; if (error != nil) { - if ([error.domain isEqualToString:@"ImglyKit.IMGLY.Error"]) { - switch (error.code) { - case 3: - RCTLogWarn(@"%@: %@", NSStringFromClass(self.class), error.localizedDescription); - break; - default: - self.licenseError = error; - RCTLogError(@"%@: %@", NSStringFromClass(self.class), error.localizedDescription); - break; - } - } else { - self.licenseError = error; - RCTLogError(@"Error while unlocking with license: %@", error); - } + reject(RN_IMGLY.kErrorUnableToUnlock, [NSString RN_IMGLY_string:@"Unable to unlock with license." withError:error], error); + return; + } else { + resolve(nil); + return; } } -- (void)unlockWithLicenseURL:(nonnull NSURL *)url {} +- (void)unlockWithLicenseURL:(nonnull NSURL *)url resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {} -- (void)unlockWithLicenseString:(nonnull NSString *)string {} +- (void)unlockWithLicenseString:(nonnull NSString *)string resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {} -- (void)unlockWithLicenseObject:(nonnull NSDictionary *)dictionary {} +- (void)unlockWithLicenseObject:(nonnull NSDictionary *)dictionary resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {} -- (void)unlockWithLicense:(nonnull id)json +- (void)unlockWithLicense:(nonnull id)json resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject { NSString *string = nil; NSURL *url = nil; @@ -222,14 +207,14 @@ - (void)unlockWithLicense:(nonnull id)json } if (url != nil) { - [self unlockWithLicenseURL:url]; + [self unlockWithLicenseURL:url resolve:resolve reject:reject]; } else if (string != nil) { - [self unlockWithLicenseString:string]; + [self unlockWithLicenseString:string resolve:resolve reject:reject]; } else if ([json isKindOfClass:[NSDictionary class]]) { NSDictionary *dictionary = json; - [self unlockWithLicenseObject:dictionary]; + [self unlockWithLicenseObject:dictionary resolve:resolve reject:reject]; } else if (json) { RCTLogConvertError(json, @"a valid license format"); diff --git a/ios/RNImglyKitSubclass.h b/ios/RNImglyKitSubclass.h index 1007a7f..e42f7e0 100644 --- a/ios/RNImglyKitSubclass.h +++ b/ios/RNImglyKitSubclass.h @@ -50,7 +50,6 @@ typedef void (^IMGLYCompletionBlock)(void); @property (class, strong, atomic, nullable) IMGLYConfigurationBlock configureWithBuilder; -@property (strong, atomic, nullable) NSError* licenseError; @property (strong, atomic, nullable) NSString* exportType; @property (strong, atomic, nullable) NSURL* exportFile; @property (atomic) BOOL serializationEnabled; @@ -68,11 +67,11 @@ typedef void (^IMGLYCompletionBlock)(void); resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject; - (void)dismiss:(nullable PESDKMediaEditViewController *)mediaEditViewController animated:(BOOL)animated completion:(nullable IMGLYCompletionBlock)completion; -- (void)handleLicenseError:(nullable NSError *)error; -- (void)unlockWithLicenseURL:(nonnull NSURL *)url; -- (void)unlockWithLicenseString:(nonnull NSString *)string; -- (void)unlockWithLicenseObject:(nonnull NSDictionary *)dictionary; -- (void)unlockWithLicense:(nonnull id)json; +- (void)handleLicenseError:(nullable NSError *)error resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject; +- (void)unlockWithLicenseURL:(nonnull NSURL *)url resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject; +- (void)unlockWithLicenseString:(nonnull NSString *)string resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject; +- (void)unlockWithLicenseObject:(nonnull NSDictionary *)dictionary resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject; +- (void)unlockWithLicense:(nonnull id)json resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject; extern const struct RN_IMGLY_Constants { diff --git a/ios/RNVideoEditorSDK.m b/ios/RNVideoEditorSDK.m index 6a2003b..6e96763 100644 --- a/ios/RNVideoEditorSDK.m +++ b/ios/RNVideoEditorSDK.m @@ -65,36 +65,36 @@ - (void)present:(nonnull PESDKVideo *)video withConfiguration:(nullable NSDictio } configuration:dictionary serialization:state resolve:resolve reject:reject]; } -RCT_EXPORT_METHOD(unlockWithLicenseURL:(nonnull NSURL *)url) +RCT_EXPORT_METHOD(unlockWithLicenseURL:(nonnull NSURL *)url resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject) { dispatch_async(dispatch_get_main_queue(), ^{ NSError *error = nil; [VESDK unlockWithLicenseFromURL:url error:&error]; - [self handleLicenseError:error]; + [self handleLicenseError:error resolve:resolve reject:reject]; }); } -RCT_EXPORT_METHOD(unlockWithLicenseString:(nonnull NSString *)string) +RCT_EXPORT_METHOD(unlockWithLicenseString:(nonnull NSString *)string resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject) { dispatch_async(dispatch_get_main_queue(), ^{ NSError *error = nil; [VESDK unlockWithLicenseFromString:string error:&error]; - [self handleLicenseError:error]; + [self handleLicenseError:error resolve:resolve reject:reject]; }); } -RCT_EXPORT_METHOD(unlockWithLicenseObject:(nonnull NSDictionary *)dictionary) +RCT_EXPORT_METHOD(unlockWithLicenseObject:(nonnull NSDictionary *)dictionary resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject) { dispatch_async(dispatch_get_main_queue(), ^{ NSError *error = nil; [VESDK unlockWithLicenseFromDictionary:dictionary error:&error]; - [self handleLicenseError:error]; + [self handleLicenseError:error resolve:resolve reject:reject]; }); } -RCT_EXPORT_METHOD(unlockWithLicense:(nonnull id)json) +RCT_EXPORT_METHOD(unlockWithLicense:(nonnull id)json resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject) { - [super unlockWithLicense:json]; + [super unlockWithLicense:json resolve:resolve reject:reject]; } RCT_EXPORT_METHOD(present:(nonnull NSURLRequest *)request diff --git a/package.json b/package.json index a659e8e..fb67d3b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "react-native-videoeditorsdk", "title": "React Native module for VideoEditor SDK", - "version": "2.17.1", + "version": "3.0.0", "description": "A React Native module for VideoEditor SDK. Integrate the video editor into your own HTML5, iOS or Android app - in minutes!", "main": "index.js", "typings": "index.d.ts", @@ -35,6 +35,6 @@ "react-native": ">=0.60.0 <1.0.x" }, "dependencies": { - "react-native-imglysdk": "2.17.1" + "react-native-imglysdk": "3.0.0" } }