Notifications.ts 2.62 KB
Newer Older
yogevbd's avatar
yogevbd committed
1 2 3 4
import { NativeCommandsSender } from './adapters/NativeCommandsSender';
import { NativeEventsReceiver } from './adapters/NativeEventsReceiver';
import { Commands } from './commands/Commands';
import { EventsRegistry } from './events/EventsRegistry';
5
import { Notification } from './DTO/Notification';
6
import { UniqueIdProvider } from './adapters/UniqueIdProvider';
yogevbd's avatar
yogevbd committed
7
import { CompletionCallbackWrapper } from './adapters/CompletionCallbackWrapper';
8
import { NotificationCategory } from './interfaces/NotificationCategory';
9 10
import { NotificationsIOS } from './NotificationsIOS';
import { NotificationsAndroid } from './NotificationsAndroid';
yogevbd's avatar
yogevbd committed
11 12

export class NotificationsRoot {
13 14 15
  public readonly ios: NotificationsIOS;
  public readonly android: NotificationsAndroid;

yogevbd's avatar
yogevbd committed
16 17 18 19
  private readonly nativeEventsReceiver: NativeEventsReceiver;
  private readonly nativeCommandsSender: NativeCommandsSender;
  private readonly commands: Commands;
  private readonly eventsRegistry: EventsRegistry;
20
  private readonly uniqueIdProvider: UniqueIdProvider;
yogevbd's avatar
yogevbd committed
21
  private readonly completionCallbackWrapper: CompletionCallbackWrapper;
yogevbd's avatar
yogevbd committed
22 23 24 25

  constructor() {
    this.nativeEventsReceiver = new NativeEventsReceiver();
    this.nativeCommandsSender = new NativeCommandsSender();
yogevbd's avatar
yogevbd committed
26
    this.completionCallbackWrapper = new CompletionCallbackWrapper(this.nativeCommandsSender);
27
    this.uniqueIdProvider = new UniqueIdProvider();
yogevbd's avatar
yogevbd committed
28
    this.commands = new Commands(
29 30
      this.nativeCommandsSender,
      this.uniqueIdProvider
yogevbd's avatar
yogevbd committed
31
    );
yogevbd's avatar
yogevbd committed
32
    this.eventsRegistry = new EventsRegistry(this.nativeEventsReceiver, this.completionCallbackWrapper);
yogevbd's avatar
yogevbd committed
33

34 35
    this.ios = new NotificationsIOS(this.commands);
    this.android = new NotificationsAndroid(this.commands);
yogevbd's avatar
yogevbd committed
36 37 38
  }

  /**
yogevbd's avatar
yogevbd committed
39
   * postLocalNotification
yogevbd's avatar
yogevbd committed
40
   */
yogevbd's avatar
yogevbd committed
41 42
  public postLocalNotification(notification: Notification, id: number) {
    return this.commands.postLocalNotification(notification, id);
yogevbd's avatar
yogevbd committed
43 44 45
  }

  /**
yogevbd's avatar
yogevbd committed
46
   * getInitialNotification
yogevbd's avatar
yogevbd committed
47 48 49 50 51
   */
  public getInitialNotification(): Promise<Notification> {
    return this.commands.getInitialNotification();
  }

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
  /**
   * setCategories
   */
  public setCategories(categories: [NotificationCategory?]) {
    this.commands.setCategories(categories);
  }

  /**
   * cancelLocalNotification
  */
  public cancelLocalNotification(notificationId: string) {
    return this.commands.cancelLocalNotification(notificationId);
  }

  /**
   * isRegisteredForRemoteNotifications
   */
69 70
  public isRegisteredForRemoteNotifications(): Promise<boolean> {
    return this.commands.isRegisteredForRemoteNotifications();
71 72
  }

yogevbd's avatar
yogevbd committed
73 74 75 76 77 78 79
  /**
   * Obtain the events registry instance
   */
  public events(): EventsRegistry {
    return this.eventsRegistry;
  }
}