-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathindex.android.js
81 lines (71 loc) · 2.06 KB
/
index.android.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
'use strict';
var {
NativeModules,
DeviceEventEmitter,
} = require('react-native');
var GcmModule = NativeModules.GcmModule;
var _notifHandlers = new Map();
var DEVICE_NOTIF_EVENT = 'remoteNotificationReceived';
var NOTIF_REGISTER_EVENT = 'remoteNotificationsRegistered';
var NOTIF_REGISTER_ERROR_EVENT = 'remoteNotificationsRegisteredError';
class GcmAndroid {
static addEventListener(type: string, handler: Function) {
var listener;
if (type === 'notification') {
listener = DeviceEventEmitter.addListener(
DEVICE_NOTIF_EVENT,
(notifData) => {
GcmAndroid.isInForeground = notifData.isInForeground;
var data = JSON.parse(notifData.dataJSON);
handler(new GcmAndroid(data));
}
);
} else if (type === 'register') {
listener = DeviceEventEmitter.addListener(
NOTIF_REGISTER_EVENT,
(registrationInfo) => {
handler(registrationInfo.deviceToken);
}
);
} else if (type === 'registerError') {
listener = DeviceEventEmitter.addListener(
NOTIF_REGISTER_ERROR_EVENT,
(info) => {
var error = new Error(info.message);
handler(error);
}
);
}
_notifHandlers.set(handler, listener);
}
static requestPermissions() {
GcmModule.requestPermissions();
}
static stopService() {
GcmModule.stopService();
}
static createNotification(infos) {
GcmModule.createNotification(infos);
}
static abandonPermissions() {
}
static checkPermissions(callback: Function) {
}
static removeEventListener(type: string, handler: Function) {
var listener = _notifHandlers.get(handler);
if (!listener) {
return;
}
listener.remove();
_notifHandlers.delete(handler);
}
constructor(data) {
this.data = data;
}
}
console.log('GcmAndroid.launchNotification internal', GcmAndroid.launchNotification);
if (GcmModule.launchNotification) {
GcmAndroid.launchNotification = JSON.parse(GcmModule.launchNotification);
}
GcmAndroid.isInForeground = true;
module.exports = GcmAndroid;