Handling application sharing calls in UCMA

UCMA doesn't include support for application sharing calls out of the box; it can handle only audio/video and instant messaging calls. This is normally not a big deal, since there's not a whole lot that you could do in UCMA with application sharing. By virtue of not having a screen image to share, a UCMA app would be a pretty meaningless participant in an application sharing call. There's one case, though, where being able to handle application sharing calls would be convenient: creating back-to-back calls between other Lync users. Yes, the BackToBackCall class, which has so many delightful uses for audio calls, also applies to application sharing. But if UCMA doesn't have any support for the application sharing modality, how can you possibly create back-to-back application sharing calls?

Buried deep within the bowels of the Contact Center reference sample (one of the sample applications that ships with UCMA) is a set of classes which help to enable app sharing support for UCMA. If you've installed UCMA in the default location, you'll find them here:

C:\Program Files\Microsoft UCMA 3.0\SDK\Core\Sample Applications\Reference\ContactCenter\ContactCenterAssembly\AppSharingExtensibility

Include the files from this directory in your project, and you'll be able to handle application sharing calls, with a few extra steps which I'll explain shortly.

Note: Please keep in mind that this code is from a sample application. There may be licensing or stability reasons why you should avoid using it in a production application. Those considerations are your responsibility.

Simply including the files in your project in Visual Studio,as you can probably imagine,won't enable application sharing support by itself. You'll need to do a couple more things. First of all, you'll need to register some of the classes with your CollaborationPlatform as "platform extensions," as shown in the following code:

[csharp] ProvisionedApplicationPlatformSettings settings = new ProvisionedApplicationPlatformSettings( "Tester", "urn:application:mgreenlee.test");

_platform = new CollaborationPlatform(settings);

// Register the platform extensions for application sharing. _platform.RegisterPlatformExtension( new ApplicationSharingCallFactory()); _platform.RegisterPlatformExtension( new ApplicationSharingMcuSessionFactory()); _platform.RegisterPlatformExtension( new ApplicationSharingMcuSessionNotificationProcessorFactory());

_platform.RegisterForApplicationEndpointSettings( OnApplicationEndpointSettingsDiscovered);

// Start up the platform. try { _platform.BeginStartup( ar => { try { _platform.EndStartup(ar); } catch (RealTimeException ex) { Console.WriteLine(ex); } }, null); } catch (InvalidOperationException ex) { Console.WriteLine(ex); } [/csharp]

You'll also need to add a using statement for the namespace of the application sharing code files, unless you changed it:

[csharp] using Microsoft.Rtc.Collaboration.Samples.ApplicationSharing; [/csharp]

At this point, you can start using the ApplicationSharingCall class to represent calls with the application sharing modality. Placing or accepting an app sharing call directly from your UCMA application won't go so well, as you'll see if you try it with code like the following:

[csharp] ApplicationSharingCall call = new ApplicationSharingCall(c);

call.BeginEstablish("sip:mgreenlee@claritycon.com", null, ar => { try { call.EndEstablish(ar);

} catch (RealTimeException ex) { Console.WriteLine(ex); } }, null); [/csharp]

Running this code will produce an exception about the media type. This is related to what I said earlier about the UCMA application not having a screen of its own to share. Basically, even with these classes in place, UCMA doesn't have a way to handle the media streams that are involved in application sharing calls.

In a back-to-back call, though, the media bypasses the UCMA application entirely, so these work fine. Here's an example of an incoming call handler that creates an instance of BackToBackCall to bridge an incoming app sharing call to another Lync user.

[csharp] private void OnIncomingAppSharingCallReceived(object sender, CallReceivedEventArgs<ApplicationSharingCall> e) { Conversation conv = new Conversation(_endpoint); ApplicationSharingCall asCall2 = new ApplicationSharingCall(conv);

// Set up a B2B call using the incoming // call plus a new call to sip:user@blog.greenl.ee BackToBackCallSettings b2bSettings1 = new BackToBackCallSettings(e.Call); BackToBackCallSettings b2bSettings2 = new BackToBackCallSettings(asCall2, "sip:user@blog.greenl.ee");

BackToBackCall b2bCall = new BackToBackCall(b2bSettings1, b2bSettings2);

// Establish the B2B call. b2bCall.BeginEstablish(ar2 => { try { b2bCall.EndEstablish(ar2); } catch (RealTimeException ex) { Console.WriteLine(ex); } }, null); } [/csharp]

This will create a BackToBackCall which works just like the audio kind, but with application sharing.

Incidentally, these application sharing extension classes also serve as an interesting example of how to create custom media classes in UCMA, which I'll cover in more detail in a future post.