Bridge Communications

Saturday, July 18, 2015

Basic Call Control Using the Lync Client SDK IV

In the first 3 parts of this series we showed you how to answer, hangup, hold, resume, and park a Lync/Skype4b audio call.  In this weeks post I am going to show you how to transfer an audio call.

Remember 3 weeks ago how we used the conversation object, when the same principal applies here, as we show an example of how to transfer a call.

public static void BlindTransferCall(Conversation c, Contact num, TransferOptions topt)
        {
            if (c == null)
                return;

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

                List<string> _context = new List<string>();
                Object[] asyncState = { ModalityState.Transferring, _context, c.Modalities[ModalityTypes.AudioVideo] };

                c.Modalities[ModalityTypes.AudioVideo].BeginTransfer(num, topt, myar =>
                {

                    try
                    {

                        Object[] _asyncState = (Object[])myar.AsyncState;
                        ModalityState ms = (ModalityState)_asyncState[0];
                        IList<string> _contextProperties = (List<string>)_asyncState[1];

                        c.Modalities[ModalityTypes.AudioVideo].EndTransfer(out ms, out _contextProperties, myar);

                    }
                    catch (ArgumentException)
                    {
                        Console.WriteLine("Entered Uri is not valid " + num.Uri);
                    }
                    catch (ItemNotFoundException)
                    {
                        Console.WriteLine("Entered Uri could not be resolved to a Contact " + num.Uri);
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(ex, true);
                        string er;
                        er = "BlindTransferCall: Error Trapped in " + Dlib.ProgramSource + ".\r\n";
                        er = er + trace.GetFrame(0).GetMethod().Name + "\r\n" + ex.Message.ToString();
                        er = er + "Line: " + trace.GetFrame(0).GetFileLineNumber();
                        er = er + "Column: " + trace.GetFrame(0).GetFileColumnNumber();
                        Console.WriteLine(er);
                    }


                }, asyncState);
            }
        }

The above procedure will blind transfer a call, talking 3 parameters.  You can see that we first make sure that the Conversation is in the state in which a transfer is allowed.  Once we determine that it is, we begin the async transfer with BeginTransfer on the Audio/Video Modality, then follow it up with the EndTransfer once complete.

This will conclude this weeks posts, if you have any questions or would like some examples or more complicated transfer scenarios hit me up on Twitter.

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

No comments:

Post a Comment