Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.7 kB
2
Indexable
Never
/**
 * @format
 */
import 'react-native-gesture-handler';
import { AppRegistry } from 'react-native';
import App from './App';
import { name as appName } from './app.json';
if (__DEV__) {
  import('./ReactotronConfig').then(() => console.log('Reactotron Configured'));
}
import RNCallKeep from 'react-native-callkeep';
import messaging from '@react-native-firebase/messaging';

 messaging().registerForRemoteNotifications();

// Register background handler
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
  console.log('quang debug index.js 12312321312', remoteMessage);
  if (Platform.OS === 'android') await RegisterCallKeep();
  RNCallKeep.displayIncomingCall('abc', 'test', 'test', 'generic', true);
});

AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => (remoteMessage) => {
  console.log('RNCallKeepBackgroundMessage', remoteMessage);

  return Promise.resolve();
});

AppRegistry.registerHeadlessTask(
  'RNCallKeepBackgroundMessage',
  () =>
    ({ name, callUUID, handle }) => {
      const options = {
        ios: {
          appName: 'Chat OTT',
        },
        android: {
          alertTitle: 'Permissions required',
          alertDescription: 'This application needs to access your phone accounts',
          cancelButton: 'Cancel',
          additionalPermissions: [],
          okButton: 'Okay',
          // selfManaged: true,
          // foregroundService: {
          //   channelId: 'com.videocallexample',
          //   channelName: 'VideoCallExample',
          //   notificationTitle: 'My app is running on background',
          //   //notificationIcon: 'Path to the resource icon of the notification',
          // },
        },
      };

      RNCallKeep.setup(options).then((accepted) => {
        if (!accepted) {
        }
        console.log('Call keep options accepted', accepted);
      });

      RNCallKeep.setAvailable(true);
      console.log('RNCallKeepBackgroundMessage', name, callUUID, handle);

      return Promise.resolve();
    }
);

const RegisterCallKeep = async () => {
  //RNCallKeep.removeEventListener('answerCall');
  //RNCallKeep.removeEventListener('endCall');
  await RNCallKeep.registerPhoneAccount({
    android: {
      alertTitle: 'Permissions required',
      alertDescription: 'This application needs to access your phone accounts',
      cancelButton: 'Cancel',
      additionalPermissions: [],
      okButton: 'Okay',
    },
  });
  await RNCallKeep.registerAndroidEvents();
  await RNCallKeep.setAvailable(true);
  //RNCallKeep.addEventListener('answerCall', answerCall);
  //RNCallKeep.addEventListener('endCall', endCall);
};

AppRegistry.registerComponent(appName, () => App);