Video Call
Rtc555 Android SDK supports Video calls between its users. It supports on-call features such as video mute/unmute, audio mute/unmute, etc.
Before initiating or accepting a Video call, make sure you have logged in to 555 platform.
SDK initialization
Below API initializes and sets the context for the SDK. It is advisable to call this API at the launch of the application. Pass application context to the API.
Rtc555Sdk.initializeLibrary(getApplication());
Parameters | |
---|---|
appContext | Application context |
Adding SDK configuration
To make Video related API call, SDK should have below mentioned mandatory configuration data to establish a connection with the 555 platform backend.
Rtc555Config config = Rtc555Sdk.getInstance().getConfig();
config.routingId = "<uuid@domain>" // Unique id for the user logged in 555 platform.
config.url = "<EVM_URL>" // Event manager URL
config.token = "<555 JWT token>" // JWT token for accessing the 555 SDK/backend APIs. Token can be access from the 555 login response.
config.notificationManagerUrl = "<NTM_URL>" // (Optional) For mobile notifications from 555 Platform
Rtc555Sdk.setConfig(config);
Create Stream
To make video call first you need to create stream which will provide you the local stream id that is used in video call APIs. We need to pass Rtc555VideoObserver as parameter.
On calling createStream API, user will get local stream id on onLocalStream callback.
Rtc555Video.createStream(Rtc555VideoObserver observer);
Parameters | |
---|---|
observer | Rtc555VideoObserver |
Initiate an Outgoing Video Call
To make outgoing video calls, pass callee email address, notification data and stream id to call API. Notification payload contains two fields called data and notification. The client can make use of data to send any custom key/value pair to remote (callee) end as part of the push notification payload. The below code shows some example to send caller Id (cid) & caller name (cname). The notification key contains the notification type and topic as mentioned in below code snippet.
The API also needs an instance of RTC555Result observer which provides onSuccess and onError callbacks.
call API returns a single value response. Success case of response will return call-Id (Unique identifier for the call). On failure it returns Rtc555Exception object.
Rtc555Video.call("testuser@comcast.com", notificationData(), streamId,observer, new Rtc555Result() {
@Override
public void onSuccess(String callId) {
Log.d(TAG, callId);
}
@Override
public void onError(Rtc555Exception e) {
Log.d(TAG, e.getMessage());
e.printStackTrace();
}
});
private HashMap notificationData() {
HashMap<String,HashMap> userdata = new HashMap<>();
HashMap<String,String> notification = new HashMap<>();
HashMap<String,Object> data = new HashMap<>();
try {
data.put("cname", "username");
data.put("cid", "testuser@comcast.com");
data.put("isVideoOnly", true);
notification.put("type", "video");
notification.put("topic", String.format("%s/%s", your_app_domain , "video"));
userdata.put("data", data);
userdata.put("notification", notification);
} catch (Exception e) {
e.printStackTrace();
}
return userdata;
}
Parameters | Description |
---|---|
targetEmailAddress | Target(callee) Email. |
notificationPayload | Notification payload data. |
streamId | Local Stream Id |
observer | Rtc555VideoObserver |
Rtc555Result | Instance of observer which gives success or failue callback |
Below is the Notification payload need to be build for outgoing notificationData:
Property | Type | Description |
---|---|---|
data | HashMap | e.g.
|
notification | HashMap |
|
Note: Please make sure client has microphone and camera permission before accessing the call/accept APIs from the SDK.
Accept Incoming Video Call
To accept the incoming Video call request, invoke accept API and pass the data received from incoming push notification. The API also needs an instance of RTC555Result observer which provides onSuccess and onError callbacks.
accept API returns call-Id (Unique identifier for the call). On failure it returns Rtc555Exception object.
Rtc555Video.accept(notificationData(incomingPushInvite), streamId, observer,
new Rtc555Result() {
@Override
public void onSuccess(String callId) {
Log.d(TAG,"CallId: "+callId);
}
@Override
public void onError(Rtc555Exception e) {
Log.d(TAG,e.getMessage());
Log.d(TAG,e.getCode());
}
});
private HashMap notificationData(Map<String, String> incomingPushInvite) {
HashMap<String, String> notificationdata = new HashMap<String, String>();
try {
notificationdata.put("trace_id", incomingPushInvite.get("trace_id"));
notificationdata.put("rtc_server", incomingPushInvite.get("rtc_server"));
notificationdata.put("room_id", incomingPushInvite.get("room_id"));
notificationdata.put("to_routing_id", incomingPushInvite.get("routing_id"));
notificationdata.put("room_token", incomingPushInvite.get("room_token"));
notificationdata.put("room_token_expiry_time",
String.valueOf(incomingPushInvite.get("room_token_expiry_time")));
} catch (Exception e) {
e.printStackTrace();
}
return notificationdata;
}
Parameters | Description |
---|---|
notificationData | Returns key/value pair for the data received from push payload. |
streamId | Local Stream Id |
observer | Rtc555VideoObserver |
Rtc555Result | Instance of observer which gives success or failue callback |
First parameter i.e notificationdata is the map including the key/value pair for the values received as part of the incoming push payload. Parse the notification payload and populate the notificationdata map for below keys.
Parameters | Description | Mapping in Notification Payload |
---|---|---|
trace_id | Trace ID for the call | <trace_id> |
room_id | Room ID that needs to be joined | <room_id> |
room_token | Room token | <room_token> |
room_token_expiry_time | Room token expiry time | <room_token_expiry_time> |
to_routing_id | Caller's routing Id | <routing_id> |
rtc_server | RTC server URL | <rtc_server> |
End an Active Video Call
Users need to invoke hangup API to end the active call.
Rtc555Video.hangup(String callId);
Parameters | Description |
---|---|
callId | callId is unique id for this call which was returned from call/accept API |
Clean up the session.
Call below API in Rtc555Sdk to release all the resources used by SDK. This call also allows the client to disconnect with the 555 platform backend. The app developer should call this API if the app goes to the background or kill state to release the SDK resource. Client need to call setConfig API again before attempting to initiate/accept the call.
Rtc555Sdk.cleanup();
Video On-call Features
Features offered by Android SDK for Video call are:
Toggle Audio Mute
This API call allows users to mute and unmute its audio in the ongoing call.
Rtc555Video.audioMuteToggle(String callId);
Parameters | Description |
---|---|
callId | callId is unique id for this call which was returned from call/accept API |
Toggle Video Mute
This API call allows users to mute and unmute its video stream in the ongoing call.
Rtc555Video.videoMuteToggle(String callId);
Parameters | Description |
---|---|
callId | callId is unique id for this call which was returned from call/accept API |
Flip Camera
This API call allows users to flip between front and rear camera of the device.
Rtc555Video.flipCamera();
Video Call Callbacks
To get local stream, remote stream, call status or error report implement Rtc555VideoObserver interface and initialize the observer and pass in call / accept API
onLocalStream
This callback gets is used to get local stream id which is required to make call and accept call. This stream can be used to render in the device screen using Rtc555Renderer
public void onLocalStream(String s);
Parameters | Description |
---|---|
streamId | Local Stream Id |
onRemoteStream
This callback gets is used to get stream id of remote participant which is used to render remote video in the current user's screen using Rtc555Renderer
public void onRemoteStream(String s);
Parameters | Description |
---|---|
streamId | Remote Stream Id |
onStatus
This callback gets invoked when we receive the status of an ongoing Video call.
void onStatus(Rtc555Sdk.CallStatus callStatus, String callId);
Parameters | Description |
---|---|
status | status of ongoing call |
callId | Call id for the ongoing call |
Call Status:
- connected - When the call is connected and media(video stream) started transffering.
- disconnected - When the call is disconnected i.e. when remote side hang up the call.
onError
This callback gets invoked when we receives Rtc555Exception from an ongoing Video call.
void onError(Rtc555Exception rtc555Exception, String callId);
Parameters | Description |
---|---|
rtc555Exception | error object consists of error code and error message |
callId | callId received from backend |
Video Call Renderer
The video call renderer referred as Rtc555Renderer provided by the Rtc555Sdk is use to render the video on the UI using stream id from Local Stream and Remote Stream.
To initialize you need to pass the height and width of the View where we need to render the video stream. After that you have to add the rootView variable of Rtc555Renderer in the layout View of the UI (Use FrameLayout for best result). You need to create two instances of Rtc555Renderer, one for Local and one for Remote.
Rtc555Renderer renderer = new Rtc555Renderer(width, height);
yourFrameLayout.addView(renderer.rootView);
Parameters | Description |
---|---|
width | Width of the rendering View |
height | Height of the rendering View |
addStream
This API is used to add the Stream id receive from Local Stream and Remote Stream in the Rtc555Renderer
void addStream(streamId, activity);
Parameters | Description |
---|---|
streamId | Stream Id |
activity | Android Activity |