Video Call
555 Android SDK supports video calls between its users. It supports on-call features such as local hold and mute. Every session related API requests have their respective callbacks to notify the user about the status of the request. IrisRtcVideoSessionObserver interface provides the callbacks specific to audio session, in addition to the generic callbacks for any session type (audio, video or chat).
Before initiating or accepting a video call, make sure to have logged in and have an active Rtc Connection. If app has been disconnected from RTC server due to inactivity, user has to request for RTC connection. Before creating or joining a session, media(video and audio) stream should be created.
Create Local Media Stream
The IrisRtcStream class manages the audio and video streams that can be created using Iris stream APIs. The IrisRtcStreamObserver provides callbacks related to stream class. The following method is called to create a stream with default options. It will create stream with both audio and video with video quality as HD and make use of back camera.
IrisRtcStream(IrisRtcStreamObserver observer, Context context)
Parameters | |
---|---|
observer | Listener to receive the callbacks upon completion or failure of the operation. |
context | Application context |
startPreview() API is called to start a local preview for the chosen camera.
...
...
IrisRtcStream rtcStream = new IrisRtcStream(observer, context);
rtcStream.startPreview(eglBaseContext);
...
...
}
Create Renderer for Media Stream
startPreview() will use the callback method onLocalStream of IrisRtcStreamObserver to send the "mediaTrack" to the application. The application can create a renderer and add the same to this track. For remote stream, onAddRemoteStream of IrisRtcVideoSessionObserver is triggered when media stream is received from the remote end.
public void onLocalStream(final IrisRtcMediaTrack mediaTrack) {
super.onLocalStream(mediaTrack);
...
...
Handler.post(new Runnable() {
@Override
public void run() {
mediaTrack.addRenderer(localRenderer);
}
});
...
...
}
//Triggered when media is received from remote peer.
void onAddRemoteStream(final IrisRtcMediaTrack mediaTrack, String routingId, String sessionId) {
...
...
mHandler.post(new Runnable() {
public void run() {
localRenderer.updateRenderer(65, 60, 30, 25, IrisRtcRenderer.IrisSdkScaleType.SCALE_ASPECT_FIT, false, localRenderLayout);
remoteRenderer.updateRenderer(0, 0, 100, 100, IrisRtcRenderer.IrisSdkScaleType.SCALE_ASPECT_FILL, false, remoteRenderLayout);
mediaTrack.addRenderer(remoteRenderer);
}
});
...
...
}
private IrisRtcRenderer localRenderer;
private IrisRtcRenderer remoteRenderer;
/**
Note: The renderers should be created before creating IrisRtcStream instance itself so that, the renderers are available when the videotracks for local and remote video are created.
Below code snippet shows how to create renderers for local and remote video streams.
**/
{
...
...
SurfaceViewRenderer localSurfaceViewRender = mContentLayout.localVideoView; // localVideoView is SurfaceViewRenderer
SurfaceViewRenderer remoteSurfaceViewRender = mContentLayout.remoteVideoView; // remoteVideoView is SurfaceViewRenderer
EglBase rootEglBase = EglBase.create();
localSurfaceViewRender.init(rootEglBase.getEglBaseContext(), null);
remoteSurfaceViewRender.init(rootEglBase.getEglBaseContext(), this);
localSurfaceViewRender.setZOrderMediaOverlay(true);
localRenderer = new IrisRtcRenderer(0, 0, 100, 100, IrisRtcRenderer.IrisSdkScaleType.SCALE_ASPECT_FIT, false, localSurfaceViewRender);
remoteRenderer = new IrisRtcRenderer(0, 0, 100, 100, IrisRtcRenderer.IrisSdkScaleType.SCALE_ASPECT_FIT, false, remoteSurfaceViewRender);
...
...
}
Note: When using the stream class, it will ask user to allow to use camera while running. Please make sure access is allowed. The run time permission dialog is shown in the app. When the stream is started, local preview will be shown even before the call gets connected.Hence the pop-up for camera access will be presented to the user the moment call starts.
Initiate an Outgoing Call
Once the Rtcconnection is made, enter a valid user id to make an outgoing call. A video session is then created with the local stream and other necessary values using IrisRtcVideoSession class.
Create the session for your video call using,
void create(String roomId, String userData, IrisRtcStream stream, IrisRtcVideoSessionObserver observer)throws IrisRtcSDKException
Parameters | |
---|---|
roomId | Room Id of the session Initiater |
userData | Notification payload data. |
stream | Local media stream to be sent. |
observer | Listener to receive the callbacks for audio session. |
IrisRtcSDKException | Exception handler for SDK. |
...
...
IrisRtcVideoSession videoSession = new IrisRtcVideoSession(appContext);
try{
videoSession.create(roomid, userdata, rtcStream, observer);
} catch (IrisRtcSDKException e) {
Log.e(e, "Failed to create session");
}
...
...
//build notification payload
String buildNotificationPayload() {
Context context = mAppContext;
JSONObject userdata = new JSONObject();
JSONObject notification = new JSONObject();
JSONObject data = new JSONObject();
try {
final String phoneNumber = PrefManager.getPhoneNumber(context);
data.put("cname", userEmailId);
data.put("cid", userEmailId);
data.put("isVideoOnly", true);
notification.put("type", "video");
notification.put("topic", "<appDomain>/pstn");
userdata.put("data", data);
userdata.put("notification", notification);
} catch (JSONException e) {
e.printStackTrace();
}
}
...
...
Once the remote party has accepted your call request, audio and video streams from remote participant is as well available to the app.
Accept Incoming Call
To join the session, a local stream should be created and passed along with other parameters received in the incoming call notification to the below API:
void join(String roomId, String roomToken, String roomTokenExpiry, IrisRtcStream stream, String rtcServer,IrisRtcVideoSessionObserver observer,IrisRtcSessionConfig sessionConfig) throws IrisRtcSDKException
Parameters | |
---|---|
roomId | Room name that needs to be joined which is recieved in notification payload. |
roomToken | Room token which is recieved in notification payload. |
roomTokenExpiry | Room token expiry time retrieved from notification payload. |
stream | Local Media stream to be sent. |
rtcServer | RTC server URL extracted from notification payload. |
observer | Listener to receive the callbacks for video session. |
sessionConfig | IrisRtcSessionConfig object for setting additional, optional session configuration parameters. |
IrisRtcSDKException | Exception handler for SDK. |
...
...
try{
videoSession.join(roomId, roomToken, roomTokenExpiryTime, rtcStream, rtcServer, videoSessionObserver, sessionConfig);
} catch (IrisRtcSDKException e) {
Log.e(e, "Failed to join video call session");
}
...
...
End an Active Call
On end call, all data and objects associated with that particular call must be cleared to avoid memory leak and efficiency. On end call, all data and objects associated with that particular call must be cleared for efficiency and to avoid memory leak. While closing a video call session following things must be kept in mind.
- Close video session
By invoking close() API in IrisRtcVideoSession, video session will get closed by releasing all objects associated with it. - Close stream
The close() operation of stream class is synchronous and can take time while closing the stream. Closing the stream during a session can cause an error in video or audio sessions. Hence it is advisable to close the stream after the session is closed.
...
...
videoSession.close();
rtcStream.close();
...
...
On-call Features
Features offered by Iris Android SDK for PSTN call are:
Hold Local Stream
Either caller or callee can hold local video stream in a call. When user holds the local video stream, other party will receive the audio stream but not the video stream. The user who had put the call on hold will not be able to see the preview of local camera but will be able to receive the remote media (audio and video) stream. stopPreview() API in IrisRtcStreamSession class is used to hold video in an active call.
...
private IrisRtcStream rtcStream;
...
...
rtcStream.stopPreview();
...
...
Unhold Local Stream
The user who kept the video stream on hold can unhold the same and resume sharing the video stream to remote participant.
...
private IrisRtcStream rtcStream;
...
...
rtcStream.startPreview(eglBaseContext);
...
...
Mute Local Audio
The participant can mute his end to stop sharing audio from their end, but at the same time they can receive audio from the other end. Iris Android SDK provides mute() API in IrisRtcStream class for the same.
...
private IrisRtcStream rtcStream;
...
...
rtcStream.mute();
...
...
Unmute Local Audio
If a participant is on mute, he can unmute the call. Only then the other party can hear the audio. Iris Android SDK provides unmute() API in IrisRtcStream class for the same.
...
private IrisRtcStream rtcStream;
...
...
rtcStream.unmute();
...
...
Video Call Related Callbacks
onAddRemoteStream
This callback is called when the remote stream is added to peerconnection (the mechanism in WebRTC that provides all the communication capabilities of WebRTC).
void onAddRemoteStream(IrisRtcMediaTrack mediaTrack, String participantId, String roomId, String traceId);
Parameters | |
---|---|
mediaTrack | Instance of IrisRtcMediaTrack containing remote track |
participantId | Participant Id |
roomId | Room id received from backend |
traceId | Trace id |
onRemoveRemoteStream
This callback is called when the remote stream is removed from peerconnection.
void onRemoveRemoteStream(IrisRtcMediaTrack mediaTrack, String participantId, String roomId, String traceId);
Parameters | |
---|---|
mediaTrack | Instance of IrisRtcMediaTrack containing remote track |
participantId | Participant Id |
roomId | Room id received from backend |
traceId | Trace id |