react-native-notifyvisitors 4.1.1 → 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -5,324 +5,295 @@ import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
5
5
  const { RNNotifyvisitors } = NativeModules;
6
6
  const nvEventEmitter = new NativeEventEmitter(RNNotifyvisitors);
7
7
 
8
- const NV_PUSH_BANNER_CLICK_EVENT = 'nv_push_banner_click';
9
- const NV_CHAT_BOT_BUTTON_CLICK = 'nv_chat_bot_button_click';
10
-
11
- const NV_SHOW_CALLBACK = 'nv_show_callback';
12
- const NV_EVENT_CALLBACK = 'nv_event_callback';
13
- const NV_EVENT_SURVEY_CALLBACK = 'nv_common_show_event_callback';
14
-
15
-
16
- const pushCallbackFunction = {};
17
-
18
- const registerPushListener = function(){
19
- if (RNNotifyvisitors != null) {
20
- nvEventEmitter.addListener(NV_PUSH_BANNER_CLICK_EVENT, (data)=>{
21
- try{
22
- if(data != null && typeof pushCallbackFunction[NV_PUSH_BANNER_CLICK_EVENT] == "function"){
23
- if(Platform.OS == "ios"){
24
- pushCallbackFunction[NV_PUSH_BANNER_CLICK_EVENT](data.data);
25
- }else{
26
- pushCallbackFunction[NV_PUSH_BANNER_CLICK_EVENT](data);
27
- }
28
- }
29
- }catch(e){
30
- console.log(e);
31
- }
32
- });
33
- }
34
- };
35
-
36
- const chatBotButtonClickListener = function(){
37
- if (RNNotifyvisitors != null) {
38
- nvEventEmitter.addListener(NV_CHAT_BOT_BUTTON_CLICK, (data)=>{
39
- try{
40
- if(data != null && typeof pushCallbackFunction[NV_CHAT_BOT_BUTTON_CLICK] == "function"){
41
- pushCallbackFunction[NV_CHAT_BOT_BUTTON_CLICK](data);
42
- }
43
- }catch(e){
44
- console.log(e);
45
- }
46
- });
47
- }
48
- };
49
-
50
-
51
- const nvShowCallbackListener = function(){
52
- if (RNNotifyvisitors != null) {
53
- nvEventEmitter.addListener(NV_SHOW_CALLBACK, (data)=>{
54
- try{
55
- if(data != null && typeof pushCallbackFunction[NV_SHOW_CALLBACK] == "function"){
56
- if(Platform.OS == "ios"){
57
- pushCallbackFunction[NV_SHOW_CALLBACK](data.data);
58
- } else{
59
- pushCallbackFunction[NV_SHOW_CALLBACK](data);
60
- }
61
-
62
- }
63
- }catch(e){
64
- console.log(e);
65
- }
66
- });
67
- }
68
- };
69
-
8
+ const NV_CALLBACKS = {
9
+ GET_LINK_INFO: "nv_push_banner_click",
10
+ NV_CHAT_BOT_EVENT: "nv_chat_bot_button_click",
11
+ NV_SHOW: "nv_show_callback",
12
+ NV_EVENT: "nv_event_callback",
13
+ NV_EVENT_SURVEY: "nv_common_show_event_callback"
14
+ }
70
15
 
71
- const nvEventCallbackListener = function(){
72
- if (RNNotifyvisitors != null) {
73
- nvEventEmitter.addListener(NV_EVENT_CALLBACK, (data)=>{
74
- try{
75
- if(data != null && typeof pushCallbackFunction[NV_EVENT_CALLBACK] == "function"){
76
- if(Platform.OS == "ios"){
77
- pushCallbackFunction[NV_EVENT_CALLBACK](data.data);
78
- } else{
79
- pushCallbackFunction[NV_EVENT_CALLBACK](data);
80
- }
81
-
82
- }
83
- }catch(e){
84
- console.log(e);
85
- }
86
- });
87
- }
88
- };
16
+ const CALLBACKS_STACK = {};
17
+
18
+ const addListeners = function () {
19
+ if (!(RNNotifyvisitors != null)) {
20
+ return;
21
+ }
22
+ Object.keys(NV_CALLBACKS).forEach(val => {
23
+ nvEventEmitter.addListener(NV_CALLBACKS[val], (data) => {
24
+ try {
25
+ if (data != null && typeof CALLBACKS_STACK[NV_CALLBACKS[val]] == "function") {
26
+ if (Platform.OS == "ios") {
27
+ CALLBACKS_STACK[NV_CALLBACKS[val]](data.data);
28
+ } else {
29
+ CALLBACKS_STACK[NV_CALLBACKS[val]](data);
30
+ }
31
+ }
32
+ } catch (e) {
33
+ console.log(e);
34
+ }
35
+ })
36
+ })
37
+ }
89
38
 
90
- const nvEventSurveyCallback = function(){
91
- if (RNNotifyvisitors != null) {
92
- nvEventEmitter.addListener(NV_EVENT_SURVEY_CALLBACK, (data)=>{
93
- try{
94
- if(data != null && typeof pushCallbackFunction[NV_EVENT_SURVEY_CALLBACK] == "function"){
95
- if(Platform.OS == "ios"){
96
- pushCallbackFunction[NV_EVENT_SURVEY_CALLBACK](data.data);
97
- }else{
98
- pushCallbackFunction[NV_EVENT_SURVEY_CALLBACK](data);
99
- }
100
-
101
- }
102
- }catch(e){
103
- console.log(e);
104
- }
105
- });
106
- }
107
- };
39
+ addListeners();
108
40
 
109
- registerPushListener();
110
- chatBotButtonClickListener();
111
- nvShowCallbackListener();
112
- nvEventCallbackListener();
113
- nvEventSurveyCallback();
114
41
 
42
+ /* Native SDK Bridge Class */
115
43
  export default class Notifyvisitors{
116
44
 
45
+ /* 1 - Survery, InApp Banners */
117
46
  static show(tokens, customObjects, fragmentName, nvCallback){
47
+ console.log("NV- Show !!");
118
48
  try{
119
- pushCallbackFunction[NV_SHOW_CALLBACK] = nvCallback;
49
+ CALLBACKS_STACK[NV_CALLBACKS.NV_SHOW] = nvCallback;
120
50
  RNNotifyvisitors.show(tokens, customObjects, fragmentName, nvCallback);
121
51
  }catch(e){
122
52
  console.log(e);
123
53
  }
124
54
  }
125
55
 
126
- static showNotifications(dismissValue){
127
- try{
128
- if(Platform.OS == "ios"){
129
- dismissValue = dismissValue+"";
130
- }else{
131
- dismissValue = parseInt(dismissValue);
132
- }
133
- RNNotifyvisitors.showNotifications(dismissValue);
134
- }catch(e){
135
- console.log(e);
136
- }
137
-
138
- }
56
+ /* 2 - Notification Center */
57
+ static showNotifications(mAppInboxInfo, dismissValue) {
58
+ console.log("NV- Show Notifications !!");
59
+ try {
60
+ if (Platform.OS == "ios") {
61
+ dismissValue = dismissValue + "";
62
+ } else {
63
+ dismissValue = parseInt(dismissValue);
64
+ }
65
+ RNNotifyvisitors.showNotifications(mAppInboxInfo, dismissValue);
66
+ } catch (e) {
67
+ console.log(e);
68
+ }
69
+
70
+ }
71
+
139
72
 
73
+ /* 3 - Event Tracking */
140
74
  static event(eventName, attributes, ltv, scope, nvCallback){
75
+ console.log("NV- Events !!");
141
76
  try{
142
- pushCallbackFunction[NV_EVENT_CALLBACK] = nvCallback;
77
+ CALLBACKS_STACK[NV_CALLBACKS.NV_EVENT] = nvCallback;
143
78
  RNNotifyvisitors.event(eventName, attributes, ltv, scope, nvCallback);
144
79
  }catch(e){
145
80
  console.log(e);
146
81
  }
147
82
 
148
83
  }
149
-
150
- static stopNotifications(){
84
+
85
+ /* 4 - Login User */
86
+ static userIdentifier(userID, sJsonObject){
87
+ console.log("NV- User Identifier !!");
151
88
  try{
152
- RNNotifyvisitors.stopNotifications();
89
+ RNNotifyvisitors.userIdentifier(userID, sJsonObject);
153
90
  }catch(e){
154
91
  console.log(e);
155
92
  }
156
93
 
157
94
  }
158
95
 
159
- static stopPushNotifications(bValue){
96
+
97
+ /* 5 - chatbot */
98
+ static startChatBot(screenName, nvCallback){
99
+ console.log("NV- Chatbot !!");
160
100
  try{
161
- RNNotifyvisitors.stopPushNotifications(bValue);
101
+ CALLBACKS_STACK[NV_CALLBACKS.NV_CHAT_BOT_EVENT] = nvCallback;
102
+ RNNotifyvisitors.startChatBot(screenName);
162
103
  }catch(e){
163
- console.log(e);
104
+ console.log(e)
164
105
  }
165
-
166
106
  }
167
-
168
- static getNotificationDataListener(callback){
169
- try{
170
- if(Platform == "ios"){
171
- RNNotifyvisitors.getNotificationDataListener("fetchEvent");
172
- }
173
- RNNotifyvisitors.getNotificationDataListener(callback);
174
- }catch(e){
175
- console.log(e);
176
- }
177
-
178
- }
179
107
 
180
- static getNotificationCount(callback){
108
+ /* 6 - Push Notification Channel */
109
+ static createNotificationChannel(chId, chName, chDescription, chImportance,
110
+ enableLights, shouldVibrate, lightColor, soundFileName){
111
+ console.log("NV- Create Notification Channnel !!");
181
112
  try{
182
- RNNotifyvisitors.getNotificationCount(callback);
113
+ if (Platform.OS === 'ios') {
114
+ console.log("This function is not supported on IOS");
115
+ } else {
116
+ RNNotifyvisitors.createNotificationChannel(chId, chName,
117
+ chDescription, chImportance, enableLights, shouldVibrate, lightColor, soundFileName);
118
+ }
183
119
  }catch(e){
184
120
  console.log(e);
185
121
  }
186
-
187
122
  }
188
123
 
189
- static scheduleNotification(nid, tag, time, title, message, url, icon){
124
+ /* 7 - Push Notification Channel */
125
+ static deleteNotificationChannel(channelId){
126
+ console.log("NV- Delate Notification Channnel !!");
190
127
  try{
191
- RNNotifyvisitors.scheduleNotification(nid, tag, time, title, message, url, icon);
128
+ if (Platform.OS === 'ios') {
129
+ console.log("This function is not supported on IOS");
130
+ } else {
131
+ RNNotifyvisitors.deleteNotificationChannel(channelId);
132
+ }
192
133
  }catch(e){
193
134
  console.log(e);
194
135
  }
195
-
196
136
  }
197
137
 
198
- static userIdentifier(userID, sJsonObject){
138
+ /* 8 - Push Notification Channel Group */
139
+ static createNotificationChannelGroup(groupId, groupName){
140
+ console.log("NV- Create Notification Channnel Group !!");
199
141
  try{
200
- RNNotifyvisitors.userIdentifier(userID, sJsonObject);
142
+ if (Platform.OS === 'ios') {
143
+ console.log("This function is not supported on IOS");
144
+ } else {
145
+ RNNotifyvisitors.createNotificationChannelGroup(groupId, groupName);
146
+ }
201
147
  }catch(e){
202
148
  console.log(e);
203
149
  }
204
-
205
150
  }
206
151
 
207
- static stopGeofencePushforDateTime(dateTime, additionalHours){
152
+ /* 9 - Push Notification Channel Group */
153
+ static deleteNotificationChannelGroup(groupId){
154
+ console.log("NV- Delete Notification Channnel Group !!");
208
155
  try{
209
- RNNotifyvisitors.stopGeofencePushforDateTime(dateTime, additionalHours);
156
+ if (Platform.OS === 'ios') {
157
+ console.log("This function is not supported on IOS");
158
+ } else {
159
+ RNNotifyvisitors.deleteNotificationChannelGroup(groupId);
160
+ }
210
161
  }catch(e){
211
162
  console.log(e);
212
163
  }
213
-
214
164
  }
215
165
 
216
- static getLinkInfo(nvCallback){
217
- try{
218
- pushCallbackFunction[NV_PUSH_BANNER_CLICK_EVENT] = nvCallback;
219
- RNNotifyvisitors.getLinkInfo();
220
- }catch(e){
221
- console.log(e)
222
- }
166
+ /* 10 - Unread Push Notification Count */
167
+ static getNotificationCenterCount(tabCountInfo, callback) {
168
+ console.log("NV- Notification push Count !!");
169
+ try {
170
+ RNNotifyvisitors.getNotificationCenterCount(tabCountInfo, callback);
171
+ } catch (e) {
172
+ console.log(e);
173
+ }
223
174
 
224
- }
175
+ }
225
176
 
226
- static scrollViewDidScroll_iOS_only(){
227
- try{
228
- RNNotifyvisitors.scrollViewDidScroll_iOS_only();
229
- }catch(e){
230
- console.log(e);
231
- }
232
- }
177
+ /* 11 - Get FCM/APNS Device Token */
178
+ static getRegistrationToken(nvCallback) {
179
+ console.log("NV- FCM/APNS Device Token !!");
180
+ try {
181
+ RNNotifyvisitors.getRegistrationToken(nvCallback);
182
+ } catch (e) {
183
+ console.log(e)
184
+ }
185
+ }
186
+
187
+ /* 12 - Play Store / App Store Rating */
188
+ static requestInAppReview(nvCallback) {
189
+ console.log("NV- In App Review !!");
190
+ try {
191
+ RNNotifyvisitors.requestInAppReview(nvCallback);
192
+ } catch (e) {
193
+ console.log(e)
194
+ }
233
195
 
234
- static promptForPushNotificationsWithUserResponse(callback) {
235
- if (!checkIfInitialized()) return;
196
+ }
236
197
 
237
- if (Platform.OS === 'ios') {
238
- RNNotifyvisitors.promptForPushNotificationsWithUserResponse(callback);
239
- } else {
240
- console.log("This function is not supported on Android");
198
+ /* 13 - Category based Notification */
199
+ static subscribePushCategory(categoryInfo, unSubscribe2All) {
200
+ console.log("NV- Subscibe Push Category !!");
201
+ try {
202
+ RNNotifyvisitors.subscribePushCategory(categoryInfo, unSubscribe2All);
203
+ } catch (e) {
204
+ console.log(e)
241
205
  }
242
206
  }
243
207
 
244
- static setAutoStartPermission_android_only(){
208
+ /* 14 - Push /InApp / Notification Center Click Callback Data */
209
+ static getLinkInfo(nvCallback){
210
+ console.log("NV- Get Link Info !!");
245
211
  try{
246
- if (Platform.OS === 'ios') {
247
- console.log("This function is not supported on IOS");
248
- } else {
249
- RNNotifyvisitors.setAutoStartPermission();
250
- }
212
+ CALLBACKS_STACK[NV_CALLBACKS.GET_LINK_INFO] = nvCallback;
213
+ RNNotifyvisitors.getLinkInfo();
251
214
  }catch(e){
252
- console.log(e);
215
+ console.log(e)
253
216
  }
217
+
254
218
  }
255
219
 
256
220
 
257
- static startChatBot(screenName, nvCallback){
221
+ /* 15 - Unique NotifyVisitors Identification */
222
+ static getNvUID (callback){
223
+ console.log("NV- Get NV UID !!");
258
224
  try{
259
- pushCallbackFunction[NV_CHAT_BOT_BUTTON_CLICK] = nvCallback;
260
- RNNotifyvisitors.startChatBot(screenName);
225
+ RNNotifyvisitors.getNvUID(callback);
261
226
  }catch(e){
262
- console.log(e)
227
+ console.log(e);
263
228
  }
264
229
  }
265
230
 
266
- static getNvUID (callback){
231
+ /* 16 - JSon Data For Custom Notification Center */
232
+ static getNotificationDataListener(callback){
233
+ console.log("NV- Get Notification Data Listener !!");
267
234
  try{
268
- RNNotifyvisitors.getNvUID(callback);
235
+ if(Platform == "ios"){
236
+ RNNotifyvisitors.getNotificationDataListener("fetchEvent");
237
+ }
238
+ RNNotifyvisitors.getNotificationDataListener(callback);
269
239
  }catch(e){
270
240
  console.log(e);
271
241
  }
272
- }
242
+
243
+ }
273
244
 
274
- static createNotificationChannel(chId, chName, chDescription, chImportance, enableLights, shouldVibrate, lightColor, soundFileName){
245
+ /* 17 - Auto Start Library Android */
246
+ static setAutoStartPermission_android_only(){
247
+ console.log("NV- Auto Start Permission Android !!");
275
248
  try{
276
249
  if (Platform.OS === 'ios') {
277
250
  console.log("This function is not supported on IOS");
278
251
  } else {
279
- RNNotifyvisitors.createNotificationChannel(chId, chName, chDescription, chImportance, enableLights, shouldVibrate, lightColor, soundFileName);
252
+ RNNotifyvisitors.setAutoStartPermission();
280
253
  }
281
254
  }catch(e){
282
255
  console.log(e);
283
256
  }
284
257
  }
285
258
 
286
- static deleteNotificationChannel(channelId){
259
+ /* 18 - Stop Showing InApp Banner Survey */
260
+ static stopNotifications(){
261
+ console.log("NV- Stop Notification !!");
287
262
  try{
288
- if (Platform.OS === 'ios') {
289
- console.log("This function is not supported on IOS");
290
- } else {
291
- RNNotifyvisitors.deleteNotificationChannel(channelId);
292
- }
263
+ RNNotifyvisitors.stopNotifications();
293
264
  }catch(e){
294
265
  console.log(e);
295
266
  }
267
+
296
268
  }
297
269
 
298
- static createNotificationChannelGroup(groupId, groupName){
270
+ /* 19 - Stop Showing Location Push for a custom time */
271
+ static stopGeofencePushforDateTime(dateTime, additionalHours){
272
+ console.log("NV- Stop Geofence Push For Date Time !!");
299
273
  try{
300
- if (Platform.OS === 'ios') {
301
- console.log("This function is not supported on IOS");
302
- } else {
303
- RNNotifyvisitors.createNotificationChannelGroup(groupId, groupName);
304
- }
274
+ RNNotifyvisitors.stopGeofencePushforDateTime(dateTime, additionalHours);
305
275
  }catch(e){
306
276
  console.log(e);
307
277
  }
278
+
308
279
  }
309
-
310
- static deleteNotificationChannelGroup(groupId){
280
+
281
+ /* 20 - Triger Push Notification on Panel */
282
+ static scheduleNotification(nid, tag, time, title, message, url, icon){
283
+ console.log("NV- Schedule Notification !!");
311
284
  try{
312
- if (Platform.OS === 'ios') {
313
- console.log("This function is not supported on IOS");
314
- } else {
315
- RNNotifyvisitors.deleteNotificationChannelGroup(groupId);
316
- }
285
+ RNNotifyvisitors.scheduleNotification(nid, tag, time, title, message, url, icon);
317
286
  }catch(e){
318
287
  console.log(e);
319
288
  }
289
+
320
290
  }
321
291
 
322
-
292
+ /* 21 - Separate Callbacks For Events and Surveys */
323
293
  static getEventSurveyInfo(nvCallback){
294
+ console.log("NV- Get Event Survey Info !!");
324
295
  try{
325
- pushCallbackFunction[NV_EVENT_SURVEY_CALLBACK] = nvCallback;
296
+ CALLBACKS_STACK[NV_CALLBACKS.NV_EVENT_SURVEY] = nvCallback;
326
297
  RNNotifyvisitors.getEventSurveyInfo(nvCallback);
327
298
  }catch(e){
328
299
  console.log(e)
@@ -330,5 +301,39 @@ export default class Notifyvisitors{
330
301
 
331
302
  }
332
303
 
304
+ /* 22 - Depricated Function For Notification Count */
305
+ static getNotificationCount(callback) {
306
+ console.log("NV- Get Notification Count !!");
307
+ try {
308
+ RNNotifyvisitors.getNotificationCount(callback);
309
+ } catch (e) {
310
+ console.log(e);
311
+ }
312
+
313
+ }
314
+
315
+
316
+ /* 23 - IOS Specific */
317
+ static scrollViewDidScroll_iOS_only(){
318
+ console.log("NV- Scroll View Did Scroll IOS !!");
319
+ try{
320
+ RNNotifyvisitors.scrollViewDidScroll_iOS_only();
321
+ }catch(e){
322
+ console.log(e);
323
+ }
324
+ }
325
+
326
+ /* 24 - IOS Specific */
327
+ static promptForPushNotificationsWithUserResponse(callback) {
328
+ console.log("NV- Prompt For Push Notifications With UserResponse IOS !!");
329
+ if (!checkIfInitialized()) return;
330
+
331
+ if (Platform.OS === 'ios') {
332
+ RNNotifyvisitors.promptForPushNotificationsWithUserResponse(callback);
333
+ } else {
334
+ console.log("This function is not supported on Android");
335
+ }
336
+ }
337
+
333
338
  }
334
339