Skip to content

Commit

Permalink
feat(events/onerror): add error types
Browse files Browse the repository at this point in the history
  • Loading branch information
ridvanaltun committed Jul 5, 2022
1 parent e0362fb commit 785eabe
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -269,7 +269,7 @@ These are various events that you can hook into and fire functions on in the com
| onCameraSwitched | (<b>facing</b>: CameraFacing) | Called when camera switched. |
| onFaceVisibilityChanged | (<b>visible</b>: Boolean) | Called when the user's face becomes visible or invisible. |
| onImageVisibilityChanged | (<b>visible</b>: Boolean, <b>gameObject</b>?: String) | Called when a natural image is being tracked and the visibility has changed. |
| onError | (<b>errorText</b>: String) | Called when an error occur, like the model path not found or the effect file failed to load. |
| onError | (<b>text</b>: String, <b>type</b>: ErrorTypes,) | Called when an error occur, like the model path not found or the effect file failed to load. |

### Methods

Expand Down
5 changes: 3 additions & 2 deletions android/src/main/java/com/reactnativedeepar/RNTDeepAR.java
Expand Up @@ -512,7 +512,8 @@ public void videoRecordingFinished() {
* */
@Override
public void videoRecordingFailed() {
sendEvent("error", "Video Recording Failed", null);
String DEEPAR_ERROR_TYPE_VIDEO = "VIDEO";
sendEvent("error", "Video Recording Failed", DEEPAR_ERROR_TYPE_VIDEO);
}

/**
Expand Down Expand Up @@ -557,6 +558,6 @@ public void shutdownFinished() {
* */
@Override
public void error(ARErrorType arErrorType, String errorText) {
sendEvent("error", errorText, null);
sendEvent("error", errorText, arErrorType.toString());
}
}
5 changes: 3 additions & 2 deletions example/src/screens/HomeScreen.tsx
Expand Up @@ -11,6 +11,7 @@ import {
import DeepARView, {
IDeepARHandle,
TextureSourceTypes,
ErrorTypes,
} from 'react-native-deepar';
import RNFetchBlob from 'rn-fetch-blob';

Expand Down Expand Up @@ -328,8 +329,8 @@ const HomeScreen = ({navigation}: {navigation: any}) => {
type: Enums.PREVIEW_TYPES.VIDEO,
});
}}
onError={(errText: String) => {
console.log('onError =>', errText);
onError={(text: String, type: ErrorTypes) => {
console.log('onError =>', text, 'type =>', type);
}}
// eslint-disable-next-line react-native/no-inline-styles
style={{
Expand Down
21 changes: 18 additions & 3 deletions ios/RNTDeepAR.m
Expand Up @@ -376,10 +376,25 @@ - (void)didFinishVideoRecording:(NSString *)videoFilePath {
}

/**
* Called if there is error encountered while recording video
*/
* Called if there is error encountered while recording video
*/
- (void)recordingFailedWithError:(NSError *)error {
self.onEventSent(@{@"type" : @"error", @"value" : [error description]});
NSString * const DEEPAR_ERROR_TYPE_VIDEO = @"VIDEO";
self.onEventSent(@{@"type" : @"error", @"value" : [error description], @"value2" : DEEPAR_ERROR_TYPE_VIDEO});
}

/**
* Called when an error has occurred.
*/
- (void)onErrorWithCode:(ARErrorType)code error:(NSString *)error {
NSString * const ARErrorType_toString[] = {
[DEEPAR_ERROR_TYPE_DEBUG] = @"DEBUG",
[DEEPAR_ERROR_TYPE_INFO] = @"INFO",
[DEEPAR_ERROR_TYPE_WARNING] = @"WARNING",
[DEEPAR_ERROR_TYPE_ERROR] = @"ERROR"
};

self.onEventSent(@{@"type" : @"error", @"value" : [error description], @"value2" : ARErrorType_toString[code]});
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/DeepARView.tsx
Expand Up @@ -6,6 +6,7 @@ import {
IDeepARProps,
IRNTDeepARView,
CameraFacing,
ErrorTypes,
} from './index';

const NATIVE_VIEW_KEY = 'RNTDeepARView';
Expand Down Expand Up @@ -180,7 +181,10 @@ const DeepARView = forwardRef<IDeepARHandle, IDeepARProps>(
if (onShutdownFinished) onShutdownFinished();
break;
case 'error':
if (onError) onError(nativeEvent.value);
if (onError) {
// @ts-ignore
onError(nativeEvent.value, ErrorTypes[nativeEvent.value2]);
}
break;
default:
break;
Expand Down
11 changes: 10 additions & 1 deletion src/index.tsx
Expand Up @@ -24,6 +24,15 @@ export interface IRNTDeepARView {
onEventSent: ({nativeEvent}: {nativeEvent: IDeepAREvent}) => void;
}

export enum ErrorTypes {
DEBUG = 0,
INFO = 1,
WARNING = 2,
ERROR = 3,
VIDEO = 4,
UNKNOWN = 5,
}

export interface IDeepARProps extends ViewProps {
apiKey: String;
onEventSent?: (event: IDeepAREvent) => void;
Expand All @@ -38,7 +47,7 @@ export interface IDeepARProps extends ViewProps {
onImageVisibilityChanged?: (isVisible: Boolean, gameObject?: String) => void;
onFrameAvailable?: () => void;
onShutdownFinished?: () => void;
onError?: (errorText: String) => void;
onError?: (text: String, type: ErrorTypes) => void;
}

interface ISwitchEffect {
Expand Down

0 comments on commit 785eabe

Please sign in to comment.