Export (0) Print
Expand All

How to: Handle delegated Lync audio calls

Learn how to programmatically handle a delegated Microsoft Lync 2013 audio call by using Microsoft Lync 2013 SDK.

The prerequisites for handling delegated calls are as follows:

  • Microsoft Lync 2013 must be installed and running on the development computer.

  • You must have sign-in credentials for Microsoft Lync Server 2013.

  • Microsoft Lync 2013 SDK must be installed on the development computer.

Core concepts to know

Topic

Description

Call delegation in Lync

Describes call delegation as implemented by Lync 2013.

Conversation manager

Describes the role of the conversation manager in starting and accepting calls.

A Microsoft.Lync.Model.DelegatorClient representing a call delegator is added to the LyncClient.DelegatorClients collection whenever a user delegates the local user to take incoming audio calls. To catch that event, you register for LyncClient.DelegatorClientAdded. When the call delegator removes the local user from the call delegate list, the LyncClient.DelegatorClientRemoved event is raised.

To register for delegator events in a form load event handler

  1. Get the Microsoft.Lync.Model.LyncClient and ensure the State is ConversationState.SignedIn.

    For information about signing in to Microsoft Lync 2013, see How to: Sign a user in to Lync.

  2. Register for LyncClient.DelegatorClientAdded and LyncClient.DelegatorClientRemoved on Microsoft.Lync.Model.LyncClient.

  3. Iterate on the collection of Microsoft.Lync.Model.DelegatorClient instances in the DelegatorClients property:

    1. Register for the ConversationManager.ConversationAdded event on the ConversationManager property of the Microsoft.Lync.Model.DelegatorClient.

    2. Register for the ConversationManager.ConversationRemoved event on the ConversationManager property of the Microsoft.Lync.Model.DelegatorClient.

You register for delegate conversation events for each DelegatorClient instance in the DelegatorClients collection after you have obtained a LyncClient instance in your form Load event. In addition, you register and unregister for conversation events in the delegator event handlers.

To handle the delegator added and the delegator removed

  1. Create a method to handle the LyncClient.DelegatorClientAdded event.

    The method signature is System.EventHandler<DelegatorClientCollectionEventArgs>.

  2. Create a method to handle the LyncClient.DelegatorClientRemoved event.

    The method signature is System.EventHandler<DelegatorClientCollectionEventArgs>.

  3. In the DelegatorClientAdded event, register for the ConversationAdded and ConversationRemoved events on the Client.ConversationManager property of the DelegatorClient.

  4. In the DelegatorClientRemoved event, unregister for the ConversationAdded and ConversationRemoved events on the Client.ConversationManager property of the DelegatorClient.

To give the local user the delegator name on an incoming delegated call, add code from the following procedure to your ConversationAdded event handler. For more information about handing incoming calls, see How to: Join a Lync conversation.

To get call a delegator’s name

  • For each DelegatorClient instance in the LyncClient.DelegatorClients property, get a ConversationManager by reading the ConversationManager property on Microsoft.Lync.Model.DelegatorClient.

    1. Compare the delegator client’s ConversationManager to the source of the ConversationAdded event:(ConversationManager)source.

    2. If the two ConversationManager instances are identical, the added conversation is a delegated conversation.

      1. Get the Contact of the call delegator by calling into GetContactByUri and then passing the Uri of the Microsoft.Lync.Model.DelegatorClient.

      2. Call GetContactInformation, passing ContactInformationType.DisplayName to get the name of the call delegator.

      3. Break out of the foreach loop.

Register for delegator events in a forms load event handler

The following example handles the Load event in Microsoft Windows Forms. For information about signing in to Lync 2013, see How to: Sign a user in to Lync.


        ...
        private LyncClient _lyncClient;
        ...
        /// <summary>
        /// Main form loader
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainForm_Load(object sender, EventArgs e)
        {
            try
            {
                _lyncClient = LyncClient.GetClient();

                //Client sign-in code is omitted for clarity
                ...
                _LyncClient.DelegatorClientAdded += _LyncClient_DelegatorClientAdded;
                _LyncClient.DelegatorClientRemoved += _LyncClient_DelegatorClientRemoved;

                foreach (DelegatorClient _DelegatorClient in _ClientModel._LyncClient.DelegatorClients)
                {
                    _DelegatorClient.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;
                    _DelegatorClient.ConversationManager.ConversationRemoved += ConversationManager_ConversationRemoved;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Critial Exception on initiate client " + ex.Message);
            }
        }

Handle the delegator added and the delegator removed

The following example registers or unregisters for conversation events on a delegator client.

        /// <summary>
        /// Handles event that is raised when a user removes local user from a call delegate list
        /// </summary>
        /// <param name="sender">LyncClient. The local client</param>
        /// <param name="e"></param>
        void _LyncClient_DelegatorClientRemoved(object sender, DelegatorClientCollectionEventArgs e)
        {
            e.DelegatorClient.ConversationManager.ConversationAdded -= ConversationManager_ConversationAdded;
        }

        /// <summary>
        /// Handles event that is raised when a user adds local user to a call delegate list
        /// </summary>
        /// <param name="sender">LyncClient. The local client</param>
        /// <param name="e"></param>
        void _LyncClient_DelegatorClientAdded(object sender, DelegatorClientCollectionEventArgs e)
        {
            e.DelegatorClient.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;
        }

Get call delegator’s name

The following example code should be added to your ConversationAdded event handler.

    //The call is a delegated call.
    if ((ConversationManager)sender != _LyncClient.ConversationManager)
    {
        //Look for the delegator ConversationManager that raised the event.
        foreach (DelegatorClient _DelegateClient in _LyncClient.DelegatorClients)
        {
            //Did this delegator conversation manager raise the ConversationAdded event?
            if (_DelegateClient.ConversationManager == (ConversationManager)sender)
            {
                //Get the Contact representing the call delegator.
                Contact delegatorContact = _LyncClient.ContactManager.GetContactByUri(_DelegateClient.Uri);
                //Add the name of the delegator to a StringBuilder instance.
                sb.Append("Incoming call delegated by " + delegatorContact.GetContactInformation(ContactInformationType.DisplayName).ToString());

                //Add the name of the caller to the string builder instance
                string delegateCallName = e.Conversation.Participants[1].Contact.GetContactInformation(ContactInformationType.DisplayName).ToString();
                sb.Append("Caller: " + delegateCallName);

                //Break out of foreach loop, correct delegator conversation manager found.
                break;
            }
        }
    }

Community Additions

ADD
Show:
© 2014 Microsoft