EventsRegistry.ts 1.94 KB
Newer Older
yogevbd's avatar
yogevbd committed
1 2 3
import { EmitterSubscription } from 'react-native';
import { NativeEventsReceiver } from '../adapters/NativeEventsReceiver';
import {
yogevbd's avatar
yogevbd committed
4 5 6 7
  Registered,
  RegistrationError,
  RegisteredPushKit,
  NotificationResponse
yogevbd's avatar
yogevbd committed
8
} from '../interfaces/NotificationEvents';
yogevbd's avatar
yogevbd committed
9 10
import { CompletionCallbackWrapper } from '../adapters/CompletionCallbackWrapper';
import { NotificationCompletion, Notification } from '../interfaces/Notification';
yogevbd's avatar
yogevbd committed
11 12

export class EventsRegistry {
yogevbd's avatar
yogevbd committed
13 14 15 16
  constructor(
    private nativeEventsReceiver: NativeEventsReceiver,
    private completionCallbackWrapper: CompletionCallbackWrapper) 
  {}
yogevbd's avatar
yogevbd committed
17

yogevbd's avatar
yogevbd committed
18
  public registerRemoteNotificationsRegistered(callback: (event: Registered) => void): EmitterSubscription {
yogevbd's avatar
yogevbd committed
19 20 21
    return this.nativeEventsReceiver.registerRemoteNotificationsRegistered(callback);
  }

yogevbd's avatar
yogevbd committed
22 23
  public registerPushKitRegistered(callback: (event: RegisteredPushKit) => void): EmitterSubscription {
    return this.nativeEventsReceiver.registerPushKitRegistered(callback);
yogevbd's avatar
yogevbd committed
24
  }
yogevbd's avatar
yogevbd committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
  
  public registerNotificationReceived(callback: (notification: Notification, completion: (response: NotificationCompletion) => void) => void): EmitterSubscription {
    return this.nativeEventsReceiver.registerRemoteNotificationReceived(this.completionCallbackWrapper.wrapReceivedCallback(callback));
  }

  public registerPushKitNotificationReceived(callback: (event: object) => void): EmitterSubscription {
    return this.nativeEventsReceiver.registerPushKitNotificationReceived(callback);
  }
  
  public registerRemoteNotificationOpened(callback: (response: NotificationResponse, completion: () => void) => void): EmitterSubscription {
    return this.nativeEventsReceiver.registerRemoteNotificationOpened(this.completionCallbackWrapper.wrapOpenedCallback(callback));
  }
  
  public registerRemoteNotificationsRegistrationFailed(callback: (event: RegistrationError) => void): EmitterSubscription {
    return this.nativeEventsReceiver.registerRemoteNotificationsRegistrationFailed(callback);
  }
  
yogevbd's avatar
yogevbd committed
42
}