wip: working android
This commit is contained in:
parent
c3cd9fa701
commit
bed57ba863
|
@ -1,60 +1,61 @@
|
||||||
import notifee, { AndroidCategory, AndroidImportance, AndroidVisibility } from '@notifee/react-native';
|
import notifee, { AndroidCategory, AndroidImportance, AndroidVisibility } from '@notifee/react-native';
|
||||||
import messaging from '@react-native-firebase/messaging';
|
import messaging from '@react-native-firebase/messaging';
|
||||||
import ejson from 'ejson';
|
import ejson from 'ejson';
|
||||||
import { Alert } from 'react-native';
|
|
||||||
|
|
||||||
import i18n from '../../i18n';
|
import i18n from '../../i18n';
|
||||||
import { BACKGROUND_PUSH_COLOR } from '../constants';
|
import { BACKGROUND_PUSH_COLOR } from '../constants';
|
||||||
|
import { store } from '../store/auxStore';
|
||||||
|
import { deepLinkingClickCallPush } from '../../actions/deepLinking';
|
||||||
|
|
||||||
export const backgroundNotificationHandler = async (): Promise<void> => {
|
export const backgroundNotificationHandler = async (): Promise<void> => {
|
||||||
// 1. get info on the device and the Power Manager settings
|
// // 1. get info on the device and the Power Manager settings
|
||||||
const powerManagerInfo = await notifee.getPowerManagerInfo();
|
// const powerManagerInfo = await notifee.getPowerManagerInfo();
|
||||||
if (powerManagerInfo.activity) {
|
// if (powerManagerInfo.activity) {
|
||||||
// 2. ask your users to adjust their settings
|
// // 2. ask your users to adjust their settings
|
||||||
Alert.alert(
|
// Alert.alert(
|
||||||
'Restrictions Detected',
|
// 'Restrictions Detected',
|
||||||
'To ensure notifications are delivered, please adjust your settings to prevent the app from being killed',
|
// 'To ensure notifications are delivered, please adjust your settings to prevent the app from being killed',
|
||||||
[
|
// [
|
||||||
// 3. launch intent to navigate the user to the appropriate screen
|
// // 3. launch intent to navigate the user to the appropriate screen
|
||||||
{
|
// {
|
||||||
text: 'OK, open settings',
|
// text: 'OK, open settings',
|
||||||
onPress: notifee.openPowerManagerSettings
|
// onPress: notifee.openPowerManagerSettings
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
text: 'Cancel',
|
// text: 'Cancel',
|
||||||
onPress: () => {
|
// onPress: () => {
|
||||||
// TODO: handle cancel
|
// // TODO: handle cancel
|
||||||
},
|
// },
|
||||||
style: 'cancel'
|
// style: 'cancel'
|
||||||
}
|
// }
|
||||||
],
|
// ],
|
||||||
{ cancelable: false }
|
// { cancelable: false }
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
const batteryOptimizationEnabled = await notifee.isBatteryOptimizationEnabled();
|
// const batteryOptimizationEnabled = await notifee.isBatteryOptimizationEnabled();
|
||||||
if (batteryOptimizationEnabled) {
|
// if (batteryOptimizationEnabled) {
|
||||||
// 2. ask your users to disable the feature
|
// // 2. ask your users to disable the feature
|
||||||
Alert.alert(
|
// Alert.alert(
|
||||||
'Restrictions Detected',
|
// 'Restrictions Detected',
|
||||||
'To ensure notifications are delivered, please disable battery optimization for the app.',
|
// 'To ensure notifications are delivered, please disable battery optimization for the app.',
|
||||||
[
|
// [
|
||||||
// 3. launch intent to navigate the user to the appropriate screen
|
// // 3. launch intent to navigate the user to the appropriate screen
|
||||||
{
|
// {
|
||||||
text: 'OK, open settings',
|
// text: 'OK, open settings',
|
||||||
onPress: notifee.openBatteryOptimizationSettings
|
// onPress: notifee.openBatteryOptimizationSettings
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
text: 'Cancel',
|
// text: 'Cancel',
|
||||||
onPress: () => {
|
// onPress: () => {
|
||||||
// TODO: handle cancel
|
// // TODO: handle cancel
|
||||||
},
|
// },
|
||||||
style: 'cancel'
|
// style: 'cancel'
|
||||||
}
|
// }
|
||||||
],
|
// ],
|
||||||
{ cancelable: false }
|
// { cancelable: false }
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
// videoConf channel
|
// videoConf channel
|
||||||
await notifee.createChannel({
|
await notifee.createChannel({
|
||||||
|
@ -62,13 +63,20 @@ export const backgroundNotificationHandler = async (): Promise<void> => {
|
||||||
name: 'Video Call',
|
name: 'Video Call',
|
||||||
lights: true,
|
lights: true,
|
||||||
vibration: true,
|
vibration: true,
|
||||||
importance: AndroidImportance.HIGH
|
importance: AndroidImportance.HIGH,
|
||||||
|
sound: 'ringtone'
|
||||||
});
|
});
|
||||||
|
|
||||||
notifee.onBackgroundEvent(
|
notifee.onBackgroundEvent(
|
||||||
event =>
|
event =>
|
||||||
new Promise(() => {
|
new Promise(() => {
|
||||||
console.log('onBackgroundEvent', event);
|
console.log('event', event);
|
||||||
|
if (event.detail.pressAction?.id === 'accept' || event.detail.pressAction?.id === 'decline') {
|
||||||
|
store.dispatch(deepLinkingClickCallPush(event.detail?.notification?.data));
|
||||||
|
notifee.cancelNotification(
|
||||||
|
getNumbersAndLettersOnly(event.detail?.notification?.data.rid + event.detail?.notification?.data.caller._id)
|
||||||
|
);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -81,7 +89,6 @@ function getNumbersAndLettersOnly(inputString: string) {
|
||||||
const setBackgroundNotificationHandler = (): void => {
|
const setBackgroundNotificationHandler = (): void => {
|
||||||
messaging().setBackgroundMessageHandler(async (n: any) => {
|
messaging().setBackgroundMessageHandler(async (n: any) => {
|
||||||
const notification = ejson.parse(n.data.ejson);
|
const notification = ejson.parse(n.data.ejson);
|
||||||
console.log('setBackgroundMessageHandler', n);
|
|
||||||
if (notification?.notificationType === 'videoconf') {
|
if (notification?.notificationType === 'videoconf') {
|
||||||
if (notification.status === 0) {
|
if (notification.status === 0) {
|
||||||
await notifee.displayNotification({
|
await notifee.displayNotification({
|
||||||
|
@ -95,7 +102,6 @@ const setBackgroundNotificationHandler = (): void => {
|
||||||
visibility: AndroidVisibility.PUBLIC,
|
visibility: AndroidVisibility.PUBLIC,
|
||||||
importance: AndroidImportance.HIGH,
|
importance: AndroidImportance.HIGH,
|
||||||
smallIcon: 'ic_notification',
|
smallIcon: 'ic_notification',
|
||||||
timestamp: Date.now(),
|
|
||||||
color: BACKGROUND_PUSH_COLOR,
|
color: BACKGROUND_PUSH_COLOR,
|
||||||
actions: [
|
actions: [
|
||||||
{
|
{
|
||||||
|
@ -108,11 +114,16 @@ const setBackgroundNotificationHandler = (): void => {
|
||||||
{
|
{
|
||||||
title: i18n.t('decline'),
|
title: i18n.t('decline'),
|
||||||
pressAction: {
|
pressAction: {
|
||||||
id: 'decline'
|
id: 'decline',
|
||||||
|
launchActivity: 'default'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
lightUpScreen: true
|
lightUpScreen: true,
|
||||||
|
loopSound: true,
|
||||||
|
sound: 'ringtone',
|
||||||
|
autoCancel: false,
|
||||||
|
ongoing: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue