Microsoft Lync and Skype for Business have a rich set of .NET APIs which make it easy to extend the platform and integrate it with other applications. This blog helps explain how to use those APIs.

Accepting transfers and forwards in UCMA 2.0 applications

Posted: July 15th, 2009 | Author: | Filed under: OCS Development, UCMA 2.0 | No Comments »
scrap
what happens if you let UCMA clean your house

The layer of abstraction that makes UCMA 2.0 such a powerful tool can also, once in a while, be dangerous. If we’re not careful enough, we can easily get the idea that the API will take care of everything for us: SIP messaging, media negotiation, presence subscriptions, house cleaning. UCMA does handle the connection to Office Communications Server without being asked (and it cooks a delicious filet mignon), but there are some things you need to remember to explicitly tell it to do.

My previous post on the UseRegistration property describes one of these. Another one that has tripped me up a couple of times is accepting transfers. If you’ve used the transfer methods in UCMA, you know how easy it is to send a transfer to a remote endpoint, with a single asynchronous method call and a handful of parameters. If the remote endpoint is Office Communicator, the new conversation window pops up and your transfer goes off without a hitch. What happens, though,if your UCMA application receives a transfer?

In other words,what happens if you call into your UCMA application from Communicator, hit the transfer button, and transfer the call to another number?

The answer is that, by default, nothing happens. The transfer fails, because UCMA 2.0 applications don’t accept transfers out of the box.

To allow your application to receive transfers for a call, you need to handle the TransferReceived event on that call:

_avCall.TransferReceived += 
    new EventHandler(_avCall_TransferReceived);

The code to accept the transfer, in the grand tradition of UCMA 2.0, consists of one method called Accept, with a parameter (signaling headers) that can almost always be null.

void _avCall_TransferReceived(object sender, 
    AudioVideoCallTransferReceivedEventArgs e)
{
    e.Accept(null);
}

Well, there you have it. With that minor alteration, your application now accepts transfers, at least on that one AudioVideoCall.

If you want to accept forwards (really only applicable for outgoing calls) you’re looking at something very similar:

_avCall.Forwarded += 
    new EventHandler(_avCall_Forwarded);

The code to accept a forward is even simpler:

void _avCall_Forwarded(object sender, CallForwardReceivedEventArgs e)
{
    e.Accept();
}

If that isn’t cool enough for you (I admit it’s a little anticlimactic), you can be more selective about the transfers you accept.

void _avCall_TransferReceived(object sender, 
    AudioVideoCallTransferReceivedEventArgs e)
{
    if (e.TransferredBy == "sip:telemarketer@useless-widget.com")
    {
        e.Decline();
    }
    else
    {
        e.Accept(null);
    }
}

Finally, depending on what you are doing with your application, you will probably want a handle to the new Conversation initiated by the transfer:

void _avCall_TransferReceived(object sender, 
    AudioVideoCallTransferReceivedEventArgs e)
{
    e.Accept(null);
 
    _conversation = e.NewConversation;
}

As you can see, this is all still very simple. Just remember to do it whenever your application needs to accept transfers, and you’re in business.