NativeEventsReceiver.js 1.61 KB
Newer Older
冷佳娟's avatar
冷佳娟 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
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_native_1 = require("react-native");
const Notification_1 = require("../DTO/Notification");
const NotificationActionResponse_1 = require("../interfaces/NotificationActionResponse");
class NativeEventsReceiver {
    constructor() {
        this.emitter = new react_native_1.NativeEventEmitter(react_native_1.NativeModules.RNEventEmitter);
    }
    registerRemoteNotificationsRegistered(callback) {
        return this.emitter.addListener('remoteNotificationsRegistered', callback);
    }
    registerPushKitRegistered(callback) {
        return this.emitter.addListener('pushKitRegistered', callback);
    }
    registerRemoteNotificationReceived(callback) {
        return this.emitter.addListener('notificationReceived', (payload) => {
            callback(new Notification_1.Notification(payload));
        });
    }
    registerPushKitNotificationReceived(callback) {
        return this.emitter.addListener('pushKitNotificationReceived', callback);
    }
    registerRemoteNotificationOpened(callback) {
        return this.emitter.addListener('notificationOpened', (response, completion) => {
            const action = response.action ? new NotificationActionResponse_1.NotificationActionResponse(response.action) : undefined;
            callback(new Notification_1.Notification(response.notification), completion, action);
        });
    }
    registerRemoteNotificationsRegistrationFailed(callback) {
        return this.emitter.addListener('remoteNotificationsRegistrationFailed', callback);
    }
}
exports.NativeEventsReceiver = NativeEventsReceiver;