Skype for Business – A Developer’s Guide : Part 2 – Client SDK
I’ve put together a series of 4 short videos, aimed at developers who are coming to Skype for Business development for the first time and want to know what’s possible. The videos show some of what you can do with some of the APIs and SDKs Microsoft make available with Skype for Business.
In this video I focus on the Client SDK, using it to solve a specific problem, using Visual Studio and a WPF application to illustrate how to get started writing Skype for Business applications.
Accompanying Blog Post: Pausing Lync when on a call using the Lync Client SDK
Source Code: github.com/tomorgan/LyncPauseMusicOnCall
Watch the whole series: Skype for Business: A Developer’s Guide
Hello. My name’s Tom Morgan. I write about Skype for Business development on my blog, thoughtstuff.co.uk.
I’ve put together a short 4-part series, designed for developers who are just getting started in Skype for Business development, or are curious about what’s possible.
There are 4 videos in the series. In the first one I covered the history of Skype for Business, showed some screenshots and listed the different types of development tools.
In this video we’re going to dig into one of those tools, the Client SDK. Nw in order to do that I’ve created and thought up a small scenario to use as a worked example.
Now, if you’ve used Skype for Business you’ll know that when an incoming call comes in, if you’re listening to music Skype for Business will actually reduce the volume of that music whilst you take the call. That’s really useful if you listen to music on external speakers and have a headset, because the music doesn’t then get in the way.
The problem I have is that, I wear a set of headphones, an integrated headset when I work in a busy office, which I also use to listen to music, and so what happens when an incoming call comes in is that the volume gets reduced but it doesn’t disappear altogether, so I still hear it whilst I’m having the conversation and the overall effect is that it’s like being in a movie, with the background music thing going on!
So what I want to do is have it so that when I’m on a call it pauses my music for me, and then when I come off the call, again, it takes it off pause and continues playing. So, let’s look at how we can do that using the Client SDK.
So, I’ve got Visual Studio here. Really simple project going on here, it’s a WPF application. It’s got a single XAML file, and all this code is not really production ready but it’s just got enough in it just to show you what’s possible. So, I’m using the Client SDK, what does that mean? It means that I’ve got a reference here to some of these DLLs you which get when you download the Client SDK. And really it’s this Microsoft.Lync.Model one which is quite interesting, and that gives you this here, the LyncClient.GetClient. So what I’m doing here, on this line here, is really just getting a handle to the Lync Client. Now, the Lync Client needs to be running, you don’t need to be signed in but it does need to be on the system and running in order for this work properly.
So, you might not be signed in so the first thing we’re going to do is register a state changed event. Now, this is something you do quite a lot in Skype for Business development is register for events. Because everything is asynchronous, at the end of the day you’re talking to a back-end service so things can happen in funny sequences, sequences you might not expect. So, I’m going to do that first and then I’m going to try and subscribe to the presence if signed in, but I’m also going to do that, you can see this here, on the state changed.
So, all I’m doing here is I’m checking really to see if I’m signed in, and if I’m not signed in I’m not going to do anything, I’m just going to wait until I am signed in. So I do two things here. The first is this client.self.contact.uri. Now I don’t want to go mega-deep into detail here but client.self as you might imagine, is the person you’re signed in as, dot contact is the contact object, and Uri is their SIP address. SIP being the identifier in Skype for Business used to identify people, looks like an email address but with sip: at the front, and use to identify people.
And what I’m doing here is setting it to this property here, SelfSipAddress. And the reason I’m doing that is, if I go into the XAML for a minute just so you can see, there is a control here. Now this is one of those WPF controls I talked about in the introductory video, and what it gives me is – here I just drop this in and I set the source to be that property I just showed you, and what it does is it puts the little presence icon, the little presence icon along with my name, on the screen.
I’m just going to run this for a second just so you can see that. So, you can see here it’s got my name and the green. But also if I hover over this I get all this stuff here. I get who I am, a nice photo of me, I can (if it wasn’t me doing it to me) I can call, I can look myself up, free-busy information, you get all that stuff built in just by dropping in this single item here. So that shows you how powerful this stuff can be.
So coming back to the code for a second, the second thing I’m doing then is I’m saying “tell me when the contact information changes”. I’m adding another event handler here for Contact Information Changed. And when that happens: you remember the original brief of the project, it was that when I’m on a call, it should pause. So, how do I know when I’m on a call? Well, two things need to happen. First of all my status, my presence status, needs to change to “Busy”, but then within that there’s a particular type of that where my Activity changes to being “on the phone”. So that’s what I’m doing here, I’m saying “look at the changed information”. So e comes across in the event arguments, have a look at the changed information – if it contains activity or it contains availability, which are the two things I want to check (so, presence is availability), then really the bit you’re expecting to see is that if statement here: if the availability is Busy and the activity is “on the phone” then trigger the pause button. I’m not going to go into Trigger Pause Button, it’s horrible C++ weirdy weirdy code that I didn’t really want to include, but all I really want to do is trigger the pause button that’s on the keyboard.
OK, so let’s see this in action. So, I have Spotify here, which I’m just going to start playing. Get that playing quietly. OK. And then I’m minimize that out of the way. And then, run my program as well, so it shows me here. So now I’m going to trigger an incoming call, which is also going to be coming from me but it’s a different SIP user which will pop up. OK. And as soon as I answer that my status goes to Busy, you can see here it says pause, so it’s already triggered, and down here you can see it’s stopped playing. As soon as I hang up and go green again it will start playing again by itself.
So that’s a really simple example application showing what’s possible, what you can do, how easily it all ties together. If I go back to this code here, none of this is particularly difficult, if you’re a .NET developer or even a Java developer it makes an awful lot of sense. The most complicated bits here are me messing around with the pause and not pause, just really saying whether I want this pause on the screen. Obviously, you should be aware of the limitations of this, this isn’t probably the best way of doing this, you can image that it’s going to trigger the pause button even if the music is already paused it’s going to start playing it and stuff, but I didn’t want to make this really complicated in terms of playing and pausing, I wanted to really concentrate on the Skype for Business side of things.
So hopefully that’s been useful. All the code is on GitHub so you can take the code and look at it yourself, and try it out, and build on it, and do something differently. The address is on the screen. There’s also an accompanying blog post which you can read, which goes alongside this and the code, just to dig into a little bit more detail. You can find out more information on my blog, thoughtstuff.co.uk, or you can follow me on Twitter, I’m @tomorgan. Thanks for watching.