-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
99 lines (73 loc) · 2.88 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { NativeEventEmitter, NativeModules, Platform, DeviceEventEmitter } from 'react-native';
import Backendless from 'backendless';
const { RNBackendless, RNBackendlessEmitter } = require('./module');
const _initApp = Backendless.initApp;
const _registerDevice = Backendless.Messaging.registerDevice;
const _unregisterDevice = Backendless.Messaging.unregisterDevice;
function voidResolver(){}
Backendless.initApp = function (appId, apiKey) {
RNBackendless.setAppId(appId);
return _initApp.apply(this, arguments)
};
Backendless.Messaging.registerDevice = async function (deviceToken, channels, expiration) {
if (Array.isArray(deviceToken)) {
expiration = channels;
channels = deviceToken;
deviceToken = null
}
return Promise.resolve()
.then(async () => {
const device = await RNBackendless.registerDevice();
Backendless.setupDevice({
uuid : device.uuid,
version : device.version,
platform: Platform.OS,
});
const deviceRegistration = await _registerDevice.call(this, deviceToken || device.token, channels, expiration);
const pushTemplates = await Backendless.Messaging.getPushTemplates(Platform.OS);
await RNBackendless.setTemplates(pushTemplates);
return deviceRegistration
})
};
Backendless.Messaging.unregisterDevice = async function (deviceUid) {
return Promise.resolve()
.then(async () => {
const device = await RNBackendless.unregisterDevice();
Backendless.setupDevice({
uuid : device.uuid,
version : device.version,
platform: Platform.OS,
});
return _unregisterDevice.call(this)
})
};
Backendless.Messaging.getInitialNotificationAction = () => {
return RNBackendless.getInitialNotificationAction();
};
Backendless.Messaging.addPushNotificationListener = callback => {
RNBackendlessEmitter.addListener('notification', callback);
};
Backendless.Messaging.removePushNotificationListener = callback => {
RNBackendlessEmitter.removeListener('notification', callback);
};
Backendless.Messaging.addPushNotificationActionListener = callback => {
RNBackendlessEmitter.addListener('notificationAction', callback);
};
Backendless.Messaging.removePushNotificationActionListener = callback => {
RNBackendlessEmitter.removeListener('notificationAction', callback);
};
Backendless.Messaging.getAppBadgeNumber = () => {
return RNBackendless.getAppBadgeNumber();
};
Backendless.Messaging.setAppBadgeNumber = value => {
return RNBackendless.setAppBadgeNumber(value).then(voidResolver);
};
Backendless.Messaging.getNotifications = () => {
return RNBackendless.getNotifications();
};
Backendless.Messaging.cancelNotification = notificationId => {
return RNBackendless.cancelNotification(notificationId).then(voidResolver);
};
Backendless.Messaging.cancelAllNotifications = () => {
return RNBackendless.cancelAllNotifications().then(voidResolver);
};