forked from evollu/react-native-fcm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (62 loc) · 1.91 KB
/
index.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import {NativeModules, DeviceEventEmitter, Platform} from 'react-native';
const eventsMap = {
refreshToken: 'FCMTokenRefreshed',
notification: 'FCMNotificationReceived'
};
const RNFIRMessaging = NativeModules.RNFIRMessaging;
const FCM = {};
FCM.getInitialNotification = () => {
return RNFIRMessaging.getInitialNotification();
}
FCM.getFCMToken = () => {
return RNFIRMessaging.getFCMToken();
};
FCM.requestPermissions = () => {
return RNFIRMessaging.requestPermissions();
};
FCM.presentLocalNotification = (details) => {
details.local_notification = true;
RNFIRMessaging.presentLocalNotification(details);
};
FCM.scheduleLocalNotification = function(details) {
if (!details.id) {
throw new Error("id is required for scheduled notification");
}
details.local_notification = true;
RNFIRMessaging.scheduleLocalNotification(details);
};
FCM.getScheduledLocalNotifications = function() {
return RNFIRMessaging.getScheduledLocalNotifications();
};
FCM.cancelLocalNotification = (notificationID) => {
RNFIRMessaging.cancelLocalNotification(notificationID);
};
FCM.cancelAllLocalNotifications = () => {
RNFIRMessaging.cancelAllLocalNotifications();
};
FCM.setBadgeNumber = (number) => {
RNFIRMessaging.setBadgeNumber(number);
}
FCM.getBadgeNumber = () => {
return RNFIRMessaging.getBadgeNumber();
}
FCM.on = (event, callback) => {
const nativeEvent = eventsMap[event];
if (!nativeEvent) {
throw new Error('FCM invalid event');
}
const listener = DeviceEventEmitter.addListener(nativeEvent, callback);
return function remove() {
listener.remove();
};
};
FCM.subscribeToTopic = (topic) => {
RNFIRMessaging.subscribeToTopic(topic);
};
FCM.unsubscribeFromTopic = (topic) => {
RNFIRMessaging.unsubscribeFromTopic(topic);
};
FCM.send = (senderId, payload) => {
RNFIRMessaging.send(senderId, payload);
};
module.exports = FCM;