Outgoing P2P/PSTN Call
Applies to: Skype for Business 2015
Notes
Important
P2P calls are not supported in Google Chrome.
Start a call
In order to make an audio call we need to:
create a conversation
var conversation = application.conversationsManager.getConversation('sip:XXXX'); // or var conversation = application.conversationsManager.getConversation('tel:+XXXX');
start the audio modality in the conversation
conversation.audioService.start();
Conversation state
We can subscribe to the conversation state to get information about the overall state of the conversation.
If a conversation's state is Connected
, it means that we are receiving live updates about state changes within the
conversation, and will receive updates when the state of any active modality in the conversation changes, or
when other participants connected to the conversation attempt to add or remove modalities. The conversation state
being Connected
does not mean that any particular modality is active.
conversation.state.changed(function (newValue, reason, oldValue) {
//...
});
Possible Conversation States:
State | Description |
---|---|
Created | ...When conversation was created |
Connecting | ...When establishing a connection |
Connected | ...When the conversation was successfully connected |
Disconnected | ...When the conversation got disconnected |
Audio Modality State
The conversation.selfParticipant.audio
property represents audio modality in the conversation.
This allows us to observe changes in the audio modality state
as a participant in the conversation.
For example: if the state changes to "Connected"
it means the audio modality has been successfully connected
in the conversation.
conversation.selfParticipant.audio.state.when('Connected', function () {
//...
});
Note
.when(value, callback)
Lets you subscribe to an observable and only triggers the callback when the observable changes its value to the value specified.
For Example: state.when('Connected', callback)
will execute the callback
when the value of state changes to "Connected".
Participants in Conversation
You can subscribe to the participants
collection on the conversation
object to be notified when new perticipants enter the conversation.
conversation.participants.added(function (participant) {
// ...
});
Ending an Audio Call
There are 2 ways to end an audio call: either stop the audio modality by calling conversation.audioService.stop()
or leave the conversation entirely by calling conversation.leave()
. If a modality other than audio, such
as chat, is active in the conversation, calling conversation.leave()
will disconnect that as well and
cause the conversation.state()
to become Disconnected
. If you want to hang up audio in a call but remain
connected to the conversation by chat, call conversation.audioService.stop()
.
conversation.leave().then(function () {
// successfully left the conversation
}, function (error) {
// error
});
// OR
conversation.audioService.stop().then(function () {
// successfully stopped audio
}, function (error) {
console.log("Failed to stop audio: " + error);
});
Complete Code Sample
Here is the code combined:
var conversation = application.conversationsManager.getConversation('sip:XXXX');
OR
var conversation = application.conversationsManager.getConversation('tel:+XXXX');
conversation.selfParticipant.audio.state.when('Connected', function () {
console.log('Connected to audio call');
});
conversation.state.changed(function (newValue, reason, oldValue) {
console.log('Conversation state changed from', oldValue, 'to', newValue);
});
conversation.participants.added(function (participant) {
console.log('Participant:', participant.displayName(), 'has been added to the conversation');
});
conversation.audioService.start().then(function() {
console.log('The call has been started successfully');
}, function (error) {
console.log('An error occurred starting the call', error);
});