chore: init CustomCallActivity

This commit is contained in:
GleidsonDaniel 2023-09-28 09:09:07 -03:00
parent 79c6e6b014
commit b3a07570ab
6 changed files with 160 additions and 2 deletions

View File

@ -81,5 +81,13 @@
<data android:mimeType="*/*" />
</intent-filter>
</activity>
<activity
android:name="chat.rocket.reactnative.CustomCallActivity"
android:showWhenLocked="true"
android:turnScreenOn="true"
android:launchMode="singleTop"
android:showOnLockScreen="true"
android:theme="@style/AppTheme"
/>
</application>
</manifest>

View File

@ -0,0 +1,10 @@
package chat.rocket.reactnative;
import com.facebook.react.ReactActivity;
public class CustomCallActivity extends ReactActivity {
@Override
protected String getMainComponentName() {
return "CallRocketChatRN";
}
}

View File

@ -1,5 +1,6 @@
{
"name": "RocketChatRN",
"share": "ShareRocketChatRN",
"displayName": "RocketChatRN"
"displayName": "RocketChatRN",
"call": "CallRocketChatRN"
}

13
app/call.tsx Normal file
View File

@ -0,0 +1,13 @@
import { View, Text } from 'react-native';
import React from 'react';
const call = () => {
console.log('call');
return (
<View style={{ flex: 1 }}>
<Text>call</Text>
</View>
);
};
export default call;

View File

@ -0,0 +1,120 @@
import notifee, { AndroidCategory, AndroidImportance, AndroidVisibility } from '@notifee/react-native';
import messaging from '@react-native-firebase/messaging';
import { Alert } from 'react-native';
import { INotification } from '../../definitions';
export const backgroundNotificationHandler = async (): Promise<void> => {
// 1. get info on the device and the Power Manager settings
const powerManagerInfo = await notifee.getPowerManagerInfo();
if (powerManagerInfo.activity) {
// 2. ask your users to adjust their settings
Alert.alert(
'Restrictions Detected',
'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
{
text: 'OK, open settings',
onPress: notifee.openPowerManagerSettings
},
{
text: 'Cancel',
onPress: () => {
// TODO: handle cancel
},
style: 'cancel'
}
],
{ cancelable: false }
);
}
const batteryOptimizationEnabled = await notifee.isBatteryOptimizationEnabled();
if (batteryOptimizationEnabled) {
// 2. ask your users to disable the feature
Alert.alert(
'Restrictions Detected',
'To ensure notifications are delivered, please disable battery optimization for the app.',
[
// 3. launch intent to navigate the user to the appropriate screen
{
text: 'OK, open settings',
onPress: notifee.openBatteryOptimizationSettings
},
{
text: 'Cancel',
onPress: () => {
// TODO: handle cancel
},
style: 'cancel'
}
],
{ cancelable: false }
);
await notifee.createChannel({
id: 'call',
name: 'Video Call',
lights: true,
vibration: true,
importance: AndroidImportance.HIGH,
vibrationPattern: [300, 500]
});
}
notifee.registerForegroundService(
notification =>
new Promise(() => {
console.log('registerForegroundService', notification);
})
);
notifee.onBackgroundEvent(async event => {
console.log('onBackgroundEvent', event);
});
};
const setBackgroundNotificationHandler = async (): Promise<void> => {
messaging().setBackgroundMessageHandler(async (notification: INotification) => {
console.log('backgroundMessageHandler', notification);
await notifee.displayNotification({
title: '(21) 1234-1234',
body: 'Incoming call',
android: {
channelId: 'call',
category: AndroidCategory.CALL,
visibility: AndroidVisibility.PUBLIC,
importance: AndroidImportance.HIGH,
smallIcon: 'ic_launcher',
timestamp: Date.now(),
showTimestamp: true,
pressAction: {
id: 'default',
launchActivity: 'chat.rocket.reactnative.CustomCallActivity'
},
actions: [
{
title: 'Accept',
pressAction: {
id: 'accept',
launchActivity: 'default'
}
},
{
title: 'Decline',
pressAction: {
id: 'reject'
}
}
],
fullScreenAction: {
id: 'default',
launchActivity: 'chat.rocket.reactnative.CustomCallActivity'
}
}
});
});
};
setBackgroundNotificationHandler();

View File

@ -2,7 +2,8 @@ import 'react-native-gesture-handler';
import 'react-native-console-time-polyfill';
import { AppRegistry } from 'react-native';
import { name as appName, share as shareName } from './app.json';
import { name as appName, share as shareName, call as callName } from './app.json';
import { isFDroidBuild } from './app/lib/constants/environment';
if (__DEV__) {
require('./app/ReactotronConfig');
@ -18,8 +19,13 @@ if (__DEV__) {
console.info = () => {};
}
if (!isFDroidBuild) {
require('./app/lib/notifications/backgroundNotificationHandler');
}
AppRegistry.registerComponent(appName, () => require('./app/index').default);
AppRegistry.registerComponent(shareName, () => require('./app/share').default);
AppRegistry.registerComponent(callName, () => require('./app/call').default);
// For storybook, comment everything above and uncomment below
// import 'react-native-gesture-handler';