skype-for-businesslync-client-sdk

Subscribing to Presence Changes in Skype for Buisness Client


I want to subscribe to my own presence changes in my Skype for Buisness Client and tried the ContactInformationChanged event from the Lync Client SDK. The documentation on subscribing to presence (doc) writes that their is also a need to create a Subscription, fill it with the ContactInformationTypes i want to subscribe to, add the contact i want to subscribe to and call Subscribe() on the subscription object. Now unless i misunderstood the documentation you still habe to subscribe to the ContactInformationChanged event if you do that. The thing is even if i leave out the subscription creation part and just subscribe to the ContactInformationChanged event it makes no difference. For example if i do this:

        var selfContact = m_lyncClient.Self.Contact;
        selfContact.ContactInformationChanged += Contact_ContactInformationChanged;

        m_subscription = m_lyncClient.ContactManager.CreateSubscription();
        m_subscription.AddContact(selfContact);
        List<ContactInformationType> contactInformationList = new List<ContactInformationType>
        {
            ContactInformationType.Activity,
            ContactInformationType.Availability,
            ContactInformationType.ActivityId,
            ContactInformationType.CustomActivity,
        };
        m_subscription.Subscribe(ContactSubscriptionRefreshRate.High, contactInformationList);

I get event messages for ContactInformationChanged with a ContactInformationTypethat i didn't specify.

My Questions:


Solution

  • Is the Subscription creation part even necessary?

    For your own contact, no you don't need to create a subscription.

    Is there a way to just get Presence Notifications of specific ContactInformationType's changing (like Availabilty for example)?

    No. You just need to filter out all other callbacks like so:

    private void Contact_ContactInformationChanged(object sender, ContactInformationChangedEventArgs e)
    {
        if (e.ChangedContactInformation.Contains(ContactInformationType.Availability) ||
            e.ChangedContactInformation.Contains(ContactInformationType.ActivityId) ||
            e.ChangedContactInformation.Contains(ContactInformationType.CustomActivity))
        {
            OnLyncPresenceChanged();
        }
    }