NativeEventsReceiver.ts 785 Bytes
Newer Older
yogevbd's avatar
yogevbd committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
import { NativeModules, NativeEventEmitter, EventEmitter, EmitterSubscription } from 'react-native';
import {
  NotificationRegisteredEvent, NotificationReceived
} from '../interfaces/NotificationEvents';

export class NativeEventsReceiver {
  private emitter: EventEmitter;
  constructor() {
    this.emitter = new NativeEventEmitter(NativeModules.RNEventEmitter);
  }

  public registerRemoteNotificationsRegistered(callback: (event: NotificationRegisteredEvent) => void): EmitterSubscription {
    return this.emitter.addListener('remoteNotificationsRegistered', callback);
  }

yogevbd's avatar
yogevbd committed
16
  public registerRemoteNotificationReceived(callback: (event: NotificationReceived) => void): EmitterSubscription {
yogevbd's avatar
yogevbd committed
17 18 19
    return this.emitter.addListener('notificationReceivedForeground', callback);
  }
}