-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.android.js
85 lines (72 loc) · 2.27 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
82
83
84
85
var FCM = require("./index-common.js");
var Plugin = com.noizeramp.nsfcm.Plugin;
var Listener = com.noizeramp.nsfcm.Listener;
// ------------------------------------------------------------------------------------------------
// Public API
// ------------------------------------------------------------------------------------------------
/**
* Registers onTokenRefresh listener.
*/
function setTokenRefreshListener(listener) {
Plugin.setTokenRefreshListener(new Listener({ callback: listener}));
}
/**
* Registers message listener.
*/
function setMessageListener(listener) {
Plugin.setMessageListener(new Listener({ callback: function(messageJSON, dataJSON) {
var message = messageJSON && JSON.parse(messageJSON);
var data = dataJSON && JSON.parse(dataJSON);
listener(message, data);
}}));
}
/**
* Requests the registration token.
*/
function getToken() {
return Plugin.getToken();
}
/**
* Subscribes to a certain topic.
*/
function subscribeToTopic(topic) {
Plugin.subscribeToTopic(topic);
}
/**
* Unsubscribes from a certain topic.
*/
function unsubscribeFromTopic(topic) {
Plugin.unsubscribeFromTopic(topic);
}
/**
* Returns whatever launch options we are passed by the OS in case the app was launched
* from a notification tap. If it's a normal launch, #false is returned.
*/
function launchNotificationData(args) {
if (args.android) {
var extras = args.android.getExtras();
if (extras) {
var from = extras.getString("from");
if (from) {
var keys = extras.keySet().toArray();
var data = {};
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
data[key] = extras.getString(key);
}
return data;
}
}
}
return false;
}
// ------------------------------------------------------------------------------------------------
// Exports
// ------------------------------------------------------------------------------------------------
FCM.setTokenRefreshListener = setTokenRefreshListener;
FCM.setMessageListener = setMessageListener;
FCM.getToken = getToken;
FCM.subscribeToTopic = subscribeToTopic;
FCM.unsubscribeFromTopic = unsubscribeFromTopic;
FCM.launchNotificationData = launchNotificationData;
module.exports = FCM;