@@ -933,27 +933,6 @@ export class Iterable {
933933 ) ;
934934 }
935935
936- /**
937- * A callback function that is called when an authentication failure occurs.
938- *
939- * @param authFailure - The auth failure details
940- *
941- * @example
942- * ```typescript
943- * Iterable.onAuthFailure({
944- * userKey: '1234567890',
945- * failedAuthToken: '1234567890',
946- * failedRequestTime: 1234567890,
947- * failureReason: IterableAuthFailureReason.AUTH_TOKEN_EXPIRED,
948- * });
949- * ```
950- */
951- static onAuthFailure ( authFailure : IterableAuthFailure ) {
952- Iterable ?. logger ?. log ( 'onAuthFailure' ) ;
953-
954- RNIterableAPI . onAuthFailure ( authFailure ) ;
955- }
956-
957936 /**
958937 * Pause the authentication retry mechanism.
959938 *
@@ -970,9 +949,35 @@ export class Iterable {
970949 RNIterableAPI . pauseAuthRetries ( pauseRetry ) ;
971950 }
972951
973- /** * @internal
952+ /**
953+ * Sets up event handlers for various Iterable events.
954+ *
955+ * This method performs the following actions:
956+ * - Removes all existing listeners to avoid duplicate listeners.
957+ * - Adds listeners for URL handling, custom actions, in-app messages, and authentication.
958+ *
959+ * Event Handlers:
960+ * - `handleUrlCalled`: Invokes the URL handler if configured, with a delay on Android to allow the activity to wake up.
961+ * - `handleCustomActionCalled`: Invokes the custom action handler if configured.
962+ * - `handleInAppCalled`: Invokes the in-app handler if configured and sets the in-app show response.
963+ * - `handleAuthCalled`: Invokes the authentication handler if configured and handles the promise result.
964+ * - `handleAuthSuccessCalled`: Sets the authentication response callback to success.
965+ * - `handleAuthFailureCalled`: Sets the authentication response callback to failure.
966+ *
967+ * Helper Functions:
968+ * - `callUrlHandler`: Calls the URL handler and attempts to open the URL if the handler returns false.
969+ *
970+ * @internal
974971 */
975972 private static setupEventHandlers ( ) {
973+ // Remove all listeners to avoid duplicate listeners
974+ RNEventEmitter . removeAllListeners ( IterableEventName . handleUrlCalled ) ;
975+ RNEventEmitter . removeAllListeners ( IterableEventName . handleInAppCalled ) ;
976+ RNEventEmitter . removeAllListeners (
977+ IterableEventName . handleCustomActionCalled
978+ ) ;
979+ RNEventEmitter . removeAllListeners ( IterableEventName . handleAuthCalled ) ;
980+
976981 if ( Iterable . savedConfig . urlHandler ) {
977982 RNEventEmitter . addListener ( IterableEventName . handleUrlCalled , ( dict ) => {
978983 const url = dict . url ;
0 commit comments