Avaya Client SDK

< Back to Package Overview

Using Presence with Shared Contacts

Using the Avaya Client SDK, you can easily get presence of shared contacts. To display presence of contact from your device, you must complete the following activities.

Subscribe for contact's presence

To subscribe for contact's presence, use functions exposed by Contact class. First, add Contact.onPresenceChangedCallback() to Contact.

var onPresenceChanged = function (contact, presence) {
    console.log('Overall presence state of ' + contact.getDisplayName() + ' is ' + presence.getOverallState());
};
contact.addOnPresenceChangedCallback(onPresenceChanged);

Start presence service for contact

After that, call Contact.startPresence(). You will receive instant notification with current presence information of the contact and will be receiving further updates.

contact.startPresence().then(
        function () {
            console.log('Successfully subscribed for presence updates of ', contact.getDisplayName());
        },
        /**
         * @param {AvayaClientServices.Services.Presence.PresenceError} error
         */
        function (error) {
            console.error('Failed to subscribe for presence updates', error);
        }
);

Get contact's presence

Once we subscribed for contact's presence the updates will be reflected automatically. See Subscribe for contact's presence for more details. If you need to get contact's presence immediately, call Contact.getPresence() after presence service is started.

/**
*
* @param {AvayaClientServices.Services.Presence.Presence} presence
*/
var presence = contact.getPresence();

Stop presence service for contact and unsubscribe from updates

Do not forget to unsubscribe from contact's presence when you no longer want to receive the presence updates. First, remove Contact.onPresenceChangedCallback() from Contact. After that, call Contact.stopPresence() to stop presence service for contact.

contact.removeOnPresenceChangedCallback(onPresenceChanged);
contact.stopPresence()