Using the Avaya Client SDK, you can easily integrate the ability for users of your application to make and receive audio or video calls.
To receive and answer an incoming video call, you must complete the following activities.
In order to get notifications for any incoming calls, your application can implements and adds callbacks to the Calls object to receive call service notifications.
calls.addOnIncomingCallCallback(function(call) {
// Called to report that there is an incoming call.
// Add code here to handle this incoming call, eg,
// update UI to alert user, provide options for handling
// the call, ... etc.
});
calls.addOnCallRemovedCallback(function(call) {
// Called to report that the call has been removed before
// answer.
// Add code here to handle the removed call, eg,
// update UI to remove the call... etc.
});
When there is an incoming call, the Calls.addOnIncomingCallCallback() callback function is called with a Call object in the arguments.
Any incoming call may include video, and the App needs to use the getIncomingVideoOffered API on the Call to determine the call's offer status. The API returns one of three values which the application must handle
var incomingVideoOffered = call.getIncomingVideoOffered();
The application accepts a video call by setting video mode prior to invoking call.accept().
// Set the desired direction on the video channel
if (video-transmission-desired) {
call.setVideoMode(AvayaClientServices.Services.Call.VideoMode.SEND_RECEIVE);
// Answer the call. Note that there's no guarantee that it will
// start with the expected video direction (or any video).
call.accept();
One video-related callback must be implemented on the Call's to allow your application to transmit or receive video with directions matching the one negotiated by the remote endpoint. Although bi-directional or receive-only video is requested by the local application, the remote's video direction may not be compatible.
call.addOnCallVideoChannelsUpdatedCallback(function(call) {
var mediaEngine = client.getMediaServices();
var videoChannels = call.getVideoChannels();
// Retrieve the local and remote HTML video elements.
// Both the local and remote video elements should have both autoplay and muted properties set.
var localVideoControl = document.getElementById('localVideo');
var remoteVideoControl = document.getElementById('remoteVideo');
if (videoChannels[0]) {
var localStream;
var remoteStream;
switch (videoChannels[0].getNegotiatedDirection()) {
case AvayaClientServices.Services.Call.MediaDirection.RECV_ONLY:
localVideoControl.src = '';
remoteStream = mediaEngine.getVideoInterface().getRemoteMediaStream(videoChannels[0].getChannelId());
if (AvayaClientServices.Base.Utils.isDefined(remoteStream)) {
remoteVideoControl.src = URL.createObjectURL(remoteStream);
}
break;
case AvayaClientServices.Services.Call.MediaDirection.SEND_ONLY:
localStream = mediaEngine.getVideoInterface().getLocalMediaStream(videoChannels[0].getChannelId());
if (AvayaClientServices.Base.Utils.isDefined(localStream)) {
localVideoControl.src = URL.createObjectURL(localStream);
}
remoteVideoControl.src = '';
break;
case AvayaClientServices.Services.Call.MediaDirection.SEND_RECV:
localStream = mediaEngine.getVideoInterface().getLocalMediaStream(videoChannels[0].getChannelId());
if (AvayaClientServices.Base.Utils.isDefined(localStream)) {
localVideoControl.src = URL.createObjectURL(localStream);
}
remoteStream = mediaEngine.getVideoInterface().getRemoteMediaStream(videoChannels[0].getChannelId());
if (AvayaClientServices.Base.Utils.isDefined(remoteStream)) {
remoteVideoControl.src = URL.createObjectURL(remoteStream);
}
break;
case AvayaClientServices.Services.Call.MediaDirection.INACTIVE:
case AvayaClientServices.Services.Call.MediaDirection.DISABLE:
default:
localVideoControl.src = '';
remoteVideoControl.src = '';
break;
}
} else {
localVideoControl.src = '';
remoteVideoControl.src = '';
}
});
To terminate the call from the application, you can use the end() function on the call object.
call.end();
The addOnCallEndedCallback is triggered when the call has been ended. Use this event to update the UI of your application. Ending the call will release the video camera automatically. Again, see the Sample App for the steps.