forked from SelligentMarketingCloud/MobileSDK-ReactNative
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.android.js
256 lines (225 loc) · 8.42 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
// Android specific methods
import { NativeEventEmitter, NativeModules } from 'react-native'
import SelligentConstants from './constants'
import SelligentHelpers from './helpers'
const { RNSelligent } = NativeModules
const RNSEventEmitter = new NativeEventEmitter(RNSelligent)
export default {
// Basic SMManager
// InAppMessage
/**
* Enable/disable in-app messages on Android.
*
* Android specific: if args is a boolean set to "true", the in-app messages will be enabled with a default refresh type "DAY".
*
* @param {function} successCallback Callback function on success.
* @param {function} errorCallback Callback function on error.
* @param {(boolean|InAppMessageRefreshType)} options Boolean to enable/disable in-app messages or an enum InAppMessageRefreshType to enable and set which in-app messages should be enabled.
*/
enableInAppMessages: function (successCallback, errorCallback, enabled) {
if (!SelligentHelpers.typeMatches(enabled, 'number') && !SelligentHelpers.typeMatches(enabled, 'boolean')) {
errorCallback(SelligentHelpers.wrongArgumentError('Expected a boolean or a number.'))
return
}
successCallback(SelligentHelpers.SUCCESS)
RNSelligent.enableInAppMessages({ enabled })
return
},
/**
* To check if in app messages are enabled on Android.
*
* @param {function} successCallback Callback function on success.
*/
areInAppMessagesEnabled: function (successCallback) {
return RNSelligent.areInAppMessagesEnabled(successCallback)
},
/**
* Display message on Android.
*
* @param {function} successCallback Callback function on success.
* @param {function} errorCallback Callback function on error.
* @param {string} messageId Id of the message.
*/
displayMessage: function (successCallback, errorCallback, messageId) {
if (!SelligentHelpers.typeMatches(messageId, 'string')) {
errorCallback(SelligentHelpers.wrongArgumentError('Expected a string.'))
return
}
successCallback(SelligentHelpers.SUCCESS)
RNSelligent.displayMessage(messageId)
return
},
// Log
/**
* Enable logging messages on Android.
*
* @param {function} successCallback Callback function on success.
* @param {function} errorCallback Callback function on error.
* @param {boolean} shouldEnableLoggingMessages Boolean to enable/disable logging messages on Android.
*/
enableAndroidLogging: function (successCallback, errorCallback, enabled) {
if (!SelligentHelpers.typeMatches(enabled, 'boolean')) {
errorCallback(SelligentHelpers.wrongArgumentError('Expected a boolean.'))
return
}
successCallback(SelligentHelpers.SUCCESS)
RNSelligent.setDebug(enabled)
return
},
// Remote Notification
/**
* Check if notifications are enabled or disabled.
*
* @param {function} successCallback Callback function on success.
*/
areNotificationsEnabled: function (successCallback) {
RNSelligent.areNotificationsEnabled(successCallback)
return
},
/**
* Set the resource for the small icon for notifications on Android.
*
* @param {function} successCallback Callback function on success.
* @param {function} errorCallback Callback function on error.
* @param {string} iconName Name of the icon.
*/
setNotificationSmallIcon: function (successCallback, errorCallback, iconName) {
if (!SelligentHelpers.typeMatches(iconName, 'string') || iconName.length === 0) {
errorCallback(SelligentHelpers.wrongArgumentError('Expected a string (not empty).'))
return
}
successCallback(SelligentHelpers.SUCCESS)
RNSelligent.setNotificationSmallIcon(iconName)
return
},
/**
* Set the resource for the large icon for notifications on Android.
*
* @param {function} successCallback Callback function on success.
* @param {function} errorCallback Callback function on error.
* @param {string} iconName Name of the icon.
*/
setNotificationLargeIcon: function (successCallback, errorCallback, iconName) {
if (!SelligentHelpers.typeMatches(iconName, 'string') || iconName.length === 0) {
errorCallback(SelligentHelpers.wrongArgumentError('Expected a string (not empty).'))
return
}
successCallback(SelligentHelpers.SUCCESS)
RNSelligent.setNotificationLargeIcon(iconName)
return
},
/**
* Set the color for the icon for notifications on Android.
*
* @param {function} successCallback Callback function on success.
* @param {function} errorCallback Callback function on error.
* @param {string} color The color for the notification.
*/
setNotificationIconColor: function (successCallback, errorCallback, color) {
if (!SelligentHelpers.typeMatches(color, 'string') || color.length === 0) {
errorCallback(SelligentHelpers.wrongArgumentError('Expected a string (not empty).'))
return
}
const _successCallback = () => {
successCallback(SelligentHelpers.SUCCESS)
}
RNSelligent.setNotificationIconColor(color, _successCallback, errorCallback)
return
},
/**
* Set the notification activity on Android.
*
* @param {function} successCallback Callback function on success.
* @param {function} errorCallback Callback function on error.
* @param {string} activityName The name of the activity.
*/
setNotificationActivity: function (successCallback, errorCallback, activityName) {
if (!SelligentHelpers.typeMatches(activityName, 'string') || activityName.length === 0) {
errorCallback(SelligentHelpers.wrongArgumentError('Expected a string (not empty).'))
return
}
const _successCallback = () => {
successCallback(SelligentHelpers.SUCCESS)
}
RNSelligent.setNotificationActivity(activityName, _successCallback, errorCallback)
return
},
/**
* Get GCM Token
*
* @param {function} successCallback Callback function on success.
*/
getGCMToken: function (successCallback) {
RNSelligent.getGCMToken(successCallback)
return
},
/**
* Get remote messages display type.
*
* @param {function} successCallback Callback function on success.
* @param {function} errorCallback Callback function on error.
*/
getRemoteMessagesDisplayType: function (successCallback) {
RNSelligent.getRemoteMessagesDisplayType(successCallback)
return
},
// Broadcasts Events
/**
* Subscribe to events.
*
* @param {function} successCallback Callback function on success.
* @param {function} errorCallback Callback function on error.
* @param {function} eventCallback Callback function on event.
* @param {array} customEvents Array of custom events to subscribe to.
*/
subscribeToEvents: function (successCallback, errorCallback, eventCallback, customEvents = []) {
if (customEvents !== undefined) {
if (!SelligentHelpers.typeMatches(customEvents, 'array')) {
errorCallback(SelligentHelpers.createTypeErrorMessage('customEvents', customEvents, 'array'))
return
}
// check if values are all strings
var arrayLength = customEvents.length
for (var i = 0; i < arrayLength; i++) {
if (!SelligentHelpers.typeMatches(customEvents[i], 'string')) {
errorCallback(SelligentHelpers.wrongArgumentError('Expected an array of strings.'))
return
}
}
}
RNSEventEmitter.addListener(SelligentConstants.BroadcastEventType.BUTTON_CLICKED, eventCallback);
RNSEventEmitter.addListener(SelligentConstants.BroadcastEventType.RECEIVED_IN_APP_MESSAGE, eventCallback);
RNSEventEmitter.addListener(SelligentConstants.BroadcastEventType.WILL_DISPLAY_NOTIFICATION, eventCallback);
RNSEventEmitter.addListener(SelligentConstants.BroadcastEventType.WILL_DISMISS_NOTIFICATION, eventCallback);
RNSEventEmitter.addListener(SelligentConstants.BroadcastEventType.RECEIVED_GCM_TOKEN, eventCallback);
successCallback(SelligentHelpers.SUCCESS)
RNSelligent.subscribeToEvents(customEvents)
return
},
/**
* Subscribe to event.
*
* @param {function} eventCallback Callback function on event.
* @param {string} eventName Name of the event to subscribe to.
*/
subscribeToEvent: function (eventCallback, eventName) {
RNSEventEmitter.addListener(eventName, eventCallback);
return
},
/**
* Set the firebase (GCM) token
*
* @param {function} successCallback Callback function on success.
* @param {function} errorCallback Callback function on error.
* @param {string} token the firebase token.
*/
setFirebaseToken: function (successCallback, errorCallback, token) {
if (!SelligentHelpers.typeMatches(token, 'string') || token.length === 0) {
errorCallback(SelligentHelpers.wrongArgumentError('Expected a string (not empty).'))
return
}
successCallback(SelligentHelpers.SUCCESS)
RNSelligent.setFirebaseToken(token)
return
},
}