Learn Skype Web SDK Day 26 : Creating a Conference
[contemplate-1]
View Demo
A conference is nothing more than a conversation with more than one person. This is as oversimplification of course, but it can help to think like this when using the Skype for Web API, because that is the abstraction it provides.
When using the API, you can create a conference simply by creating a conversation exactly as you normally would, but adding more than one participant. Likewise, once a conversation has been established you can add participants. In the background the conversation will upscale to a conference, but the difference won’t be obvious via the API, and you don’t need to modify how you normally work with conversations:
[code language=”javascript”]
var conversation = client.conversationsManager.createConversation();
var convParticipant1 = conversation.createParticipant(contact1);
var convParticipant2 = conversation.createParticipant(contact2);
conversation.participants.add(convParticipant1);
conversation.participants.add(convParticipant2);
[/code]
There are two indicators though, which you can use to identify the difference between conversation and conference. The first is a isGroupConversation flag, which is part of the Conversation object. By registering state changes on this property you can be kept informed of when the upscale to conference occurs. The second is the conference URI. This is populated for conferences, and is the SIP URI which other Lync users can use to access the conference. Again, this has a changed event:
[code language=”javascript”]
conversation.isGroupConversation.changed(function () {
//do something when the conversation becomes a conference.
});
conversation.uri.changed(function () {
//do something with the conference URI
})
[/code]
In the example code for this post, specify two participants to start a conference. You can also then use the generated conference URI to allow other users to join.
In the code sample below, the user’s list of contacts and groups is displayed:
[code language=”javascript”]
isGroupConversation:
Conference URI:
var pageTitle = 'Creating a Conference'; var blogPostLocation = "http://thoughtstuff.co.uk"; var githubLocation = "http://github.com";
var client; $(function () { 'use strict';
Skype.initialize({ apiKey: 'SWX-BUILD-SDK', }, function (api) { client = new api.application();
// whenever client.state changes, display its value client.signInManager.state.changed(function (state) { $('#loginStatus').text("Login State: " + state); });
}, function (err) { alert('Error loading Skype Web SDK: ' + err); });
$('#btnLogIn').click(function () {
// start signing in client.signInManager.signIn({ username: $('#username').val(), password: $('#password').val() }).then(function () { //log in worked! alert('Logged in!'); $('#btnCreateConference').prop('disabled', false);
}, function (error) { //Something went wrong. alert(error); }); });
$('#btnLogOut').click(function () { // start signing out client.signInManager.signOut() .then(function () { //log out worked! alert('Logged out!'); $('#btnCreateConference').prop('disabled', true); }, function (error) { //Something went wrong. alert(error); }); });
$('#btnCreateConference').click(function () { CreateConference($('#contact1').val(),$('#contact2').val()); });
function CreateConference (contactSIP1,contactSIP2) { //first, get the people to start a conference with. We're using 2 people which //is the minimum for a conference, but you could easily use more. var contact1; GetContactFromName(contactSIP1).then(function (results) { results.forEach(function (result) { contact1 = result.result; });
var contact2; GetContactFromName(contactSIP2).then(function (results) { results.forEach(function (result) { contact2 = result.result; });
//create the conversation object var conversation = client.conversationsManager.createConversation();
//add the 2 contacts to the conversation by creating a conversation participant object //for each one. var convParticipant1 = conversation.createParticipant(contact1); var convParticipant2 = conversation.createParticipant(contact2); conversation.participants.add(convParticipant1); conversation.participants.add(convParticipant2);
conversation.isGroupConversation.changed(function () { $('#isGroupConversation').text(conversation.isGroupConversation()); });
conversation.uri.changed(function () { $('#conferenceUri').text(conversation.uri()); })
//add the newly created conference/conversation to the ConversationManager list client.conversationsManager.conversations.add(conversation);
conversation.chatService.start();
}); });
}
function GetContactFromName(contactSIP) { var query = client.personsAndGroupsManager.createPersonSearchQuery(); query.text(contactSIP); query.limit(1); return query.getMore(); }
});
[/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.
[contemplate-2]



Is there a way to join two chat conferences at the same time and chat in them ? The problem I get is that as soon as I create a second conversation the old one gets overridden and stops working and only the new one works.