forked from ZeptInc/react-native-pusher-push-notifications
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
67 lines (64 loc) · 2.03 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
import {
DeviceEventEmitter,
NativeEventEmitter,
NativeModules,
Platform,
} from 'react-native';
const { RNPusherPushNotifications, RNPusherEventHelper } = NativeModules;
const rnPusherPushNotificationsEmitter = new NativeEventEmitter(
RNPusherEventHelper
);
const errorCallback = callback => (statusCode, response) =>
callback && callback(statusCode, response);
const successCallback = callback => () => callback && callback();
export default {
setInstanceId: instanceId => {
if (Platform.OS === 'ios') {
RNPusherPushNotifications.setInstanceId(instanceId);
} else {
RNPusherPushNotifications.setAppKey(instanceId);
}
},
subscribe: (channel, onError, onSuccess) => {
if (Platform.OS === 'ios') {
RNPusherPushNotifications.subscribe(channel, onError);
} else {
RNPusherPushNotifications.subscribe(channel, onError, onSuccess);
}
},
setSubscriptions: (interests, onError) => {
if (Platform.OS === 'ios') {
RNPusherPushNotifications.setSubscriptions(interests, onError);
} else {
console.log('Not implemented yet');
}
},
getSubscriptions: (onSuccess, onError) => {
if (Platform.OS === 'ios') {
console.log('Not implemented yet');
} else {
RNPusherPushNotifications.getSubscriptions(onSuccess, onError);
}
},
unsubscribe: (channel, onError, onSuccess) => {
if (Platform.OS === 'ios') {
RNPusherPushNotifications.unsubscribe(channel, onError);
} else {
RNPusherPushNotifications.unsubscribe(channel, onError, onSuccess);
}
},
setOnSubscriptionsChangedListener: (onChange) => {
if (Platform.OS === 'ios') {
console.log('Not implemented yet');
} else {
RNPusherPushNotifications.setOnSubscriptionsChangedListener(onChange);
}
},
on: (eventName, callback) => {
if (Platform.OS === 'ios') {
rnPusherPushNotificationsEmitter.addListener(eventName, payload => callback(payload));
} else {
DeviceEventEmitter.addListener(eventName, payload => callback(payload));
}
},
};