jefflinwood / twilio_client_phonegap

Phonegap plugins for the Twilio Client iOS and Android SDKs
MIT License
59 stars 53 forks source link

Works Fine For 7 Consecutive Calls But Doesn't Work on 8th Call #90

Open lokesh75way opened 5 years ago

lokesh75way commented 5 years ago

Hi Jeff,

Firstly, I'd like to thank you to write such a great plugin as this is working great with my app. But I see a very strange issue which I couldn't fix so far and spent almost 2 weeks on it and I am still struggling with it.

In my Ionic 3 app, my device is connecting with Twilio perfectly fine for first 6-7 consecutive calls and returns status "READY", but on 7th or 8th call it doesn't make connection and returns status "OFFLINE" every time I try to re-connect until I kill the app and restart the app. Upon restart the app, it again works fine for next 6-7 consecutive calls. The cycle goes on...

Would you mind to help a little bit of mine in this matter as why this is happening or if I am missing anything? Your immediate response over this would be really appreciated.

Below is the error I see in my console:

================================================================= com.acsnowcap.acsnowcap E/Device: Unable to register for incoming calls com.twilio.client.impl.session.SessionException: pjsua_acc_add(): Too many objects of the specified type (PJ_ETOOMANY) at com.twilio.client.impl.useragent.UserAgent.addAccount(Native Method) at com.twilio.client.impl.CallControlManager.addUserAccount(CallControlManager.java:347) at com.twilio.client.impl.DeviceImpl.setCapabilityToken(DeviceImpl.java:249) at com.twilio.client.impl.DeviceImpl.(DeviceImpl.java:89) at com.twilio.client.impl.TwilioImpl.createDevice(TwilioImpl.java:264) at com.twilio.client.Twilio.createDevice(Twilio.java:84) at com.phonegap.plugins.twilioclient.TCPlugin.deviceSetup(TCPlugin.java:197) at com.phonegap.plugins.twilioclient.TCPlugin.execute(TCPlugin.java:106) at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98) at org.apache.cordova.PluginManager.exec(PluginManager.java:132) at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59) at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41) at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method) at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:9) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:157) at android.os.HandlerThread.run(HandlerThread.java:61)

jefflinwood commented 5 years ago

Hi,

I haven't seen this one before - it does look like you are hitting some kind of limit with the number of Twilio connections open in one app.

Is it possible that you are aren't closing the Twilio connections after hanging up (or they aren't really hung up?)

Thanks!

lokesh75way commented 5 years ago

Hi Jefflin,

Thanks for your prompt response.

Actually its not a problem with the number of Twilio connections because when I serve my app in browser then I am able to make even 20 consecutive calls. But I need to use a different piece of code to run in browser and different piece of code to run in mobile device to support my plugin.

After a lot of more debugging, I reached to a point where I fount below function (line of code) is not working after 7 calls:

TwilioPlugin.Device.prototype.setup = function(token) {}

In twilio_client_phonegap/www/tcPlugin.js

This function throws that error in the console. However, if I just kill/close the app at same time and re starts it immediately, then it again work fine for next 7 consecutive calls.

Seems like this SETUP function stops working after 7 consecutive calls and returns "OFFLINE" status until I close the app and restart it.

Is it possible for you somehow to get me into the right direction or help me how to fix that as I am really struggling with it.

Many Thanks in Advance!

lokesh75way commented 5 years ago

I think we can get this fix if I can somehow DESTROY the Twilio Setup because seems like that's what exactly causing the issue. I didn't find any method in the library through which I can destroy the previous Twilio Setup.

Can you just help me in this regard to find which method I can use to destroy the Twilio Setup? Or how can I do that? because closing app also destroy the previous twilio setup that's why it works upon restart of app.

Any thoughts?

Thanks in Advance!!!

jefflinwood commented 5 years ago

Hi,

The web browser implementation isn't the same as the Cordova implementation, unfortunately - the Cordova plugin uses the Twilio Client for iOS or Twilio Client for Android libraries. On Android, it looks like calling setup will replace the Twilio Device (Android class) every time it gets called with a token (whether it is new or not). If you call setup with an empty string, that will release the device and then go offline - is there a chance that your token method is returning an empty string sometimes?

lokesh75way commented 5 years ago

Firstly, I'd like to thank you so much for your last recent response on this. I finally got it working for Android device. By calling the setup with empty string, it released the device and I am now finally able to make successful device setup every time. MANY THANKS FOR YOUR HELP ON THIS.

Now, this problem still persists in iOS device. I checked the Twilio Client for iOS file and saw that there is no method to DESTROY/RELEASE the Device.

Would you mind to please help me a little more regarding iOS devices that how can I release the device in iOS?

Many Thanks in Advance Jeffrin!!!

lokesh75way commented 5 years ago

Hey Jefflin,

Sorry to bother you again on this, but I think I just need a method to somehow DESTROY/RELEASE the Twilio setup in my iOS device.

Would you mind to please guide me on this last issue by taking 2 minutes out of your precious time as because of this I have really been stuck and can't release my app.

Please Please...!!! Many Thanks in Advance!!!

jefflinwood commented 5 years ago

Hi, I totally understand this is blocking you - let me take a look into this - it's a little different on iOS.

lokesh75way commented 5 years ago

Hi Jefflin,

Yes actually it is different on iOS because I have already tried to customize the plugin by adding "Twilio.destroy" method in it using several ways, but I am still not able to fix it.

I know its quite hectic for you but please do update me as soon as you look in to it and found any solution to get it work on iOS.

I'll be highly grateful to you for this kindness!!!

Thanks

ansongoldade commented 5 years ago

Hello Jeff,

I am working with Lokesh on a project that is using this plugin. I have a proposed fix to the issue that I've verified on both platforms. I was going to create a branch and submit a pull request but I do not have access to do that. Would you like to see the proposed changes? If yes, what form would you like them in? PR or git format-patch?

I'll keep running with my local changes but it would be nice to get these committed to the repository, if you agree to them, so we don't have to manage local source code changes in the plugin.

Longer term (next few months) we'll move to the upgraded Twilio Voice API tokens and use the other plugin at https://github.com/jefflinwood/twilio-voice-phonegap-plugin. In the near term these fixes seem to resolve our issue and get us closer to shipping product.

Look forward to your thoughts. Anson