News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Subscriptions do not renew
Tags: sdk, subscription
Sep 9, 2022 at 2:48pm   •   6 replies  •  0 likes
Call Sights

I'm using the 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.

6 Answers
answered on Oct 26, 2022 at 2:36pm  

@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.

answered on Oct 24, 2022 at 11:16am  

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?

on Oct 24, 2022 at 11:28am   •  0 likes

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

answered on Oct 24, 2022 at 10:43am  

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)?


on Oct 24, 2022 at 10:58am   •  0 likes

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.

answered on Sep 13, 2022 at 10:03am  

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();" ?

answered on Sep 9, 2022 at 5:41pm  

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.

answered on Sep 10, 2022 at 2:42pm  

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?


A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

Developer Platform
Integrated Apps
App Gallery
Developer support
Games and rewards

Resource center
Product Releases
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us