forked from AGProjects/sylk-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bgMessaging.js
33 lines (27 loc) · 1.24 KB
/
bgMessaging.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
//@flow
import { NativeModules, AppState } from 'react-native';
const { SylkNative } = NativeModules;
export default async (remoteMessage) => {
//console.log('Push notification received', remoteMessage.data.event, 'in state', AppState.currentState);
if (AppState.currentState === "background") {
let event = remoteMessage.data.event;
let callUUID = remoteMessage.data['session-id'];
let to = remoteMessage.data['to_uri'];
let from = remoteMessage.data['from_uri'];
let displayName = remoteMessage.data['from_display_name'];
let mediaType = remoteMessage.data['media-type'];
let url;
if (event === 'incoming_conference_request') {
url = 'sylk://conference/incoming/' + callUUID + '/' + from + '/' + to + '/' + displayName + '/' + mediaType;
} else if (event === 'incoming_session') {
url = 'sylk://call/incoming/' + callUUID + '/' + from + '/' + to + '/' + displayName;
} else if (event === 'cancel') {
url = 'sylk://call/cancel/' + callUUID;
}
if (url) {
//console.log('Wake up from push with URL', url);
SylkNative.launchMainActivity(encodeURI(url));
}
}
return Promise.resolve();
}