ConnectyCube / connectycube-reactnative-samples

Chat and Video Chat code samples for React Native, ConnectyCube
https://connectycube.com
Apache License 2.0
125 stars 111 forks source link

Calls and chats not working after 5 minutes of inactivity #64

Closed davidrenji closed 4 years ago

davidrenji commented 4 years ago

Hi all, we are building a videocall/chat app in RN 0.61.5 using connectycube-reactnative 1.8.1. But we have the issue that after around 5 minutes of inactivity, the app doesn't received chats or calls anymore, and there's no error message. We thought it was an issue with our app, so we downloaded the samples in this repo, and run the call sample with our credentials in the same devices we have our app installed, and the same issue happens, it works fine when you open the app, but after 5 minutes it doesn't receive calls anymore, so we're not sure what the issue is, maybe there's some setup that we need to do in our account and not the app? or maybe a initial setup in the app is missing? We've tried a lot of things but still nothing. Can someone help us please?

masmerino13 commented 4 years ago

Same here, I have tested the the samples that they have here and this doesn't works after some minutes, it's weird.

DaveLomber commented 4 years ago

@davidrenji @masmerino13 thank you guys for reporting the issue

I'm afraid it can be something related to chat connection keep alive settings

Anyway we need to check it on our end @banshiAnton @ccvlad and then get back you you asap

davidrenji commented 4 years ago

Thank you very much @DaveLomber, we really appreciate your help. Please keep us posted. Thanks.

ccvlad commented 4 years ago

Hi, I have signed up on ConnectCube and created app on dashboard. Now, I am running RNChat Repo with my auth_key. While trying to signup on app I am getting the following error from API. [Response][8] {"errors": ["Unexpected signature"]} LOG error {"code": 422, "info": {"errors": ["Unexpected signature"]}} LOG [Request][9] POST https://api.connectycube.com/session.json {"data": {"application_id": ####, "auth_key": "########", "nonce": 2592, "signature": "c27243c9e131d531286221570e2c4719a5cbff9d", "timestamp": 1587898158, "user": {"login": "Vendor1", "password": "12341234"}}, "type": "POST", "url": "https://api.connectycube.com/session.json"}

Please let me know what is missing...thanks

Your issue doesn't related to this theme. Please, create separate issue.

ccvlad commented 4 years ago

Hi all, we are building a videocall/chat app in RN 0.61.5 using connectycube-reactnative 1.8.1. But we have the issue that after around 5 minutes of inactivity, the app doesn't received chats or calls anymore, and there's no error message. We thought it was an issue with our app, so we downloaded the samples in this repo, and run the call sample with our credentials in the same devices we have our app installed, and the same issue happens, it works fine when you open the app, but after 5 minutes it doesn't receive calls anymore, so we're not sure what the issue is, maybe there's some setup that we need to do in our account and not the app? or maybe a initial setup in the app is missing? We've tried a lot of things but still nothing. Can someone help us please?

Hi there!

We should know few things to reproduce. Does the issue present in foreground or background application state? Android or iOS? Simulator/emulator or device?

davidrenji commented 4 years ago

Hi @ccvlad , It happens when the app is in foreground (we haven't tried it in background because we think it would happen the same). Also we've tried it on android (version 9) and ios (iPhone 11) simulators, and with android (sansumg galaxy s7 with android 8.0.0) and ios (iPhone 6s with 13.3.1) real devices. If you need something else, please let me know

masmerino13 commented 4 years ago

I was curious also and I have generated the APK of the RNVideo app and had installed it on my S8+ Android 9, seems there are no listeners working after some minutes (around 5 minutes in my case) after that I have to restart the app to have this working again

ccvlad commented 4 years ago

@davidrenji @masmerino13 thanks for details. Chat connection must to be stable. We will check and let you know

renepls commented 4 years ago

I got same issue, @ccvlad any update on this?

DaveLomber commented 4 years ago

@renepls @davidrenji @masmerino13

ok so the repro steps are:

1) run an app 2) then wait 5 mins, app still in foreground 3) now try to call from other phone

Result: no incoming call events

Correct?

@ccvlad @banshiAnton the steps are clear we should be able to reproduce

davidrenji commented 4 years ago

@DaveLomber that's correct. As far as I remember this was not an issue before.

DaveLomber commented 4 years ago

@davidrenji by before you mean which sdk version?

davidrenji commented 4 years ago

@DaveLomber, sorry by before I meant like it was working fine a few weeks ago, but we haven't change the version we are using.

davidrenji commented 4 years ago

hey guys, did you find anything?

masmerino13 commented 4 years ago

Hello guys,

We have a social network www.jwperfectmatch.com that already use your Javascript SDK and now we have ready the mobile app, could you guys help us with that, since we needs to publish the app and this issue is critical for us.

Thank you.

cc: @DaveLomber @ccvlad

masmerino13 commented 4 years ago

Do you guys, have any update about that? We are doing some work around trying to handle the issue.

ccvlad commented 4 years ago

Hi there!

We have tested and did not find the issue. Could you try the latest react-native-connectycube? The latest version uses promises instead of callbacks in API calls.

If you would see the same problem, try to set timer and send a message to your user after each minute to keep chat online.

Let us know about updates.

davidrenji commented 4 years ago

@ccvlad as I mentioned before, the issue is not just our app, we downloaded your test app, added our account credentials and we see the same issue. So if you tested it and it looks good on your end, tha means our account has an issue. is it possible for you to test with our account?

Thanks.

ccvlad commented 4 years ago

It doesn't have a sens to test with your account. I've tested also our RNVideoChat sample on Samsung S8 (9.0) with the web videochat sample. I logged in on the device - chat connection was staying in foreground about 7 mins and then I was able to receive call from the web client. Then I've tested 10-12 mins in foreground and 1h in background and always was being able to receive incoming calls.

Did you check this RNVideoChat sample? Is the issue present for you there? Do we check the same sample?

Could you provide steps to reproduce? I could miss something.

DaveLomber commented 4 years ago

@davidrenji @masmerino13 could you please try one thing, this will help use identify the issue

What I want to check is whether it relates to socket disconnect if no data is sent/received, so this message will just keep a socket as active.

If it will help - we will add a more handy API for this

davidrenji commented 4 years ago

thank guys. @ccvlad We are testing the RNVideoChat sample on 2 different phone, on a Samsung S7 with android 8.0.0 and an iPhone 6s with ios 13.3.1 We are testing from one phone to the other and we still have the issue. In the sample app, we just login with one user in a phone, and we login with a different user on the other phone. If we do a test call after that, it works just fine. Then if we hangout and left the phones there for 5 minutes, and then we try to make a call again, the call doesn't go through. We don't get any error, we just see that one phone is like dialing, but the other phone remains the same, it doesn't receive the call. We have tested this with other phones just to be sure that is not a problem with the ones we have, and still the same. We are really frustrated because this is the only part we are missing that is preventing us to go live. If you want I can record the issue and upload a video if you would like to see it.

@DaveLomber Because we are almost going live with this app for our client, we have done a lot of workaround trying to solve the issue, like a timer every 5 minutes that will close session and reconnect again. But we get tons of weird issues after doing that. Sometimes we get the calls, sometimes we don't, some times we cannot chat, sometimes we cannot send push notifications, so it's kind of crazy. But I don't understand the suggestion you made us about "send a system message to 'current' user", maybe you can give us more details, please?

DaveLomber commented 4 years ago

@davidrenji please find a code snippet:

setTimeout(() => {
   const userId = userCredentials.userId; // same 'userId' you use for connect  https://developers.connectycube.com/js/messaging?id=connect-to-chat
   const msg = {ping: 1}
   ConnectyCube.chat.sendSystemMessage(userId, msg);
}, 1000*60);

...

ConnectyCube.chat.onSystemMessageListener = function(msg) {
   if (msg.ping) {
       console.log("this is a self ping, ignore it");
       return; 
   }
};

https://developers.connectycube.com/js/messaging?id=system-messages

So it will just send a system message each 1 min to self user, hence will keep a connection alive

Please try this workaround at your end and let us know

davidrenji commented 4 years ago

Thank you @DaveLomber we tried that and it looks like it fix the issue. Now, the problem we have right is when the app is in background. It still loses the connection after 5min and because it's in background, the interval timer that is sending the system message doesn't run, so the connection is not kept alive. Any idea to solve this? Thanks

davidrenji commented 4 years ago

We've added the AppChange event to know if 5 minutes have already passed when user opens the app again after going to background. But now, the question is how to "reconnect" so the chat and the calls can starting working again? Any help would be appreciated.

Thanks.

DaveLomber commented 4 years ago

@davidrenji great it works! then please just use this solution as a workaround We will provide a better solution for this issue later, something around XMPP ping https://xmpp.org/extensions/xep-0199.html or similar.

DaveLomber commented 4 years ago

Re background - this is a normal situation. Do not need to do anything with it.

To receive calling in BG you need to send push notifications along with starting a call request , so end user will be receiving push if in background and will be able to answer. If a user is in Foreground - then just ignore a push.

Please find a guide re how to integrate pushes in RN https://developers.connectycube.com/reactnative/push-notifications

davidrenji commented 4 years ago

thanks @DaveLomber, but that's exactly what we are doing right now. We start the call process from the caller side and send a push. Then the receiver gets the push, clicks the notification and the apps opens and gets the call. But if 5 min have passed after app has gone to background (from the receiver side), and then receiver user taps the call push, but when the app opens, the ConnectyCube.videochat.onCallListener doesn't trigger, hence the receiver doesn't get the call. That's why I was asking if there's a way to "reconnect". That way if the receiver gets the call but the onCallListener doesn't get trigger, we can try to do a "reconnect" or something similar in order to trigger the onCallListener. Does that make sense?

Thanks again for your help.

DaveLomber commented 4 years ago

A better way can be is not to wait for 'onCallListener ' here, but just to get all the needed info from a push payload and join into a call.

Or, regarding re-connect - you can connect to chat again when switch to foreground if it's disconnected and then receive a 'onCallListener'

davidrenji commented 4 years ago

Thanks @DaveLomber. When you said "join into a call", how can we do that? because I cannot find that in the documentation, the only way I see if using the onCallListener

DaveLomber commented 4 years ago

@davidrenji ok you are right.. I just explained it in a bit wrong way

so correct - we need to connect to chat again on switching to foreground if a user is disconnected

Are you seeing any difficulties with it?

davidrenji commented 4 years ago

We can try that. I guess this is what you are referring to (connect to chat) right?

Thanks.

DaveLomber commented 4 years ago

Correct

this one is used to connect to chat https://developers.connectycube.com/js/messaging?id=connect-to-chat

In a case of chat disconnection - you will get a onDisconnectedListener so you actually can track where you need to connect again

https://developers.connectycube.com/js/messaging?id=disconnect

davidrenji commented 4 years ago

@DaveLomber thanks. After some testing it worked doing the a chat re-connection. But now we have another issue (any help would be much appreciated it) when getting a call in background on Android. What we are doing is we send push notifications so the receiver knows he is getting a call and it works fine most of the time, but sometimes, when the user taps the push he gets when he is using another app, then the push opens our app but we see that our app reloads (we think the OS, for some reason kills the app when it's in background). And when this reload happens, then the app loads as it should be, but the onCallListener is never trigger, hence the user doesn't get the call.

And as I mentioned, it happens only when the app is like killed by the OS, because sometimes when tapping the push, it opens the app and if it doesn't reload, then the onCallListener works fine.

DaveLomber commented 4 years ago

@davidrenji Technically it should not be any diffs whether an app is in killed state or not

Pleas make sure that you really have chat connect implemented at app start app.

If nothing helps and an issue still persist - please provided SDK logs after you opened an app by push from a killed state, we will see what's happening with chat connection

DaveLomber commented 4 years ago

Just for a future ref https://developers.connectycube.com/js/videocalling?id=receive-a-call-in-background Will be advancing the section

davidrenji commented 4 years ago

@DaveLomber thank you very much. We were able to fix the issue. We really appreciate your help.

whenmoon commented 4 years ago

A better way can be is not to wait for 'onCallListener ' here, but just to get all the needed info from a push payload and join into a call.

Or, regarding re-connect - you can connect to chat again when switch to foreground if it's disconnected and then receive a 'onCallListener'

Hi @DaveLomber my comment isn't particularly related to this issue but I would like to know how to implement what you mention here.

Are you suggesting that the session object be passed with the notification payload and the call can be accepted or rejected using session.accept({}) using the object in the payload? I have tried doing this but it seems I can't create a notification which includes a property that is not a primitive data type which I think is normal:

  const payload = JSON.stringify({
    message: profileFullName + '-' + callLength,
    notificationID: Number(usersCcId),
  });

  const pushParameters = {
    notification_type: 'push',
    user: { ids: [calleeId] }, // recipients.
    environment: 'production', // environment, can be 'production'.
    message: ConnectyCube.pushnotifications.base64Encode(payload)
  };

If this is possible would the user have to be authenticated with ConnectyCube before calling session.accept({}) and so on?

DaveLomber commented 4 years ago

@whenmoon you are right, I was writing it before I got it can't work like this

The only possible way is:

User1:

  1. initiates a call
  2. also send s a push to all participants about the call request

User2 (in background):

  1. receives a push about an incoming call
  2. accept it by clicking on a push
  3. an app will start,
  4. login user, connect to chat - all is automatic
  5. receive an incoming call request session via 'onCallListener'
  6. accept it via session.accept({})
DaveLomber commented 4 years ago

As for a better solution - we released 3.1.0 for both JS and RN sdks with a new feature to ping server, please have a look

ConnectyCube.chat.ping().then(() => {

}).catch(error => {

});

https://github.com/ConnectyCube/connectycube-js-sdk-releases/releases/tag/3.1.0