Avaya Client SDK

< Back to Package Overview

Making a video call

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 make a video call, you must complete the following activities:

  • Create a call object and initialize the details for the call
  • Subscribe for call events
  • Obtain resources for the video stream
  • Assign video and start the call
  • Activate the video resources
  • End the call

Create a call object and initialize the details for the call

The Call object is created from the CallService. The call object is created from the Call Service.

Call call = user.CallService.CreateCall();

You can specify the phone number to dial by setting the remote address.

call.RemoteAddress = callNumber;

Subscribe for call events

In order to track accepted call's lifecycle, you can subscribe for different events of the Call object. In order to transmit local video and render incoming video you can subscribe for VideoChannelsUpdated event.

call.VideoChannelsUpdated += CallVideoChannelsUpdated;

Obtain resources for the video stream

The application needs to obtain two resources when making a call with video. A video camera. Camera availability is verified through the CameraVideoSource class. This class manages most aspects of camera operation, including verification of available hardware. A video inerface.

CameraVideoSource cameraVideoSource = new CameraVideoSource();
VideoInterface videoInterface = media.getVideoInterface();

Assign video and start the call

The application specifies a video call by setting video mode prior to invoking call.start() or when using call.accept().

call.SetVideoMode(MediaDirection.SendReceive, handler);
call.Start();

Activate video resources

// Main event to track video updates and start/stop video
void CallVideoChannelsUpdated(object sender, VideoChannelsEventArgs e)
{
    Call call = (Call)sender;
    // First check if video channels are not empty
    if (e.VideoChannels.Count > 0)
    {
        if (videoChannel.IsEnabled)
        {
            // Start video transmition
            try
            {
                // Capture form could be different
                cameraVideoSource.Start(
                    cameraVideoSource.Cameras.First(),
                    new VideoCaptureFormat(1280, 720, 0, 30), null);
                VideoSink sink = 
                    videoInterface.getLocalVideoSink(channelId);
                cameraVideoSource.setVideoSink(sink);
            }
            catch (Exception ex)
            {
            // Handle exception here
            }
            // Start video rendering
            try
            {
                // An object on the view that is responsible for video render
                VideoRenderer2 remoteRendererSink = new VideoRenderer2();
                VideoSource videoSource = 
                    videoInterface.getRemoteVideoSource(channelId);
                videoSource.setVideoSink(remoteRendererSink);
            }
            catch (Exception ex)
            {
                // Handle exception here
            }
        }
        else
        {
            // Stop video transmission
            if (cameraVideoSource != null)
            {
                cameraVideoSource.setVideoSink(null);
            }
            // Stop video rendering
            VideoSource videoSource = 
                videoInterface.getRemoteVideoSource(channelId);
            if (videoSource != null)
            {
                videoInterface.getRemoteVideoSource(channelId).
                    setVideoSink(null);
            }
        }
    }

End the call

To terminate the call from the application, you can use the end() function on the call object.

call.End();

The onCallEnded callback event is sent to the call listener when the call has been ended. Use this event to update the UI of your application. Ending the call will deallocate the video channel and release the video camera automatically, but any render surface allocated by the application will need to be released by it. Again, see SdkSampleApp for the steps.