voximplant / react-native-voximplant

Voximplant mobile SDK for React Native (iOS/Android)
http://voximplant.com
205 stars 39 forks source link

Problems to handle call when app not started #90

Open Linoa65 opened 5 years ago

Linoa65 commented 5 years ago

Hello !

I open this issue because I need to handle call in all states of app, even the app is not started.

I implemented this kind of logic to simplify the code :

Foreground : OK for android and iOS, the call is get with classic event incoming call (already logged) or if not logged (possible timeout) you receive data-only message from Voximplant, then login, then handle call.

Background (app not closed) : OK for android and iOS, same logic than foreground, but in android case, wakeup the app to foreground, and iOS case, print a notification to open app before answer or reject call.

Background (app closed) : OK for iOS. I need to login into firebase before, because some data or needed to display call. With iOS I use RNVoipPushNotification, which works perfectly. My notification is handled, then stored. After that, the app is started, it login into firebase and vi, then handle the call with notification previously stored. Everything seems to be fine. For Android, the same behavior happens, so I handle notification, stored it, start app, login, then handle notification stored to run my incomingCall method. Sadly it doesn't works on Android. My incomingCall method is not called.

I checked logs, and the notification is correctly handled by VI :

VOXSDK  : Client [LOGGED_IN] handlePushNotification: message = {...}

I'm pretty sure that the client is in a good state before handle notification, and the problem is internal to VI or maybe a problem about my implementation, but I'm unable to know why the event is not sent.

If you need additional informations, feel free to ask it, and I hope I give all needed information to find out where this problem is situated.

I have problem to open my app automatically when all data are loaded, but even if I open it manually, I get this line printed in my logs (cf: snippet above).

Thanks ! Florient

YuliaGrigorieva commented 5 years ago

Hello @Linoa65 ,

Is the issue 100% reproducible? What is the time iterval between push notification received in your app (i.e. before you start handle it) and this line in the logs (i.e. VOXSDK : Client [LOGGED_IN] handlePushNotification: ... ) ?

Best regards, Yulia Grigorieva

Linoa65 commented 5 years ago

In my case, the issue happens each time, I'm unable to catch the call in this case. Maybe I can access to some logs to help you ? My case is really specific because I need to login to some services before display call, and maybe there is conflicts with firebase, I don't know...

The time interval is about 5-7 seconds, and it happens only on android, so the JS code seems to be fine because I have no problems on iOs.

Really thanks for your fast answer ! Florient

YuliaGrigorieva commented 5 years ago

Hello @Linoa65 ,

Due to the issue is 100% reproducible, I suppose it can be caused by invalid push paylod data passed to the Voximplant SDK.

Please check that you pass an object in the following format:

voximplant= {
"callid":"<...>",
"sessionid":"<...>",
"addr":"<...>",
"display_name":"<...>",
"userid":"<...>"
}

Some modules that provide Firebase implementation may insert the push payload to an addidional structure.

So, in the Voximplant SDK logs you should see a message like this

I/VOXSDK: Client [DISCONNECTED] handlePushNotification: message = {voximplant={"callid":"<...>","sessionid":"<...>","addr":"<...>","display_name":"<...>","userid":"<...>"}}

Best regards, Yulia Grigorieva

Linoa65 commented 5 years ago

Hello @YuliaGrigorieva

I checked my logs, and the format is OK. It weird because when I'm in the app, foreground, and after a time in debug mode it's possible to be logged out, so I receive the notification when I get called like I'm not in the app and it works good.

My problem with notifications happens only in this case, when the app is closed.

When I receive notification as callee, the app starts is background, connect to firebase and Voximplant, then handle the call. So I'm totally logged when I handle the notification, and I always get this line in logs :

08-02 16:22:19.793 13697 13815 I VOXSDK  : Client [LOGGED_IN] handlePushNotification: message = {voximplant={"callid":"...","sessionid":"...","addr":"xxx.xxx.xxx.xx:xxxx","display_name":"...","userid":"..."}}
08-02 16:22:19.801 13697 13811 I VOXSDK  : Signaling: SEND: {"name":"pushFeedback","params":[{"callid":"...","sessionid":"...","addr":"xxx.xx.xx.xxx:xxxx","display_name":"...","userid":"..."}]}

I'm only supposing, but it's possible the problem is just about the listener of incoming call is not correctly set ?

EDIT : When a call works, the logs are the same, but after that I have correct behavior :

08-02 17:09:54.680 16889 17056 I VOXSDK  : Call [09567da9d6eec3f7.1564758596.2217171, NOT_STARTED]CallIn: answer
08-02 17:09:54.680 16889 17056 D VOXSDK  : PCVideoParameters: Preferred video codec: VP8
08-02 17:09:54.680 16889 17056 I VOXSDK  : Call [09567da9d6eec3f7.1564758596.2217171, NOT_STARTED]CallIn: answer: video flags are provided: receive: true, send: false
08-02 17:09:54.680 16889 17056 I VOXSDK  : Call [09567da9d6eec3f7.1564758596.2217171, NOT_STARTED]start

I tried to add listener just before handling call but it didn't work too, I don't understand the source of the problem...

Sincerely Florient

YuliaGrigorieva commented 5 years ago

Hello @Linoa65 ,

Could you please check that you have the following lines in the logs:

I/VOXSDK: Signaling: onMessage: {"name" : "handleIncomingConnection" , ....
...
I/VOXSDK: Invoke onIncomingCall

Best regards, Yulia Grigorieva

YuliaGrigorieva commented 5 years ago

Could you please also try reproducing the issue on the demo app?

Linoa65 commented 5 years ago

Thank you for help ! I finally found my problem, there was a problem in the logging state when app is started from closed state, but I found a fix for it. Now, when my app is closed, I can handle call without problem but I need to open my app manually when the call is received to trigger the connection to VoxImplant.

After investigation, it seems that the promises used with VoxClient are never resolved when app is in background. First step is to connect() to client, but when my app is in background (and started programmatically), the promises is never resolved unless I manually open my app.

Maybe it is not a problem directly related to VoxImplant, but if you have some info for me, I'll take it !! :)

Thanks for all Florient

YuliaGrigorieva commented 5 years ago

Hello @Linoa65 ,

Could you please provide the information what react-native module you use to handle push notifications on android? (react-native-firebase or another)

Best regards, Yulia Grigorieva

Linoa65 commented 5 years ago

I use react-native-firebase to handle push notifications. When incoming push comes from VI, the app starts, but the promise of connection to VoxImplant is never resolve.

To handle my notification with firebase I use HeadlessJS, with this line :

AppRegistry.registerHeadlessTask("RNFirebaseBackgroundMessage", () => BackgroundTaskService);

"react-native": "0.59.8" "react-native-firebase": "5.3.1" "react-native-voximplant": "1.9.0"

YuliaGrigorieva commented 5 years ago

Hello @Linoa65 ,

I have checked your scenario with the demo app, and I'm not able to reproduce the issue on it. The demo app establish the connection to the Voximplant Cloud and performs login in the background. The local notification about incoming call is shown only when IncomingCall event is received.

Could you please provide your BackgroundTaskService implementation? Do you start the connection and login process in it?

Some references from the demo app:

  1. BackgroundTaskService implementation is the demo app: https://github.com/voximplant/react-native-demo/blob/b218fc85cf99f5d4b5a169a7373e1127723f1487/src/manager/PushBackground.android.js#L11
  2. LoginManager.pushNotificationReceived implementation: https://github.com/voximplant/react-native-demo/blob/b218fc85cf99f5d4b5a169a7373e1127723f1487/src/manager/LoginManager.js#L140

Best regards, Yulia Grigorieva

Linoa65 commented 5 years ago

In my BackgroundTaskService, I'm just sending my notification to my notification service (which display notification and handle call for VI call data-message). If my message is sent by VoxImplant, I'm starting the app with a custom android method which start my Activity.

YuliaGrigorieva commented 5 years ago

I suppose that the reason why the Client.connect promise is not resolved is that the API was not called in Headless JS task.

Linoa65 commented 5 years ago

So, I need to get logged in my background task ? Because I need to first connect to firebase before connect to VI.

Linoa65 commented 5 years ago

In the logic of my app, at starting, I'm login in to Firebase, then with user id, I login in VI. When I receive message on app closed, it runs the background task, which catch and handle my notification. The problem is that the app is running in background task and I need to display my call, so I start the Activity programatically. When the activity starts, my notification to catch is correctly handled, the app runs, and the login code is in App.js (not in background task). What is the best way to handle the call on app closed ? Because if I login in background task, after that I'll need to run my app, and it will take some time, and I want too to hide it to user and open my app only when app is totally logged and call handled.

Linoa65 commented 5 years ago

After many researches, it seems that React Native "pause" tasks when app goes background. There is a way to force execution even app goes background ?

YuliaGrigorieva commented 5 years ago

Hello @Linoa65,

React Native should not pause tasks unless you resolve the promise.

https://facebook.github.io/react-native/docs/headless-js-android

You can do anything in your task such as network requests, timers and so on, as long as it doesn't touch UI. Once your task completes (i.e. the promise is resolved), React Native will go into "paused" mode (unless there are other tasks running, or there is a foreground app).

Do I understand correctly that you do not use notifications, but bring the app to the foreground to notify the user about an incoming call?

Best regards, Yulia Grigorieva

Linoa65 commented 5 years ago

Yes, on Android I'm doing that, I'm bringing app to foreground, but I need to do that only when I'm fully connected, and my call to connection system is done on App.js, which begin its execution when my app started, but blocked at VI connection

YuliaGrigorieva commented 5 years ago

Hello @Linoa65 ,

Could you please give a sample project, so I can reproduce the issue and debug it?

Best regards, Yulia Grigorieva