question

Call Sights avatar image
Call Sights asked Call Sights edited

Subscriptions do not renew

I'm using the RingCentral.net SDK. I use basically this code to monitor for my extension's calls:
=================
string s1 = "/restapi/v1.0/account/{0}/extension/~/presence?detailedTelephonyState=true&sipData=true";

string s2 = "/restapi/v1.0/account/{0}/telephony/sessions";

// replace the IDs in the above strings (not shown)

await restClient.PubNubExtension.Subscribe(new[] {s1, s2}, Device.ParseSubscription);

=================

After an hour the token for the RestClient needs renewing, so I renew this with:

await restClient.Refresh().ConfigureAwait(false);

Is there some best practice on how to use long lasting subscriptions? I'll happily share the non-working code that I'm doing, but I'm pretty sure it's wrong so I'd like to understand how to do it properly.


sdksubscription
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image
Phong Vu answered

What you did above is to refresh the access token so that you can continue using the restClient to call RingCentral APIs.

For PubNub subscription, it expires after 15 mins, but the SDK handle the renewal for you so you don't need to explicitly renew the subscription. All you need is to refresh the access token as you did above.

1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Call Sights avatar image
Call Sights answered Call Sights commented

Thank you, @Phong Vu, for a quick response. So it sounds like it should be working already, but it is not.

In traces I see the subscription/renew happening every 13 minutes, so that's a good sign. But when the RestClient token refreshes then the subscriptions cease to work.

How can I investigate this further? Can think which direction I can go in to confirm any expectations?

1 comment
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image Phong Vu ♦♦ commented ·

Do you do something e.g. like this?

var pubNubExtension = new PubNubExtension();
await rcsdk.InstallExtension(pubNubExtension);
try
    {
        var eventFilters = new[]
                {
                    "/restapi/v1.0/account/~/extension/~"
                };
        var subscription = await pubNubExtension.Subscribe(eventFilters, message =>
        {
            // do something with message
            
        });
...

I believe that after installing the pubNubExtension instance, it will automatically use the latest access token from the rcsdk instance.

0 Likes 0 ·
Tyler Liu avatar image
Tyler Liu answered

I am the author of the RingCentral.NET SDK and I can help you on this.

By design, you just need to make sure that you always have a valid access token, then subscription will auto refresh 2 minutes before expiration.

I don't quite understand "await restClient.Refresh().ConfigureAwait(false);"

Shouldn't it be "await restClient.Refresh();" ?

1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Call Sights avatar image
Call Sights answered Tyler Liu commented

Hi @Tyler Liu. Thank you for your help with this (And @Phong Vu too).

I have the subscriptions all working now, except for one situation. Please can I ask if this works for you because I'm thinking that it might be an issue with the SDK.

1) Start a client and do the token exchange

2) Set timers to renew tokens frequently enough (ie <15 mins)

3) Set up PubNub subscriptions

4) Prove that everything works and events are received

5) Hibernate your PC for >1 hour

6) When the PC returns from hibernation then everything appears to work, except no events are received (via PubNub).

I understand that some of the problems might possibly be down to my timers and token renewal. On the timer, it detects that the token is invalid and renews it again for a new token. Then it calls .Subscribe() again and the logs show that it works ("200") but still no events.

Before I go much further with this, are events after hibernation working for you (in any scenario)?

Thanks


1 comment
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Tyler Liu avatar image Tyler Liu ♦ commented ·

I don't think subscriptions could survive a computer hibernate.

Because subscriptions expire in 15 minutes. When your computer wake up, the subscription already expired, there is not way to refresh. (the refresh should be done before the expiration.)


In that case, you may need to re-create the subscriptions.

0 Likes 0 ·
Call Sights avatar image
Call Sights answered Tyler Liu commented

Hi @Tyler Liu. Thanks. Sorry, yes I should have been clearer. We detect the outage (ie token failure) and destroy the restclient and pubnubextension and create new ones. Using the new objects we . subscribe and get a successful response but not events follow.


Your response makes me think that somehow we are not destroying the old objects sufficiently well or that it must be some other fault in terms of how we’re handling the objects.


In principle if we’re creating all new objects after the unhibernate then it really ought to work ok, right?

1 comment
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Tyler Liu avatar image Tyler Liu ♦ commented ·

It should just work if you create new objects instead. Please try again and update me.

0 Likes 0 ·
Call Sights avatar image
Call Sights answered Call Sights edited

@Tyler Liu I got to the bottom of this. When the machine comes out of hibernation, then the DNS service isn't fully working, and the RingCentral requests fail. We've seen the exceptions and thought it was game over. But it's not. When the network returns fully, then we can refresh the token and carry on. The PubNub connection still wobbles over this but ultimately it works within a refresh cycle (ie within 15 minutes).

Not sure if this helps. But I thought it could be useful to write these findings in case it helps someone else.

2 comments
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Tyler Liu avatar image Tyler Liu ♦ commented ·

If that is the case. You don't have to wait for 15 minutes. You may refresh it as soon as the DNS service is working. https://github.com/ringcentral/RingCentral.Net/blob/master/RingCentral.Net.Pubnub/PubNubExtension.cs#L119

There are only < 200 lines of code in total, so, there is not much magic.


0 Likes 0 ·
Call Sights avatar image Call Sights Tyler Liu ♦ commented ·

@Tyler Liu Thanks. Agreed. We're not yet able to spot the cause of the exception and thus realise the potential instability. The exceptions all look the same. But we're working on our options here.

And actually to be clear, we get the Token.Refresh() done straight away, pretty much. Our issue is just PubNub. The issue appears to be within the PubNub object. We don't have the source for that.

0 Likes 0 ·

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys