Skip to content

Commit

Permalink
Add version 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
leontobias committed May 2, 2023
1 parent 9ea589b commit 14eb997
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 62 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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<void>`.
* [react-native-photoeditorsdk] Unlocking the SDK via `PESDK.unlockWithLicense` now returns a `Promise<void>`.

### Fixed

* [react-native-videoeditorsdk] Fixed unused types exports.

## [2.17.1]

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -48,16 +49,28 @@ 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
private var currentEditorUID: String = UUID.randomUUID().toString()
private var settingsLists: MutableMap<String, SettingsList> = 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
Expand Down Expand Up @@ -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()
Expand All @@ -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
}
}
Expand Down
12 changes: 1 addition & 11 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,6 @@ declare class VESDK {
videoSize?: Size
): Promise<VideoEditorResult | null>;

/**
* 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.
*
Expand All @@ -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<void>;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
41 changes: 13 additions & 28 deletions ios/RNImglyKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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");
Expand Down
11 changes: 5 additions & 6 deletions ios/RNImglyKitSubclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down
16 changes: 8 additions & 8 deletions ios/RNVideoEditorSDK.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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"
}
}

0 comments on commit 14eb997

Please sign in to comment.