@smartface/plugin-firebase
Version:
Smartface Firebase Plugin for Smartface Native Framework
81 lines • 3.01 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// @ts-ignore
var NativeFirebaseMessaging = requireClass('com.google.firebase.messaging.FirebaseMessaging');
var androidconfig_1 = __importDefault(require("@smartface/native/util/Android/androidconfig"));
var notifications_1 = __importDefault(require("@smartface/native/global/notifications"));
var Messaging = /** @class */ (function () {
function Messaging() {
}
// Required push permission for get token.
/**
* iOS : Returns the FCM token.
* Android : Returns the notification token.
*
* @method getToken
* @android
* @ios
* @since 0.1
*/
Messaging.getToken = function (callback) {
if (!androidconfig_1.default.isEmulator) {
notifications_1.default.registerForPushNotifications(function (e) { return callback(e.token); }, function () { return callback(undefined); });
}
};
/**
* Asynchronously subscribes to a topic.
*
* @method subscribeToTopic
* @param {String} topic
* @android
* @ios
* @since 0.1
*/
Messaging.subscribeToTopic = function (topic) {
if (Messaging.nativeObject) {
Messaging.nativeObject().subscribeToTopic(topic);
}
};
/**
* Asynchronously unsubscribe from a topic.
*
* @method unsubscribeFromTopic
* @param {String} topic
* @android
* @ios
* @since 0.1
*/
Messaging.unsubscribeFromTopic = function (topic) {
if (Messaging.nativeObject) {
Messaging.nativeObject().unsubscribeFromTopic(topic);
}
};
Messaging.nativeObject = !androidconfig_1.default.isEmulator ? function () { return NativeFirebaseMessaging.getInstance(); } : undefined;
Messaging.ios = {
native: undefined,
/**
* The FCM token is used to identify this device so that FCM can send notifications to it.
* It is associated with your APNS token when the APNS token is supplied, so that sending
* messages to the FCM token will be delivered over APNS.
*
* The FCM token is sometimes refreshed automatically. `onTokenReflesh` method will be called once a token is
* available, or has been refreshed. Typically it should be called once per app start, but
* may be called more often, if token is invalidated or updated.
*
* Once you have an FCM token, you should send it to your application server, so it can use
* the FCM token to send notifications to your device.
*
* @method onTokenReflesh
* @ios
* @since 0.1
*/
onTokenReflesh: function () { }
};
return Messaging;
}());
exports.default = Messaging;
module.exports = Messaging;
//# sourceMappingURL=messaging-Android.js.map