react-native-webrtc / react-native-callkeep

iOS CallKit framework and Android ConnectionService for React Native
ISC License
921 stars 444 forks source link

Additional improvements in headless mode #226

Closed jpudysz closed 4 years ago

jpudysz commented 4 years ago

Hello, I would like to create PR with additional improvements related to headless mode. Before I create PR please let me know if it's needed. My previous PR (#221 ) was left without any response so I'm trying to implement needed features on my fork and I can share them with community.

But let's go back to new improvements: I took code from @manuquentin (#223) and added a few changes:

With this PR we would be able to drop additional dependency like react-native-invoke-app.

Demo:

messaging().setBackgroundMessageHandler(async notificaiton => {
    return startCallFromBackgroundAndroid(notificaiton.data, headlessMode)
})

const startCallFromBackgroundAndroid = (payload, isHeadless) => {
    // setup RNCallKeep
   // set available

   RNCallKeep.addEventListener('answerCall', ({ callUUID }) => {
      RNCallKeep.openAppFromHeadlessMode(callUUID)
  })
}

// Later eg. after navigation did mount:

useAsyncEffect(async () => {
  const extras = await RNCallKeep.getExtrasFromHeadlessMode()

  if (extras) {
     navigation.navigate(ScreenNames.CallScreen, {
         roomUUID: extras.callUUID
     })
  }

}, [])
manuquentin commented 4 years ago

Hi @jpudysz, I'll take a look at your PR soon.

For the backToForeground, I've merged a #223 that will open the app if the activity if not started.

I don't understand the use of openAppFromHeadlessMode. Is it when you don't have firebase and so not access to setBackgroundMessageHandler ?

jpudysz commented 4 years ago

It's for the case when my Android app is killed (even with a locked screen).

Current behaviour:

With my PR:

maitzeth commented 4 years ago

Hello, Im having a similar problem, but I dont know if my implementation is good enough.

When I receive a call Push Notification from setBackgroundMessageHandler I attach all the event listeners but the app doesnt not open when I answer the IncomingCall.

I tried to install react-native-invoke-app but I think is deprecated, cuz doesnt work on Android 9 and 10.

I dont know if my problem is related to this.

manuquentin commented 4 years ago

Hi @maitzeth, I think you need backToForeground on Android to open you app.

maitzeth commented 4 years ago

Hi @maitzeth, I think you need backToForeground on Android to open you app.

Hello @manuquentin yes, I saw your last PR from yesterday.

This feature was needed. Thank you!

I have a little question: There is a way to open the app on setBackgroundMessageHandler from firebase listener instead of firing backToForeground on answerCall listener?

manuquentin commented 4 years ago

Hi @maitzeth, Yes I see no reason that backToForeground will not work in setBackgroundMessageHandler

maitzeth commented 4 years ago

@manuquentin I've write an issue something in Android 9 and 10 in this https://github.com/react-native-webrtc/react-native-callkeep/issues/227#issue-645603593 do you have any idea about this?

jpudysz commented 4 years ago

Hello everyone, I'm super busy and I can't contribute here, what's more, we are far behind each other. You can check my repo with a few additional improvements for Android (https://github.com/jpudysz/react-native-callkeep) - tested on production as I'm developing for my client's VoIP app.

I tried to create PR here, but I changed backToForeground logic and it differs from original repo. New functionality such as headless mode, locked screen are strictly connected with this function and I can't merge it. Ideally, we can take my ideas and merge it with the master (I don't mind and you can copy-paste my code under your PR). Ping me if I needed.

PS. I added changelog inside my repo, so you can check new functionalities. @manuquentin if you want to discuss how to merge it or you need some explanation ping/PM me.

nero2009 commented 3 years ago

Thank you so much @jpudysz . you fork helped me get add functionality that I really needed for my usecase

Thanks alot for sharing.

jpudysz commented 3 years ago

I'm happy that I was able to help someone. Cheers from Poland!

juanxog commented 2 years ago

Thanks you so much @jpudysz , very useful. solved my problem with backforeground and answerCall event. I have a new problem with openAppFromHeadlessMode, when i call it in setBackgroundMessageHandler of firebase with terminated state, it doesn't open my app only show (nativeUI answered) i would like to open my app and show my videocall screen. Additionally, i tried to use backForeground but the app doesn't open.

ch3tan03 commented 2 years ago

Thanks you so much @jpudysz , very useful. solved my problem with backforeground and answerCall event. I have a new problem with openAppFromHeadlessMode, when i call it in setBackgroundMessageHandler of firebase with terminated state, it doesn't open my app only show (nativeUI answered) i would like to open my app and show my videocall screen. Additionally, i tried to use backForeground but the app doesn't open.

Any update on this?

juanxog commented 2 years ago

@ch3tan03 use this fork https://github.com/jpudysz/react-native-callkeep

fukemy commented 2 years ago

hi, any solution for IOS? In case app killed I can not do anything. Can someone help

HalilFocic commented 2 years ago

@fukemy I have strugled a lot with iOS and app being killed. You have to install react-native-voip-push-notification package and adjust the iOS files according to their repo. Documentation is a bit messy but you will basically add lines to AppDelegate.m so it wakes the app. For me, after following instructions, app would start and after 4/5 seconds,it will catch the notification from background message handler. Hope i helped