Cookie CSS

Friday, February 20, 2015

Building a Lync Kiosk - Part 2

Last episode we started the process of building a super simple Lync (Skype for Business) Video Kiosk.  All we are looking to do, is;
















1.  Automatically answer the incoming Audio/Video call
2.  Make the call window full screen.
3.  Turn on our video feed.

So last time we went through the process of getting connected to the existing Lync client.  Now we want to react when a new call comes in.

 _LyncClient.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;

This event will fire each time a new conversation is added.   We will use my old reliable function to make sure it's not just an IM, and actually an audio video call.

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

So let's look at the code for the new conversation event.

void ConversationManager_ConversationAdded(object sender, ConversationManagerEventArgs e)
        {
            Conversation c = e.Conversation;

           if (ContainsAVCall(e.Conversation))
           {
               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 (Exception ex)
               {
                   Console.WriteLine(ex.Message);
               }

               try
               {

                   LyncClient.GetAutomation().GetConversationWindow(e.Conversation).ShowFullScreen(0);
               }
               catch (Exception ex)
               {
                   Console.WriteLine(ex.Message);
               }

               try
               {
                   var videoChannel = ((AVModality)c.Modalities[ModalityTypes.AudioVideo]).VideoChannel;

                   if (videoChannel.CanInvoke(ChannelAction.Start))
                   {

                       System.Threading.Thread.Sleep(2000);

                       videoChannel.BeginStart(myvs =>
                       {
                           videoChannel.EndStart(myvs);
                       }, videoChannel);

                   }
               }
               catch { }
           
           
           }
        }



So in the first section, we check to see if AV exists and if so, we begin connecting to the conversation.

Once we have the connection made, we go and find the Lync window, and make it full screen.

LyncClient.GetAutomation().GetConversationWindow(e.Conversation).ShowFullScreen(0);

Now that we are actively in a conversation we'll turn on our video so they caller can see us.

var videoChannel = ((AVModality)c.Modalities[ModalityTypes.AudioVideo]).VideoChannel;

                   if (videoChannel.CanInvoke(ChannelAction.Start))
                   {

                       System.Threading.Thread.Sleep(2000);

                       videoChannel.BeginStart(myvs =>
                       {
                           videoChannel.EndStart(myvs);
                       }, videoChannel);

                   }

That's it, when the call is hung up, this all goes away and you are back to your desktop.

Thanks for taking the time to check us out, stay tuned for more to come.  If you'd like to download the source code for this project you can do so below.

Download Here

Doug Routledge, C# Lync, SQL, Exchange, UC Developer

No comments:

Post a Comment

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