Skip to content

Commit

Permalink
MOB-1000 #comment implemented response handler events
Browse files Browse the repository at this point in the history
  • Loading branch information
shachartransmit committed May 1, 2024
1 parent 481e246 commit 53cba4e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ Made with [create-react-native-library](https://github.com/callstack/react-nativ



add transmit plist file to ios and json file/manifest for android
add transmit plist file to ios and json file/manifest for android
must set response handler
32 changes: 31 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NativeModules, Platform } from 'react-native';
import { NativeModules, Platform, NativeEventEmitter } from 'react-native';

const LINKING_ERROR =
`The package 'react-native-ts-identity-orchestration' doesn't seem to be linked. Make sure: \n\n` +
Expand All @@ -17,6 +17,7 @@ const TsIdentityOrchestration = NativeModules.TsIdentityOrchestration
}
);

const eventEmitter = new NativeEventEmitter(TsIdentityOrchestration);

export namespace TSIDOModule {

Expand Down Expand Up @@ -89,11 +90,22 @@ export namespace TSIDOModule {
- data: The client response data object. Mandatory in ClientInput response option type, populate with data for the Journey step to process. Optional in Cancel and Custom as an additional parameters for the branch.
*/
submitClientResponse: (clientResponseOptionId: TSIDOModule.ClientResponseOptionType | string, data?: { [key: string]: any; } | null | undefined) => void;

/**
This method will expose a success and error handlers to your application.
- Parameters:
- responseHandler : The response handler object with success and error callbacks.
*/
setResponseHandler: (responseHandler: TSIDOModule.ResponseHandler) => void;
}
}

class RNTSIdentityOrchestration implements TSIDOModule.API {

private responseHandler?: TSIDOModule.ResponseHandler;
private static kResponseHandlerEventname = "tsido_response_handler_event";

initializeSDK = async (): Promise<boolean> => {
return await TsIdentityOrchestration.initializeSDK();
}
Expand All @@ -109,5 +121,23 @@ class RNTSIdentityOrchestration implements TSIDOModule.API {
TsIdentityOrchestration.submitClientResponse(clientResponseOptionId, data);
}

setResponseHandler = (responseHandler: TSIDOModule.ResponseHandler): void => {
this.responseHandler = responseHandler;
eventEmitter.addListener(
RNTSIdentityOrchestration.kResponseHandlerEventname,
this.onResponseReceived
);
}

private onResponseReceived = async (params: any) => {
const success: boolean = params["success"];
const additionalData: { [key: string]: any } = params["additionalData"];

if (success) {
this.responseHandler?.success(additionalData);
} else {
this.responseHandler?.error(additionalData.errorCode);
}
}
}
export default new RNTSIdentityOrchestration();

0 comments on commit 53cba4e

Please sign in to comment.