question

Muhammad Shoaib avatar image
Muhammad Shoaib asked Phong Vu commented

Subscription renewal Explain

I'm bit confused about subscription renewal, I've successfully followed the tutorial for presence events and I now get notified, but after I went through this tutorial https://ringcentral-tutorials.github.io/subscription-basics-nodejs-demo/ I'm confused about subscription renewals do they get handled internally or do we need to use an API after every x interval to renew the subscription to make sure we keep getting the notifications?

rest api
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 Phong Vu edited

That tutorial does not discuss about renew a subscription. The reason I added 2 additional functions to check existing subscription and remove the subscription was explained in the tutorial (don't want to have many pending subscriptions while rerun app too often to test).

Basically, the SDK support PubNub notification and it expires after 15 minutes. That's why the SDK was implemented to refresh the notification more frequently.

You said "disconnection from RingCentral server", do you mean the app/user logout or terminate the app? Anyway, you can call the platform.logout() to log out deliberately.

If you want to check if your app is still logged in (meaning the access token is still valid) you can call platform.loggedIn() which returns true or false accordingly. If it returns false, then call platform.login() to login again. If it is true, you are good to call any APIs.

If you app suppose to run for weeks or months continuously, I recommend to use Webhooks notifications instead of PubNub notification. Check this quick start to learn more about RingCentral Webhooks.

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

First of all, the SDK renews the subscription automatically as long as the access token is still valid. You should implement the callback functions to decide what to do:

// Register Platform Event Listeners
platform.on(platform.events.refreshSuccess, handleRefreshSuccess);
platform.on(platform.events.refreshError, handleRefreshError);
// Register Subscription Event Listeners
subscription.on(subscription.events.renewSuccess, handleSubscriptionRenewSuccess);
subscription.on(subscription.events.renewError, handleSubscriptionRenewError);

What is the tutorial for presence do you refer to?

1 |3000

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

Muhammad Shoaib avatar image
Muhammad Shoaib answered Muhammad Shoaib edited

@Phong Vu sorry for omitting the info, this is the presence tutorial I was referring to https://ringcentral-tutorials.github.io/callrecording-notification-node/?distinctId=16e69c9b43c9e-0f45863320bf05-1d3d6b55-13c680-16e69c9b43dc9b, also I couldn't find anything related to handling the disconnection from ringcentral server, more precisely how can we handle the disconnect if we are disconnected from this

var platform = rcsdk.platform();
        platform.login({
            username:un,
            password:pwd
        }).then()

what I am looking for is to reconnect after we get disconnected and then do we need to re-do the subscription process?

1 |3000

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

Muhammad Shoaib avatar image
Muhammad Shoaib answered Phong Vu commented

@Phong Vu by disconnection I meant if the app logouts for some reason (internet connectivity issue). but I guess we can just check using the loggedin() and call login() if true. Also can you kindly shed some light on as to why webhooks are preferred over pubnub for app that's meant to run for weeks or months continuously.

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 ·

Read this doc at the section "When should I use a Webhook vs PubNub".

Also, Webhook subscription expiration time is much longer (7 days) so you need to renew just once in a while.

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