Cookie CSS

Sunday, June 28, 2015

Basic Call Control Using the Lync Client SDK

The Lync WPF controls are a great way to start out a developer new to the SDK.  They make it easy to see the status of a user, call the user's endpoint, and even shortcut meetings and emails.  In your applications, there may come a time you want to do a little more than what the WPF controls offer.  Microsoft exposes an object called lyncClient for just this.  Essentially it let's you remote control almost every aspect of your Lync or Skype4B client.

To use it first you add reference to some of the Lync client libraries you will be using like this.

using Microsoft.Lync.Controls;
using Microsoft.Lync.Internal;
using Microsoft.Lync.Controls.Internal;
using Microsoft.Lync.Model;
using Microsoft.Lync.Model.Conversation;
using Microsoft.Lync.Model.Conversation.AudioVideo;
using Microsoft.Lync.Model.Extensibility;

Once you have this in place you program simply needs to create an variable of the lyncClient object and bind it to the running client.

lyncClient lc = LyncClient.GetClient();

Now one thing to note, this will throw an exception if Lync/Skype4B is not running, so you may want to verify that first, or handle the error for the user.

Some basic call control

All of our call control examples this week and next are going to be performed on an object call a Conversation.  If you can remember from my previous posts, before you try to perform functions on an AudioVideo Modality it's important to see if the conversation has one.  You don't want to try to put a chat session or application sharing session on hold.

private bool ContainsAVCall(Conversation c)
{
            try
            {
                return c.Modalities.ContainsKey(ModalityTypes.AudioVideo) && c.Modalities[ModalityTypes.AudioVideo].State != ModalityState.Disconnected;
            }
            catch
            {
                return false;
            }
}

So once we know if a Conversation has an AudioVideo Modality then we can safely make some call control related requests of it.  Here is an example of how to answer a ringing audio/video call.

try
            {
                if (c.Modalities[ModalityTypes.AudioVideo].CanInvoke(ModalityAction.Connect))
                {
                    c.Modalities[ModalityTypes.AudioVideo].BeginConnect(myar =>
                    {

                        try
                        {

                            c.Modalities[ModalityTypes.AudioVideo].EndConnect(myar);

                        }
                        catch { }


                    }, null);
                }
            }
            catch{}

You'll notice before we try to call the BeginConnect we check to make sure that we can call it, because there are states of an audio call in which you can't, ie if you have already answered it, or it's on hold.

Stay tuned next week when we look at some more advanced call control functions.

Doug Routledge, C# Lync, Skype for Business, SQL, Exchange, UC Developer  BridgeOC
Twitter - @droutledge @ndbridge

No comments:

Post a Comment

Any spam comments will be deleted and your user account will be disabled.