EventsRegistry.ts 1.6 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
  Registered,
  RegistrationError,
  NotificationResponse
yogevbd's avatar
yogevbd committed
7
} from '../interfaces/NotificationEvents';
yogevbd's avatar
yogevbd committed
8
import { CompletionCallbackWrapper } from '../adapters/CompletionCallbackWrapper';
9
import { Notification } from '../DTO/Notification';
10
import { NotificationCompletion } from '../interfaces/NotificationCompletion';
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
    return this.nativeEventsReceiver.registerRemoteNotificationsRegistered(callback);
  }
yogevbd's avatar
yogevbd committed
21 22 23 24 25 26 27 28 29 30 31 32
  
  public registerNotificationReceived(callback: (notification: Notification, completion: (response: NotificationCompletion) => void) => void): EmitterSubscription {
    return this.nativeEventsReceiver.registerRemoteNotificationReceived(this.completionCallbackWrapper.wrapReceivedCallback(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
33
}