-
Notifications
You must be signed in to change notification settings - Fork 14
/
bgMessaging.js
34 lines (29 loc) · 1.31 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
34
//@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 + '/' + mediaType;
} else if (event === 'cancel') {
url = 'sylk://call/cancel/' + callUUID;
}
if (url) {
console.log('Wake up from push with URL', url);
SylkNative.launchMainActivity(encodeURI(url));
} else {
console.log('Do not wake up');
}
}
return Promise.resolve();
}