Bridge Communications

Saturday, July 4, 2015

Basic Call Control Using the Lync Client SDK II

Last week I started this series on using the Lync client SDK to control your Lync or Skype For Business client.  The first simple example I showed was how to answer a ringing audio video call.  Today in part two we'll look at some things to you can once you have answered that, specifically how to put it on hold and how to take it off hold.

Putting an audio call on hold

private void HoldCall(Conversation c)
        {
            if (c == null)
                return;

            try
            {
                if (c.Modalities[ModalityTypes.AudioVideo].CanInvoke(ModalityAction.Hold))
                {

                    c.Modalities[ModalityTypes.AudioVideo].BeginHold(myar =>
                    {

                        try
                        {

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

                        }
                        catch { }


                    }, null);

                }
            }
            catch (Exception ex)
            {
                Console.Writeline(ex.Message);
            }
        }

For hold I use a procedure like the one above.  The only thing I need to know to start is the conversation that we wish to put on hold, so I pass that as a parameter.  From there you can see I check to see if the conversation is not null before proceeding.  The finally check is to make sure that the Modality Action hold can be applied to the call, because sometimes it cannot, ie if it is already on hold, or not answered yet.

A veteran programmer once told me when I was starting out, that writing a program to do something is easy, but writing a program that react to everything that could possibly be happening at the same time is hard, and the measure of a good programmer.

Retrieve a held call

        private void ResumeCall(Conversation c)
        {
            if (c == null)
                return;

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

                        try
                        {

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

                        }
                        catch { }


                    }, null);
                }
            }
            catch (Exception ex)
            {
                  Console.Writeline(ex.Message);
            }
        }

To resume a call I do exactly the same thing as to hold, but instead of checking for the hold modality I check for the retrieve, and instead of calling BeginHold I call BeginRetrieve.  Again, it's important to note you should always check to see if you can perform the action before you try, unless you like causing and handling exceptions.

This will wrap up this week's blog, stay tuned for part III next week as we continue to explore more advanced call control features.  And happy 4th of July!

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.