Skip to content

Additional improvements in headless mode #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jpudysz opened this issue Jun 24, 2020 · 15 comments
Closed

Additional improvements in headless mode #226

jpudysz opened this issue Jun 24, 2020 · 15 comments

Comments

@jpudysz
Copy link

jpudysz commented Jun 24, 2020

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:

  • I left old functionality of backToForeground, just added improvement for silent fail in the headless mode
  • I introduced a new method openAppFromHeadlessMode which can take callUUID and saves it
  • Whenever we want (especially after a cold boot) we can use another method getExtrasFromHeadlessMode and redirect to user's call UI

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
Copy link
Contributor

manuquentin commented Jun 24, 2020

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
Copy link
Author

jpudysz commented Jun 24, 2020

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

Current behaviour:

  • app receives FCM push and runs the headless task
  • we can display CallKeep UI, handle call etc.

With my PR:

  • app receives FCM push and runs the headless task
  • CallKeep UI is visible
  • on answerCall I'm opening my app (cold boot) from the headless task and the user is redirected to my call screen UI

@maitzeth
Copy link

maitzeth commented Jun 24, 2020

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
Copy link
Contributor

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

@maitzeth
Copy link

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
Copy link
Contributor

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

@maitzeth
Copy link

@manuquentin I've write an issue something in Android 9 and 10 in this #227 (comment) do you have any idea about this?

@jpudysz
Copy link
Author

jpudysz commented Aug 10, 2020

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.

@jpudysz jpudysz closed this as completed Aug 10, 2020
@nero2009
Copy link

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

  • Answer call in lock screen
  • Custom call UI

Thanks alot for sharing.

@jpudysz
Copy link
Author

jpudysz commented Jul 1, 2021

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

@juanxog
Copy link

juanxog commented May 19, 2022

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
Copy link

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
Copy link

juanxog commented Jun 24, 2022

@fukemy
Copy link

fukemy commented Oct 18, 2022

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

@HalilFocic
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants