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