Notifications.ts 1.43 KB
Newer Older
yogevbd's avatar
yogevbd committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
import { NativeCommandsSender } from './adapters/NativeCommandsSender';
import { NativeEventsReceiver } from './adapters/NativeEventsReceiver';
import { Commands } from './commands/Commands';
import { EventsRegistry } from './events/EventsRegistry';
import { Notification } from './interfaces/Notification';

export class NotificationsRoot {
  private readonly nativeEventsReceiver: NativeEventsReceiver;
  private readonly nativeCommandsSender: NativeCommandsSender;
  private readonly commands: Commands;
  private readonly eventsRegistry: EventsRegistry;

  constructor() {
    this.nativeEventsReceiver = new NativeEventsReceiver();
    this.nativeCommandsSender = new NativeCommandsSender();
    this.commands = new Commands(
      this.nativeCommandsSender
    );
    this.eventsRegistry = new EventsRegistry(this.nativeEventsReceiver);
  }

  /**
  * Request permissions to send remote notifications - iOS only
  */
  public requestPermissions(): Promise<any> {
    return this.commands.requestPermissions();
  }

  /**
   * Reset the app to a new layout
   */
  public localNotification(notification: Notification): Promise<any> {
    return this.commands.sendLocalNotification(notification);
  }

  /**
   * 
   */
  public getInitialNotification(): Promise<Notification> {
    return this.commands.getInitialNotification();
  }

  /**
   * Obtain the events registry instance
   */
  public events(): EventsRegistry {
    return this.eventsRegistry;
  }
}