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.

Subscribe for contact's presence

To subscribe for contact's presence, use functions exposed by Contact class. First, add handler for PresenceChanged event to the Contact object.

void OnContactPresenceChanged(object sender,
                              ContactPresenceChangedEventArgs e)
{
    Contact contact = e.ContactInfo;
    Presence presence = e.PresenceInfo;
    PrintInfo(string.Format("Presnece changed for {0} {1}",
        contact.FirstName.Value, contact.LastName.Value));
    PrintInfo("OverallState: " + presence.OverallState);
    PrintInfo("note: " + presence.Note);
}

...

contact.PresenceChanged += OnContactPresenceChanged;

Start presence service

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

Contact.ContactPresenceCompletionHandler completionHandler = (error) =>
{
    if (error == null)
    {
        PrintInfo("Successfully subscribed for presence updates.");
    }
    else
    {
        PrintError(string.Format("Failed to subscribe for presence updates:{0}",
            error.Error));
    }
};

contact.StartPresence(AccessControlBehavior.None, completionHandler);

Get contact's presence

Once we subscribed for contact's presence the updates will be reflected automatically. If you need to get contact's presence immediately, use Contact.Presence.OverallState property after presence service is started.

PresenceState presenceState = contact.Presence.OverallState

Stop presence service 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 handler for PresenceChanged event from the Contact object. After that, call Contact.StopPresence() to stop presence service.

contact.PresenceChanged -= OnContactPresenceChanged;
ContactPresenceCompletionHandler completionHandler = (error) =>
{
    if (error == null)
    {
        PrintInfo("Successfully unsubscribed for presence updates.");
    }
    else
    {
        PrintError(
            String.Format("Failed to unsubscribe for presence updates:{0}",
            arg.Error));
    }
};
contact.StopPresence(completionHandler)