Pages Menu
TwitterRssFacebook

Posted by on May 1, 2015 in Learn Skype Web SDK | 0 comments

Learn Skype Web SDK Day 2 : Logging Out

Learn Skype Web SDK Day 2 : Logging Out

This is one post in a series of more than 30, devoted to helping you get up to speed quickly with the new Skype Web SDK. Each lesson comes with source code (in GitHub) and a working demo page so you can see what it does. Check out the full list of posts on the Skype Web SDK page.

View Demo

Last time we talked about getting logged in, and looking at the current signed-in state.

Equally important is getting logged out. If you only ever log in using the Skype for Business API and don’t log out, instead just closing the browser, then the user you have signed in will continue to show as signed in for a period of time afterwards. This can be confusing to people who try and send them messages etc. Therefore, you should try and ensure that a log out takes place when the user has finished wherever possible.

To sign out, call signOut on the signInManager object. The method doesn’t take any parameters, and returns a promise so you can react to a successful or unsuccessful sign out:

[code language=”javascript”]

client.signInManager.signOut()
.then(function () {
//log out worked!
alert(‘Logged out!’);
}, function (error) {
//Something went wrong.
alert(error);
});

[/code]

Previously, we talked about the state property of the signInManager. Whilst you can always use that to retrieve the current sign-in status of the user, you might want to make your application more responsive.

You can react to changes in state by coding against the state.changed event:

[code language=”javascript”]

client.signInManager.state.changed(function (state) {
//do something, the state has changed.
});

[/code]

The new value of state is available in the state parameter.

Alternatively, you can react conditionally, according to specific states. For instance, to do something only if the state has just changed to SignedIn:

[code language=”javascript”]

client.signInManager.state.when(‘SignedIn’, function () {
//do something, state is SignedIn
});

[/code]

The example below takes the log-in example from before, adds a Log Out button, and adds a log-in state indicator:

[code language=”javascript”]

[/code]

Demo Online

You can try this code out against your own Skype for Business environment by going to the demo page. From here you can also download the code from GitHub if you want to host it
locally, or take it and use it in your next project.

Disclaimer: This is sample code, intended to inform and educate. It is not production-ready and is lacking key components such as error handling. You use it entirely at your own risk. You should fully understand the effects, limitations and risks of the code before executing, and understand the implications of any set-up steps. By using these code examples you are using the Skype Web SDK, so you should read the Skype Software License Terms to which you are agreeing.

Good to Know

Post a Reply

Your email address will not be published. Required fields are marked *

This site uses cookies to help make this website better. By continuing to use this site we’ll assume you’re OK with that (implied consent).