forked from b8ne/react-native-pusher-push-notifications
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (75 loc) · 2.31 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
import {
DeviceEventEmitter,
NativeEventEmitter,
NativeModules,
Platform,
} from 'react-native';
const { RNPusherPushNotifications, RNPusherEventHelper } = NativeModules;
const rnPusherPushNotificationsEmitter = new NativeEventEmitter(
RNPusherEventHelper
);
export default {
clearAllState: () => {
if (Platform.OS === 'ios') {
RNPusherPushNotifications.clearAllState();
} else {
RNPusherPushNotifications.clearAllState();
}
},
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);
}
},
setUserId: (userId, token, onError, onSuccess) => {
if (Platform.OS === 'ios') {
RNPusherPushNotifications.setUserId(userId, token, onError, onSuccess);
} else {
RNPusherPushNotifications.setUserId(userId, token, onError, onSuccess);
}
},
setOnSubscriptionsChangedListener: (onChange) => {
if (Platform.OS === 'ios') {
console.log('Not implemented yet');
} else {
RNPusherPushNotifications.setOnSubscriptionsChangedListener(onChange);
}
},
on: (eventName, callback) => {
if (Platform.OS === 'ios') {
return rnPusherPushNotificationsEmitter.addListener(eventName, payload => callback(payload));
} else {
return DeviceEventEmitter.addListener(eventName, payload => callback(payload));
}
},
};