Avaya Client SDK

< Back to Package Overview

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

  • Create a call object and initialize the details for the call
  • Implement the call delegate to monitor 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

Creating a CSCall object allows you to set various properties for the call before the call is actually placed.

The CSCall object is created from the CSCallService.

CSCallService* callService = user.callService;
CSCall* call = [callService createCall];

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

call.remoteAddress = callNumber;

Implement the call delegate to monitor for call events

To monitor call events, the <CSCallDelegate> protocol provided by the CSCall object can be used. This protocol provides notification as the call state changes.

Your application can define an object that implements the <CSCallDelegate> methods and can add it to the CSCall object to receive callback notifications.

@interface AppCallHandler() 
...
@end

@implementation AppCallHandler

    - (void)callDidStart:(CSCall *)call {
        // Called to report that call has started (ie, call is in progress).
        // Add code here to update the UI as appropriate.
    }

    - (void)callDidBeginRemoteAlerting:(CSCall *)call 
                        withEarlyMedia:(BOOL)hasEarlyMedia {
        // Called to report that an outgoing call is ringing at the far end.
        // Add code here to update the UI as appropriate.
    }

    - (void)callDidEstablish:(CSCall *)call {
        // Called to report that an outgoing call has been established 
        // (ie, far end has answered and speechpath has been established).
        // Add code here to update the UI as appropriate.
    }

    - (void)callDidEnd:(CSCall *)call reason:(CSCallEndReason)reason {
        // Called to report that call has ended.
        // Add code here to update the UI as appropriate.
    }

    - (void)call:(CSCall *)call didFailWithError:(NSError *)error {
        // Called to report that call has failed and the failure reason
        // is described in the error parameter.
        // Add code here to update the UI as appropriate.
    }

    - (void)updateVideoChannels:(NSArray *)videoChannels {
        // Called to report that video channels of the call updated
        // Add code here to update the UI as appropriate.
    }

    ...

@end

You can instantiate an application call handler (AppCallHandler) and add that as a delegate to the call.

AppCallHandler *callHandler = [[AppCallHandler alloc] init];
call.delegate = callHandler;

Obtain resources for the video stream

The application needs to obtain one or two resources when answering a call with video. If the application wishes to transmit video, it should find a video camera. Camera availability is verified through the CSVideoCapturerIOS class. This class manages most aspects of camera operation, including verification of available hardware. Regardless of camera need, a video interface is required.

VideoInterface* videoInterface = user.mediaServices.videoInterface;
CSVideoCapturerIOS* videoCapturer = [[CSVideoCapturerIOS alloc] init];

Assign video and start the call

To answer the incoming call with video, you should call setVideoMode with CSVideoModeSendReceive and then call the start method on the incoming call object.

[call setVideoMode:CSVideoModeSendReceive
                   completionHandler:^(NSError *handler)];
[call start];

Activate video resources

Video transmission/rendering could be updated as follows:

- (void)updateVideoChannels:(NSArray *)videoChannels {

    CSVideoChannel *videoChannel = videoChannels[0];

    if (videoChannel.enabled == YES) {
        // Start video rendering
        if (videoChannel.negotiatedDirection == CSMediaDirectionSendReceive
        || videoChannel.negotiatedDirection == CSMediaDirectionReceiveOnly) {
            // An object on the view that is responsible for video rendering
            CSVideoCapturerIOS* remoteSink = [[CSVideoRendereIOS alloc] init];
            [[videoInterface getRemoteVideoSource:videoChannel.channelId]
                                                  setVideoSink:remoteSink];
            }
        }

        // Start video transmission
        if (videoChannel.negotiatedDirection == CSMediaDirectionSendReceive
        || videoChannel.negotiatedDirection == CSMediaDirectionSendOnly) {
            // Use frontal camera - CSVideoCameraPositionFront 
            // or rear camera - CSVideoCameraPositionBack
            [videoCapturer useVideoCameraAtPosition:CSVideoCameraPositionFront
                                                        completion:nil];
            }
        }
    }
    else {
        [[videoInterface getRemoteVideoSource:videoChannel.channelId]
                                                            setVideoSink:nil];
        [videoCapturer setVideoSink: nil];
        }
    }
}

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.