EventsRegistry.ts 2 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
import { CompletionCallbackWrapper } from '../adapters/CompletionCallbackWrapper';
10 11
import { Notification } from '../interfaces/Notification';
import { NotificationCompletion } from '../interfaces/NotificationCompletion';
yogevbd's avatar
yogevbd committed
12 13

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

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

yogevbd's avatar
yogevbd committed
23 24
  public registerPushKitRegistered(callback: (event: RegisteredPushKit) => void): EmitterSubscription {
    return this.nativeEventsReceiver.registerPushKitRegistered(callback);
yogevbd's avatar
yogevbd committed
25
  }
yogevbd's avatar
yogevbd committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
  
  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
43
}