forked from voximplant/react-native-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PushManager.android.js
64 lines (50 loc) · 1.27 KB
/
PushManager.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
/*
* Copyright (c) 2011-2018, Zingaya, Inc. All rights reserved.
*/
'use strict';
import React from 'react';
import {
Platform
} from 'react-native';
import loginManager from './LoginManager';
import VoxImplant from 'react-native-voximplant';
import FCM, {FCMEvent} from 'react-native-fcm';
FCM.on(FCMEvent.Notification, async (notif) => {
var remoteData = {};
remoteData.voximplant = notif.voximplant;
pushManager.pushNotificationReceived(remoteData);
});
FCM.on(FCMEvent.RefreshToken, (token) => {
console.log("Refresh token: " + token);
});
var pushToken = '';
class PushManager {
constructor() {
}
init() {
console.log("PushManager init");
if (Platform.OS === 'android') {
FCM.getFCMToken().then(token => {
console.log(token)
pushToken = token;
});
}
}
getPushToken() {
return pushToken;
}
pushNotificationReceived(notification) {
loginManager.getInstance().pushNotificationReceived(notification);
}
showLocalNotification(from) {
FCM.presentLocalNotification({
title: 'Incoming call',
body: 'from: ' + from,
priority: "high",
show_in_foreground: false,
number: 10
});
}
}
const pushManager = new PushManager();
export default pushManager;