Pages Menu
TwitterRssFacebook

Posted by on May 28, 2015 in Learn Skype Web SDK

Learn Skype Web SDK Day 21 : Up-scaling to an Audio Call

Learn Skype Web SDK Day 21 : Up-scaling to an Audio Call

[contemplate-1]
View Demo

Adding audio to an existing call isn’t as hard as it sounds. With Skype for Web API, each modality (method of communication) is handled separately. Therefore, if you have already set up an Instant Message conversation, you can easily add Audio to the mix by finding the Audio Service (which is part of the conversation) and starting it. Likewise, you can safely stop it later without worrying about impacting any other modalities which may be active, such as Instant Messaging.

It really is an simple as:

[code language=”javascript”]
conversation.audioService.start();
[/code]

and:

[code language=”javascript”]
conversation.audioService.stop();
[/code]

In the example code for this post, you start by creating an Instant Messaging conversation. Once that is established you can start and stop the audio service repeatedly.

Of course, it might be you (or your user) which initiates the audio. Your application needs to be able to respond to incoming audio requests. Provided you are subscribing to state change events on the audio of the self participant (which you tend to do anyway to know whether the call has connected or is disconnected etc) you can do this.

For incoming call requsts on an existing conversation, the state will change to “Notified”. This indicates an incoming call request. You can then accept this request to start the audio call, or choose to reject it:

[code language=”javascript”]
conversation.selfParticipant.audio.state.changed(function (newState) {
if (newState == ‘Notified’)
{
//either
conversation.audioService.accept();
//or
conversation.audioService.reject();
}
[/code]

In the example code for this post, once the Instant Message conversation has been created, incoming requests to upscale to audio will show an Accept and Reject button.

[code language=”javascript”]


Conversation State:







    Audio Status:



    [/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]

    1 Comment

    1. Hay Tom,

      I’m trying up-scaling to video conversation from a connected audio conversation.. but when I call videoService.start() right after audioService.state() becomes “Connected” it fails to start the video. however if I waited say for 5 seconds and tried to start the video it succeeds.. what am I doing wrong? here’s the code:

      audioService.state.changed(
      function(state) {
      if (state == "Connected") {
      videoInterval = setInterval(addVideo, 5000);
      //addVideo();
      }
      });

      function addVideo() {
      conversation.videoService.start().then(function () { conversation.selfParticipant.video.channels(0).stream.source.sink.container(document.getElementById("divSelfVideoWindow"));
      });
      }

    Post a Reply

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