Session Management

The Android SDK provides the following methods for managing video sessions:

Record a Session

You can record an RTC session as individual streams and get it transcoded through a post-session service to create a single composite video file that can be retrieved and replayed using any video player. You can configure the room for auto-recording or invoke APIs to start recording when required. For details on fetching recorded sessions, refer to How to fetch Recordings?

Ways to Record a Session

A session can be recorded in the following ways:

Auto-Recording a Session

You can configure a Room with { settings: { auto_recording: true }} during Room Creation to automatically start recording the RTC session taking place in the room. The moderator of the room can stop the recording using the stopRecord() method.

On-Demand Recording

Start Recording a Session

The EnxRoom.startRecord() method allows the moderator to start recording a session. You can use this method to provide options on the UI for the moderator to access them.

There is no limit to the number of times a moderator can start recording.

Class: EnxRoom

Method: public void startRecord()

Observer: public void setRecordingObserver(EnxRecordingObserver-Object)

Callbacks

CallbackDescription
setRecordingObserverInitiates recording observer to receive callbacks.
onStartRecordingEventNotification to the moderator in a room when the recording starts.
onRoomRecordingOnNotification to all the participants in a room when the recording starts.

Sample Code

// Initiate Recording Observer to receive Callbacks
room.setRecordingObserver(this);
room.startRecord(); // To start recording
public void onStartRecordingEvent(JSONObject jsonobject){
// You started recording
}
public void onRoomRecordingOn(JSONObject jsonobject){
// Recording has started - to all
}

Error codes and Exceptions

CodeDescription
5007Unauthorized access. When a participant tries to invoke startRecord().
5033Repeated startRecord() call when the previous request is in process.
5034Repeated startRecord() call when the recording has already started.

Stop Recording a Session

The EnxRoom.stopRecord() method allows the moderator to stop recording of a session. You can use this method to provide options on the UI for the moderator to access them.

There is no limit to the number of times a moderator can stop recording.

Class: EnxRoom

Method: public void startRecord()

Observer: public void setRecordingObserver(EnxRecordingObserver-Object)

Callbacks

CallbackDescription
setRecordingObserverInitiates recording observer to receive callbacks.
onStopRecordingEventNotification to the moderator when the recording stops.
onRoomRecordingOffNotification to all the participants in a room when the recording stops.

Sample Code

// Initiate Recording Observer to receive Callbacks
room.setRecordingObserver(this);
room.stopRecord(); // To stop recording
public void onStopRecordingEvent(JSONObject jsonobject){
// You stopped recording
}
public void onRoomRecordingOff(JSONObject jsonobject){
// Recording has stopped - to all
}

Error codes and Exceptions

CodeDescription
5008Unauthorized access. When a participant tries to invoke stopRecord().
5035Repeated stopRecord() call when the recording has already stopped.
5036Invoke the stopRecord() call without starting to record. Non-contextual method call.

Live Recording with UI

Note: This functionality available from the Android SDK v2.1.2 version and later.

Recording live refers to a new process of creating a transcoded file in a live session with a custom layout without recording individual streams. It provides the following advantage:

  • You get a transcoded file within minutes post-session without waiting for long like the previous transcoding process.
  • Unlike previous transcoding processes created in a predefined layout, you can define your own layout for the live recording process.

Auto Live Recording

You can configure a room to automatically start live recording when the first person joins the room. To do this, add the following settings while creating a room:

"settings": {
"live_recording": {
"auto_recording: true,
"url": "https://your-custom-view-url"
}
}

For more information, see:

How to Create a Custom View for Live Recording. It is the same as creating a view for live streaming.

A moderator can stop live recording in a room by using the stopRecord() method.

On-Demand Live Recording

Start Live Recording

The EnxRoom.startLiveRecording() method allows moderators to start live recording of video sessions.

Class: EnxRoom

Observer: public void setLiveRecordingObserver(EnxLiveRecordingObserver enxLiveRecordingObserver)

Method: public void startLiveRecording(JSONObject jsonObject)

Parameters Data Type Description
streamingConfig JSON Object Streaming configuration.
streamingConfig.urlDetails: To define custom view and its options.
  • url: To specify the URL of the custom view. For more information, see Create Custom View for Live Recording .
  • any_custom_key_object: You may use any custom key or object that your Custom View handles to change view/layout through query string.

Callback: onACKStartLiveRecording: Acknowledgment callback to the Moderator when the Live Recording starts.

Sample Response

{data ={
confNum = 534010000012;
isRecordingInitiated = 1;
type = RecordingInitiated;
};
status ={
error ={
errorCode = 0;
errorDesc = "";
};
resultCode = 0;
success = 1;
};
}

Callbacks

CallbackDescription
onRoomLiveRecordingOnNotification to all the users in the room that the Live Recording has started.
onRoomLiveRecordingUpdateIntermediate Notifications to all users about progress of the Live-Recording process.
onRoomLiveRecordingFailedNotification to all users if Live Recording failed to start or failed after getting started.

Sample Code 1

{
data = {
data = {
data = {
confNum = 534010000012;
isRecordingInitiated = 1;
type = RecordingInitiated;
};
status = {
error = {
errorCode = 0;
errorDesc = "";
};
resultCode = 0;
success = 1;
};
streamerDetails = {
agentId = "d6acdf34-01f3-ca66-2bcc-789363adc043";
broadCastStreamerID = "b5296afd-1357-1de1-c89d-5dc0aca3e5ae";
};
};
startedBy = "7f0f2b04-1ad4-4231-8fdc-9f9e014053b4";
};
type = "liveRecording-started";
},
enxRoom.setLiveRecordingObserver(this); //To get Live recording callback, the user needs to set this live recording observer
enxRoom.startLiveRecording(jsonObject)
// Where streamingConfig/jsonObject =
{
"urlDetails": {
"url": "url",
"layOut": {},
"chatOverlay": true/false
}
}
public void onACKStartLiveRecording( JSONObject jsonobject) {
// To the Moderator - Live Recording has started
}
public void onRoomLiveRecordingOn( JSONObject jsonobject) {
// To all the participants - Live Recording started
}
public void onRoomLiveRecordingUpdate( JSONObject jsonobject) {
// To all the participants - Live Recording updates
}
public void onRoomLiveRecordingFailed( JSONObject jsonobject) {
// To all the participants - Live Recording failed
}

Error Codes and Exceptions

CodeDescription
5086The Endpoint application is not connected to the Room
5097Start Live Recording methods are not available in the Chat-Only Room
5138Failed to Start Live Recording with an invalid configuration parameter
5122Start Live Recording is in progress. Retrying to Start Live Recording is illegible
5139Live Recording is already running. Retrying to Start Live Recording is illegible
Stop Live Recording

The EnxRoom.stopLiveRecording() method allows moderators to stop live recording of video session.

Class: EnxRoom Method: public void stopLiveRecording(JSONObject jsonObject)

Note: This method is available only for Android SDK 2.1.2 and later versions.

Method: public void stopLiveRecording()

Note: This method is available only for Android SDK 2.1.3 and later versions.

ParameterData TypeDescription
streamingConfigJSON ObjectOptional
Streaming configuration
You can pass streaming configuration data as it was passed with startLiveRecording() method.

Callbacks:

CallbackDescription
onACKStopLiveRecordingAcknowledgment callback when the live recording stops.
onRoomLiveRecordingOffNotification to all users in the conference that the live recording has stopped.

Sample Response

{
data ={
data ={
confNum = 534010000012;
isRecordingStopped = 1;
type = recordingStopped;
};
isRecordingStarted = 0;
status ={
error = {
errorCode = 0;
errorDesc = "";
};
resultCode = 0;
success = 1;
};
streamerDetails ={
agentId = "d6acdf34-01f3-ca66-2bcc-789363adc043";
broadCastStreamerID = "b5296afd-1357-1de1-c89d-5dc0aca3e5ae";
};
};
status = {
error ={
errorCode = 0;
errorDesc = "";
};
resultCode = 0;
success = 1;
};
streamerDetails = {
agentId = "d6acdf34-01f3-ca66-2bcc-789363adc043";
broadCastStreamerID = "b5296afd-1357-1de1-c89d-5dc0aca3e5ae";
};
}

Sample Code 1

{
data = {
data = {
data = {
data = {
confNum = 534010000012;
isRecordingStopped = 1;
type = recordingStopped;
};
isRecordingStarted = 0;
status = {
error = {
errorCode = 0;
errorDesc = "";
};
resultCode = 0;
success = 1;
};
streamerDetails = {
agentId = "d6acdf34-01f3-ca66-2bcc-789363adc043";
broadCastStreamerID = "b5296afd-1357-1de1-c89d-5dc0aca3e5ae";
};
};
status = {
error = {
errorCode = 0;
errorDesc = "";
};
resultCode = 0;
success = 1;
};
streamerDetails = {
agentId = "d6acdf34-01f3-ca66-2bcc-789363adc043";
broadCastStreamerID = "b5296afd-1357-1de1-c89d-5dc0aca3e5ae";
};
};
stoppedBy = "7f0f2b04-1ad4-4231-8fdc-9f9e014053b4";
};
type = "liveRecording-stopped";
}
enxRoom.stopLiveRecording(jsonObject)
// For v2.1.2 - Where streamingConfig/jsonObject =
{
"urlDetails": {
"url": "url",
"layOut": {},
"chatOverlay": true/false
}
}
enxRoom.stopLiveRecording() // For v2.1.3+
public void onACKStopLiveRecording( JSONObject jsonobject) {
// To the owner - Live Recording has stopped
}
public void onRoomLiveRecordingOff ( JSONObject jsonobject) {
// To the participants - Live Recording stopped
}

Error Codes and Exceptions

CodeDescription
5086The Endpoint application is not connected to the Room
5097Start Live Recording methods are not available in the Chat-Only Room
5138Failed to Start Live Recording with invalid configuration parameter passed
5122Start Live Recording is in progress. Retrying to Start Live Recording is illegible
5140Live Recording is not running in the room. To Stop Live Recording is illegible
5141Stop Live Recording is in progress. Retrying to Stop Live Recording is illegible

Error Codes

Live Recording Waiting Queue

CodeDescription
7039The live recording request was in waiting, successfully removed the request from waiting
7046The streaming request was in waiting, successfully removed the request from waiting
7080Live recording/streaming requests in the waiting queue failed to start
7081Live recording/streaming requests in the waiting queue failed to start
7104The streaming request is in waiting and will start soon
7105The last streaming request is in waiting
7207The live recording request is in waiting and will start soon
7208The last live Recording request is in waiting

Play a Recorded File

If you want to play a recorded file directly from the EnableX server, note that those files are password protected. EnableX implemented HTTP basic authentication to secure recorded file storage.

Therefore, any video player may not use the file paths only to play them from the EnableX server. The player must provide access credentials to pass through the authentication process to play the file.

Sample Code

Map<String, String> header= new HashMap<String, String>(1);
final String cred = "USERNAME" + ":" + "PASSWORD";
final String auth = "Basic "+ Base64.encodeToString(cred.getBytes(),Base64.URL_SAFE|Base64.NO_WRAP);
header.put("Authorization", auth);
videoView.setVideoURI(Uri.parse("VIDEO_URL"),header);
videoView.start();

Notes:

  1. There is an alternate way. You can download the files from EnableX server to your server and play from there without or with any security measures you may like to deploy.
  2. Files from EnableX storage get deleted after 72 hours. So, accessing them from the EnableX server to play is not guaranteed beyond 72 hours.

Hard Mute or Unmute a Room

Hard Mute a Room

The EnxRoom.hardMute() method allows moderator to hard-mute a room where all the participants are muted. A new participant joining a room in a hard-mute state is automatically muted. The right to unmute a hard-muted room lies only with the moderator. Participants can neither unmute a room or their local streams.

Class: EnxRoom

Method: public void hardMute()

Observer: public void setMuteRoomObserver(EnxMuteRoomObserver-Object)

Callbacks

CallbackDescription
onReceivedMuteRoomNotification to all the participants in a room when the room is hard-muted.
onMutedRoomNotification to the moderator when the room is hard-muted.

Sample Code

// Initiate Hard-Mute Observer to receive Callbacks
room.setMuteRoomObserver(this);
room.hardMute(); // To hard-mute Room
public void onMutedRoom(JSONObject jsonobject){
// You hard-muted Room
}
public void onReceivedMuteRoom(JSONObject jsonobject){
// Room is hard-muted - notification to all paricipants
}

Error Codes and Exceptions

CodeDescription
5001Unauthorized access. A user with the participant role invokes hardMute().
5037Repeated hardMute()request when the previous request is in process.
5038An invalid hardMute() request when the room is already in a hard-mute state.

Hard Unmute a Room

The EnxRoom.hardUnMute() method is used to change the hard-mute state of a room. The right to unmute a hard-muted room lies only with the moderator. Participants can neither unmute a room or their local streams.

Class: EnxRoom

Method: public void hardUnMute()

Observer: public void setMuteRoomObserver(EnxMuteRoomObserver-Object)

Callbacks

CallbackDescription
onReceivedUnMuteRoomNotification to all the participants in a room when the room is hard-unmuted.
onUnMutedRoomNotification to the moderator when the room is hard-unmuted.

Sample Code

room.hardUnMute(); // To hard-unmute Room
public void onUnMutedRoom(JSONObject jsonobject){
// You hard-unuted Room
}
public void onReceivedUnMuteRoom(JSONObject jsonobject){
// Room is hard-unmuted - to all
}

Error Codes and Exceptions

CodeDescription
5002Unauthorized access. A user with the participant role invokes hardUnMute().
5039An invalid hardUnMuteRoom() request when the room is not in a hard-mute state.
5040Repeated hardUnMuteRoom() request when the previous request is in process.

Hard Mute or Unmute a Participant

Hard Mute a Participant

Note: Methods below are available for Android SDK version 2.1.3 and fewer.

The EnxStream.hardMuteAudio() and EnxStream.hardMuteVideo() methods allow the moderators to hard-mute the audio and video streams of participants. The affected participants cannot unmute their audio and video streams.

Class: EnxStream

Methods:

  • public void hardMuteAudio(String clientId)
  • public void hardMuteVideo(String clientId)

Parameter: clientID: The user whose audio/video needs to be hard muted.

Callbacks

CallbackDescription
onHardMutedAudioNotification to the affected participants when their audio is hard-muted.
onHardMutedVideoNotification to the affected participants when their video is hard-muted.
onReceivedHardMuteAudioNotification to all the participants in the room when a user's audio is hard-muted.
onReceivedHardMuteVideoNotification to all the participants in the room when a user's video is hard-muted.

Sample Code

stream.hardMuteAudio(clientId); // To hard-mute user's Audio Stream
public void onHardMutedAudio(JSONObject jsonobject){
// Your audio is hard-muted
}
public void onReceivedHardMuteAudio(JSONObject jsonobject){
// A User's audio is hardmuted - to all
}
// Video Hard-Mute will used in the same way as Audio.

Error Codes and Exceptions

CodeDescription
5009Unauthorized access. A user with the participant role invokes hardMuteAudio().
5011Unauthorized access. A user with the participant role invokes hardMuteVideo().

Note: The following methods are available only for Android SDK 2.1.3 and later versions.

Hard Unmute a Participant

Moderators can unmute a participant's audio or video streams using EnxStream.hardUnMuteAudio() and EnxStream.hardUnMuteVideo() methods.

Class: EnxRoom

Methods:

  • public void hardUnMuteAudio(String clientId)
  • public void hardUnMuteVideo(String clientId)

Note: These methods are available only for Android SDK 2.1.3 and later versions.

Parameter: clientID: The user whose audio/video needs to be hard unmuted.

Callbacks

CallbackDescription
onHardUnMutedAudioNotification to the affected participants when their audio is hard-unmuted.
onHardUnMutedVideoNotification to the affected participants when their video is hard-unmuted.
onReceivedHardUnMuteAudioNotification to all the participants in the room when a user's audio is hard-unmuted.
onReceivedHardUnMuteVideoNotification to all the participants in the room when a user's video is hard-unmuted.

Sample Code

stream.hardUnMuteAudio(clientId); // To hard-unmute user's Audio Stream
public void onHardUnMutedAudio(JSONObject jsonobject){
// Your audio is hard-unmuted
}
public void onReceivedHardUnMuteAudio(JSONObject jsonObject){
// A User's audio is hard-unmuted - to all
}
// Video Hard-Unmute will used in the same way as Audio.

Error Codes and Exceptions

CodeDescription
5010Unauthorized access. A user with the participant role invokes hardUnMuteAudio().
5012Unauthorized Access. A user with the participant role invokes hardUnMuteVideo().

Room Entry Restriction

Lock a Room

The EnxRoom.lockRoom() method allows moderators to lock a room, which forbids any new user from joining the session.

Class: EnxRoom

Method: public void lockRoom()

Callbacks

CallbackDescription
onAckLockRoomAcknowledgment to the moderator when the room is locked.
onLockedRoomNotification to all the participants in the room when the room is locked.

Sample Code

room.lockRoom();
// Moderator is acknowledged that room has been locked
public void onAckLockRoom(JSONObject jsonObject) {
// Handle JSONObject
}
// Participants are notified that room has been locked
public void onLockedRoom(JSONObject jsonObject) {
// Handle JSONObject
}

Error Codes and Exceptions

CodeDescription
5115Unauthorized access. A user with the participant role invokes lockRoom().
5117Invalid request. The moderator invokes lockRoom() on a locked room.

Unlock a Room

Moderators can unlock a room using the EnxRoom.unLockRoom() method to allow subsequent users to join the session.

Class: EnxRoom

Method: public void unLockRoom()

Callbacks

CallbackDescription
onAckUnLockRoomAcknowledgment to the moderator when the room is unlocked.
onUnLockedRoomNotification to all the participants in the room when the room is unlocked.

Sample Code

room.unLockRoom();
// Moderator is acknowledged that room has been unlocked
public void onAckUnLockRoom(JSONObject jsonObject) {
// Handle JSONObject
}
// Participants are notified that room has been unlocked
public void onUnLockedRoom(JSONObject jsonObject) {
// Handle JSONObject
}

Error Codes and Exceptions

CodeDescription
5115Unauthorized access. A user with the participant role invokes unlockRoom().
5118Invalid request. When the moderator invokes unlockRoom() on an unlocked room.

Moderate Participant's Entry to a Session

Approve a User's Entry to Join a Room

In a knock-enabled Room, users must wait until the moderator permits them to join a session. The EnxRoom.approveAwaitedUser() method allows moderators to approve a user's entry to join a room.

Method: public void approveAwaitedUser(String clientId)

Callbacks

CallbackDescription
onUserAwaitedNotification to the moderator when a user awaits permission to join a room.
onRoomAwaitedNotification to the user when they await moderator's permission to join a room with { "event_type": "knock" } in the JSON payload.
onAckForApproveAwaitedUserAcknowledgment to the moderator when the user is granted permission to join a room.
onRoomConnectedNotification to the user when the user is permitted to join a room.

Sample Code

// Moderator is notified about awaited user
public void onUserAwaited(JSONObject jsonObject) {
// Awaited Client Info in the jsonObject, e.g.
// {"id","String", "name": "String"}
enxRoom.approveAwaitedUser(jsonObject.id); // To allow user to join room
};
public void onAckForApproveAwaitedUser(JSONObject jsonObject) {
// User has been allowed entry
}

Decline a User's Entry to Join a Room

The EnxRoom.denyAwaitedUser() method allows moderators to decline a user's entry to join a room.

Class: EnxRoom

Method: public void denyAwaitedUser(String clientId)

Callbacks

CallbackDescription
onUserAwaitedNotification to the moderator when a user awaits permission to join a room.
onRoomAwaitedNotification to the user when they await moderators permission to join a room with { "event_type": "knock" } in the JSON payload.
onAckForDenyAwaitedUserAcknowledgment to the moderator when the user denied permission to join a room.
onRoomDisconnectedNotification to the user along with a reason for denial when the user is denied access to the room.

Sample Code

// Moderator is notified about awaited user
public void onUserAwaited(JSONObject jsonObject) {
// Awaited Client Info in the jsonObject, e.g.
// {"id","String", "name": "String"}
enxRoom.denyAwaitedUser(jsonObject.id); // To deny user
};
public void onAckForDenyAwaitedUser(JSONObject jsonObject) {
// User has been denied entry
}

Manage Awaited Users When the Moderator Joins Late

If a moderator joins a session after the participants have sent a request to join the session in a knock-enabled room, then the moderator can get a list of participants awaiting moderator's approval using room.awaitedParticipants. You can utilize this attribute to build the UI for moderator controls to handle pending approvals.

Sample Code

// e.g. room.awaitedParticipants
[
{ "clientId": "String",
"name": "String"
}
]

Disconnect a User

The EnxRoom.dropUser() method allows moderators to disconnect or force-drop one or more participants from a session.

Class: EnxRoom

Method: public void dropUser(List<String> clientIds)

Parameter: clientIDs: Required. List of Client IDs to be disconnected.

Callbacks

CallbackDescription
onAckDropUserAcknowledgment to the moderator when the user is disconnected.
onRoomDisconnectedNotification to the affected users with the reason of disconnection from the room.

Sample Code

room.dropUser(list);
// Moderator is acknowledged that user has been dropped
public void onAckDropUser(JSONObject jsonObject) {
// Handle JSONObject
}

Error Codes and Exceptions

CodeDescription
5116Unauthorized access. A user with the participant role invokes dropUser().

Session Extension and Closure

Extend a Session

Each Room is defined with a duration value in minutes. This duration defines the total length of a single session. This time is counted as soon as the first user joins the session. EnableX drops the session when the session duration elapses.

For practical reasons, a session may need to get extend. Therefore, EnableX allows users to extend a session duration at runtime. The extension process is explained below.

  1. An Extension window opens 10 minutes before the specified closure time of a session. All the connected users are notified of this event.
  2. Users can trigger an extension of the session by calling a method. Once triggered, the Extension Window is closed, thus preventing subsequent extension requests.
  3. If the extension is not triggered, the final Extension window opens 5 minutes before the scheduled closure of the session. All the connected users are notified of this event.
  4. The session can be extended by 10 to 30 minutes. The extended period can vary as there is no restriction on the number of times a session is extended.
  5. When a session is extended, the previous steps are repeated.

Method: public void extendConferenceDuration()

Callbacks

CallbackDescription
onConferenceRemainingDurationNotification to everyone in the room when an Extension window is open. It carries a JSON to show how many minutes are left before the closure of the scheduled session.
onConferencessExtendedNotification to everyone when the session is extended.

Sample Code

//Extend Request
room.extendConferenceDuration();
// Notifies that Session is scheduled to close in N Minutes
public void onConferenceRemainingDuration(JSONObject jsonObject) {
// Handle JSONObject
}
// Notifies that Session is extended
public void onConferencessExtended(JSONObject jsonObject) {
// Handle JSONObject
}

Conclude an Ongoing Session

The EnxRoom.destroy() method lets moderators to conclude an ongoing session.

Method: public void destroy()

Callbacks

CallbackDescription
onAckDestroyAcknowledgment to the moderator when the session is destroyed.
onRoomDisconnectedNotification to all users in the room when a session is destroyed.

Sample Code

room.destroy();
// Moderator is acknowledged that session is destroyed
public void onAckDestroy(JSONObject jsonObject) {
// Handle JSONObject
}

Error Codes and Exeptions

CodeDescription
5116Unauthorized access. A user with the participant role invokes destroy().

Switch Participant Roles

The EnxRoom.switchUserRole() method allows moderators to promote a participant to act as a moderator in an ongoing session. The newly appointed moderator is provided access to the moderator controls, and the former moderator becomes a participant in the session. If desired, the new moderator can grant the moderator role to another participant in the session.

Class: EnxRoom

Method: public void switchUserRole(String ClientId)

Parameter: clientId: Client ID of the participant who is designated as moderator.

Callbacks

CallbackDescription
onSwitchedUserRoleChangeAcknowledgment to the moderator when a switch user role is requested.
onUserRoleChangedNotification to all the participants in a room when a participant is newly appointed as the moderator. The appointed moderator is notified with extra information required to moderate the session.

Sample Code

room.switchUserRole(clientId); // Role Change Request from Moderator
public void onSwitchedUserRole(JSONObject jsonObject){
// Moderator is acknowledged
}
public void onUserRoleChanged(JSONObject jsonObject){
// All Participants are notified - jsonObject
/*
{ "moderator": false, // You are not a moderator
"clientId": "XXX" // New Moderator's Client ID
}
*/
// New Moderator is notified - jsonObject
/*
{ "moderator": true, // You are a moderator
"clientId": "XXX", // New Moderator's Client ID i.e. You
"raisedHands":[], // List of Client IDs requesting Floor Access
"approvedHands":[] // List of Client IDs with Floor Access
}
*/
}

Error Codes and Exceptions

CodeDescription
5085Unauthorized access. A user with the participant role invokes switchUserRole().

RTMP Live Streaming

Start Forwarding Live Video Session

The EnxRoom.startStreaming() method allows moderators to forward live video sessions over RTMP stream to any live streaming CDNs supporting this protocol.

Class: EnxRoom

Method: public void startStreaming(JSONObject streamingDetails)

Parameters

Parameter Data Type Description
streamingDetails JSON Object Configuration options for forwarding streams.
rtmpDetails.rtmpUrl: "RTM-URL/RTMP-KEY" from CDN provider.
rtmpDetails.urlDetails.urlUse: Optional RTMP streaming view URL. If it is not given then a default streaming view will be applied.

Callbacks

CallbackDescription
onAckStartStreamingAcknowledgment to the moderator when RTMP streaming starts.
onStreamingStartedNotification to all the users in a room when RTMP streaming starts.
onStreamingFailedNotification to all the users in a room when RTMP streaming fails to start or fails subsequently after getting started.
onStreamingUpdatedIntermediate notification to all the users in a room with updates on the RTMP streaming process.

Sample Code

JSONObject jsonObject = new JSONObject();
JSONObject rtmpDetails = new JSONObject();
rtmpDetails.put("rtmpUrl", "RTMP_URL/RTMP_KEY"");
jsonObject.put("rtmpDetails", rtmpDetails);
/* Optional Streaming View URL */
JSONObject urlDetails = new JSONObject();
urlDetails.put("url", "URL-TO-USE-AS-STREAMING-VIEW");
jsonObject.put("urlDetails", urlDetails);
room.startStreaming(jsonObject); // Start Streaming
public void onAckStartStreaming(JSONObject jsonObject){
// Acknowledges that Streaming started
}
public void onStreamingStarted(JSONObject jsonObject) {
// Notifies all that Streaming started
}
public void onStreamingFailed(JSONObject jsonObject) {
// Notifies all that Streaming failed
}
public void onStreamingUpdated(JSONObject jsonObject) {
// Notifies all with Streaming process updates
}

Error Codes and Exceptions

CodeDescription
5121Repeated startStreaming() call while the previous request is in process
5122Repeated startStreaming() call after Streaming has started
5125Invalid Stream configuration

Stop Forwarding Live Video Session

The EnxRoom.stopStreaming() method stops forwarding RTMP stream.

Class: EnxRoom

Method: public void stopStreaming(JSONObject streamingDetails)

Parameters

Parameter Data Type Description
streamingDetails JSON Object Configuration options for forwarding streams.
rtmpDetails.rtmpUrl: "RTM-URL/RTMP-KEY" from CDN provider.
rtmpDetails.urlDetails.urlUse: Optional RTMP streaming view URL. If it is not given then a default streaming view will be applied.

Callbacks

CallbackDescription
onAckStopStreamingAcknowledgment to the moderator when RTMP streaming stops.
onStreamingStoppedNotification to all the users in a room when RTMP streaming stops.

Sample Code

JSONObject jsonObject = new JSONObject();
JSONObject rtmpDetails = new JSONObject();
rtmpDetails.put("rtmpUrl", "RTMP_URL/RTMP_KEY"");
jsonObject.put("rtmpDetails", rtmpDetails);
/* Optional Streaming View URL */
JSONObject urlDetails = new JSONObject();
urlDetails.put("url", "URL-TO-USE-AS-STREAMING-VIEW");
jsonObject.put("urlDetails", urlDetails);
room.stopStreaming(jsonObject); // Stop Streaming
public void onAckStopStreaming(JSONObject jsonObject){
// Acknowledges that Streaming stopped
}
public void onStreamingStopped(JSONObject jsonObject) {
// Notifies all that Streaming stopped
}

Error Codes and Exceptions

CodeDescription
5123Repeated stopStreaming() call while the previous request is in process
5124stopStreaming() called without starting a Stream first. Non-Contextual Method Call

HLS Streaming

HLS streaming helps to scale up your reach to a larger audience with your real-time video session, meetings, and webinar. Audiences receive the best quality video streaming based on the available bandwidth at their end. A web-based video UI may be linked to define the view of your streaming which will be played across devices.

In the background, the linked video UI is automatically made to join the video room, and an HLS stream is created using the same view. As the stream is ready, endpoints receive an HLS stream URL from playing in HLS Player.

Service Subscription

HLS streaming infrastructure is owned and managed by EnableX. Therefore, it's a subscription-based service. Connect to the Sales/Account Manager for the subscription.

If you have a look to live stream on YouTube, Vimeo, LinkedIn, and/or Facebook, you need to know RTMP Live Streaming.

HLS View

HLS Streaming experience for audiences may be achieved through the video UI. You can have a video UI or HLS view in either of the following ways:

  • Use Default View: The simplest and quickest way is to use the default view for HLS streaming. You don't need to code it; it's available in EnableX. Limited customization option are available.
  • Develop Custom View: To have a custom view, a web-based application needs to be developed, hosted over a publicly accessible "https" URL, and linked to the video room. For more information, see how to develop a custom view for your stream.

HLS Enabled Room

Even if the HLS service is subscribed, the following room Level settings is done to have HLS Streaming in video session.

ParametersData TypeDescription
audiencesNumericOptional
Number of audiences needed in the room cannot be higher than the limit set during the subscription
If any of the following settings are being set with the room, audience count must be set to some positive number.
send_audiences_statsBooleanThe default is false
It can be set to true, if endpoint receives user-connected and user-disconnected event on entry and exit of an audience.
hls_view_urlStringOptional
If a custom view URL is not passed then the default HLS streaming view will be used.
You may explicitly pass "DEFAULT" as a value to this key.

For more information, see

Sample Code: Room Definition JSON Payload to enable HLS Streaming

{
"name": "HLS Trial",
"owner_ref": "XOXO",
"settings": {
"description": "HLS Trial",
"mode": "group",
"scheduled": false,
"adhoc": false,
"duration": 30,
"moderators": "1",
"participants": "2",
"audiences": 6,
"hls_view_url": "https://URL-DOMAIN/PATH/?token=",
"send_audiences_stats": true,
"auto_recording": false,
"quality": "SD"
}
}

Note: If HLS is not subscribed then room definition with HLS-related settings is not permitted.

HLS Audience Token to Join

A new role has been introduced for HLS audience joining a room. They can get a token for an audience role to join a session. HLS streaming gets initiated automatically as soon as the first audience joins the video room. HLS streaming stops when all audiences exit or disconnected from the video room.

For more information, see how to Create Token?.

Sample Code: Create Token JSON Payload for the audience role

{
"name": "John",
"user_ref": "XOXO",
"role": "audience"
}

Room Notifications

HLS Streaming starts as soon as the first audience joins the video room and stops when the last audience exits or disconnects from the room. So, use related HLS callbacks to handle the UI to create the user experience.

Observer: public void setEnxHlsObserver(EnxHlsStreamObserver enxHlsObserver): Add this Observer to start receiving HLS notifications.

Callbacks

CallbackDescription
onHlsStartedWhen HLS streaming starts, it's sent to the publisher and logged-in audiences. Subsequently, it's sent to a new audience on room connection. It carries hls_url to play.
onHlsStoppedWhen HLS streaming stops. It's sent to the publisher when the last audience leaves the video room.
onHlsWaitingWhen the HLS streaming initiation process is on and waiting to get started, it is sent to the audiences only.
onHlsFailedThis event is called when HLS streaming fails.

Sample Code

//Set Observer
enxRoom.setEnxHlsObserver(this);
// On HLS Start
public void onHlsStarted(JSONObject jsonObject) {
// JSON has hls_url key to play in HLS Player
}
// On HLS Stop
public void onHlsStopped(JSONObject jsonObject) {
}
// On HLS Waiting
public void onHlsWaiting(JSONObject jsonObject) {
}
// On HLS Failure
public void onHlsFailed(JSONObject jsonObject) {
}

Error Codes

On HLS Start

CodeDescription
7501Start HLS Streaming input parameters missing, internal server error.
7502Start HLS Streaming timeout, internal server error.
7503Start HLS Streaming request is in process.
7504Start HLS Streaming request timeout, internal server error.
7505HLS Streaming request is in waiting and will be started.
7506HLS Streaming cannot be started now. Try again after 2 minutes.
7507Start HLS Streaming input parameters missing, internal server error.
7508Start HLS Streaming input parameters missing, internal server error.

On HLS Stop

CodeDescription
7520The HLS Streaming request was in waiting, successfully removed the request from waiting.
7521Stop HLS Streaming failed, internal server error.
7522Stop HLS Streaming timeout, internal server error.

On HLS Waiting

CodeDescription
7509HLS Streaming cannot be started due to an internal server error. Try again after 2 minutes.
7510HLS Streaming start failed, internal server error. Try again after 2 minutes.
7511The last HLS streaming request is in waiting.
7512HLS Streaming cannot be started, internal server error. Try again after 2 minutes.
7513HLS Streaming failed to start, internal server error.

HLS Generic Error

CodeDescription
7000Start HLS Streaming input parameters missing, internal server error.

HLS Player

HLS stream URL received through video SDK needs to be played using HLS Player. The following code explains how to use ExoPlayer to play HLS stream.

Sample Code

<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/exoplayer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="100dp"
app:resize_mode="fixed_width"
/>
PlayerView ePlayer= findViewById(R.id.exoplayer);
String m3u8URL = "https://moctobpltc-i.akamaihd.net/hls/live/571329/eight/playlist.m3u8";
// Create a data source factory.
DefaultHttpDataSource.Factory dataSourceFactory = new DefaultHttpDataSource.Factory();
// Create a HLS media source pointing to a playlist uri.
HlsMediaSource hlsMediaSource =
new HlsMediaSource.Factory(dataSourceFactory)
.createMediaSource(MediaItem.fromUri(m3u8URL));
// Create a player instance.
ExoPlayer player = new ExoPlayer.Builder(context).build();
// Set the media item to be played.
player.setMediaSource(hlsMediaSource);
// Prepare the player.
player.prepare();
ePlayer.setPlayer(player);

Pin a User

The EnxRoom.pinUsers() method allows moderators to pin a user to the Active Talker List irrespective of the user's activity level. A pinned user's stream is always published in the room, even if the user is not talking. The inactive pinned users are placed in the Active Talker List after the actively talking users in a descending order based on the activity level, with the most active talkers at the top of the list. The total number of pinned users in a room is restricted to (max_active_talkers: 1) based on the room configuration.

On joining a Room, the user is notified through a onRoomConnected event with room meta information, which contains the list of pinned users as "pinnedUsers": [ /*client-ids*/ ].

Class: EnxRoom

Method: public void pinUsers(List<String> clientIds)

Parameters: clientIds: Array of Client IDs of users whose streams need to be pinned.

Callbacks

CallbackDescription
onAckPinUsersAcknowledgment to the moderator when the users are pinned.
onPinnedUsersNotification to all the participants in the room with an updated list of pinned users.

Sample Code

List<String> clientIds = new ArrayList<>();
clientIds.add("clientId1");
clientIds.add("clientId2");
enxRoom.pinUsers(clientIds); // To pin
// Moderator is acknowledged for pinning user
public void onAckPinUsers(JSONObject jsonObject){
}
// Everyone is notified wtih updated pinned list
public void onPinnedUsers(JSONObject jsonObject){
}

Error Codes and Exceptions

CodeDescription
5003Unauthorized access. A user with the participant role invokes pinUser().
5126Invalid client IDs are passed.

Unpin a User

The EnxRoom.unpinUsers() method is used to unpin the users.

Class: EnxRoom

Method: public void unpinUsers(List<String> clientIds)

Parameters: clientIds: Array of Client IDs of users whose streams need to be unpinned.

Callbacks

CallbackDescription
onAckUnpinUsersAcknowledgment to the moderator when the users are unpinned.
onPinnedUsersNotification to all the participants in the room with an updated list of pinned users.

Sample Code

List<String> clientIds = new ArrayList<>();
clientIds.add("clientId1");
clientIds.add("clientId2");
enxRoom.unpinUsers(clientIds); // To unpin
// Moderator is acknowledged for unpinning user
public void onAckUnpinUsers(JSONObject jsonObject){
}
// Everyone is notified wtih updated pinned list
public void onPinnedUsers(JSONObject jsonObject){
}

Error Codes and Exceptions

CodeDescription
5003Unauthorized access. A user with the participant role invokes unpinUser().
5126Invalid client IDs are passed.

Spotlight a User

The EnxRoom.addSpotlightUsers() method allows moderators to spotlight a user, pushing the user's stream to the top of the Active Talker List irrespective of the user's activity level. Spotlighting publishes the chosen user's stream in the room even if the user is not talking. The moderator can spotlight as many users as max_active_talkers defined in the room configuration.

On joining a room, the user is notified through a room-connected event with Room Meta Information, which contains the list of spotlightUsers.

In addition, the JSON containing the active talkers list received with the onActiveTalkersUpdated callback includes a "spotlight" key with a boolean value. Spotlighted users have spotlight: true in the list.

Class: EnxRoom

Method: public void addSpotlightUsers(List clientIds)

Parameters: clientIds: An array of Client IDs of users whose streams are spotlighted.

Callbacks

CallbackDescription
onAckAddSpotlightUsersAcknowledgment to the moderator when spotlight request is received with the following JSON { "result": 0, clients: \[\] }
result: 0 if success. It returns an appropriate error code if an error is encountered.
clients: Array of each Client IDs passed for spotlight.
onUpdateSpotlightUsersNotification to everyone in the room when the updated spotlighted user list is received with the following JSON { "moderator_id": String, clients: \[\] }
  • moderator_id: Id of the moderator who updates the spotlight user list.
  • clients: Array of Client IDs of users who are spotlighted.

Sample Code

List clientIds = new ArrayList<>();
clientIds.add("clientId1");
clientIds.add("clientId2");
enxRoom.addSpotlightUsers(clientIds); // To spotlight
// Moderator who spotlights users is acknowledged
public void onAckAddSpotlightUsers (JSONObject jsonObject){
// JSON { "result": 0, clients: [] }
}
// Everyone is notified with updated Spotlight list
public void onUpdateSpotlightUsers(JSONObject jsonObject){
// JSON { "moderator_id": "String", clients: [] }
}

Remove the Spotlight from a User

The EnxRoom.removeSpotlightUsers() method removes the spotlight from user streams.

Class: EnxRoom

Method: public void removeSpotlightUsers(List clientIds)

Parameters: clientIds: An array of Client IDs of users whose streams are spotlighted.

Callbacks

CallbackDescription
onAckRemoveSpotlightUsersOn success, it returns the response information of the requests in the JSON format: { "result": 0, clients: \[\] }
result: 0. It returns an appropriate error code if an error encountered.
clients: Array of each Client IDs removed from the spotlight.
onUpdateSpotlightUsersNotification to everyone in the room when the updated spotlighted user list is received with the following JSON { "moderator_id": String, clients: \[\] }
  • moderator_id: Id of the moderator who updates the spotlight user list.
  • clients: Array of Client IDs of users who are spotlighted.

Sample Code

List clientIds = new ArrayList<>();
clientIds.add("clientId1");
clientIds.add("clientId2");
enxRoom.removeSpotlightUsers(clientIds);// To remove from spotlight
// Moderator who removes users from Spotlight is acknowledged
public void onAckRemoveSpotlightUsers (JSONObject jsonObject){
// JSON { "result": 0, clients: [] }
}
// Everyone is notified with updated Spotlight list
public void onUpdateSpotlightUsers(JSONObject jsonObject){
// JSON { "moderator_id": "String", clients: [] }
}

Switch the Room Mode

A room defined with Group or Lecture mode may be switched to the other mode at runtime, that is, in an ongoing session. The EnxRoom.switchRoomMode() method is executed by the moderator to switch to other modes instantly.

When a room is switched from Group to Lecture mode:

  • The audio/video streams of all participants are dropped from the room with a notification to each participant.
  • All the features of the Lecture mode, such as floor access control are activated.
  • All active breakout rooms are terminated.

On the other hand, when a room is switched from Lecture to Group mode:

  • A notification is sent to each participant, allowing them to publish their audio/video streams into the room.
  • Due to privacy concerns, the SDK does not automatically start publishing audio/video streams, but application developers must decide whether to automatically publish the streams or prompt the participants to publish.

Class: EnxRoom

Observer: EnxSwitchRoomObserver

Method: public void switchRoomMode(String roomMode)

Parameter: roomMode: String. Enumerated values lecture, group
The mode to which you want to switch the room into.

Callbacks

CallbackDescription
onAckSwitchedRoomAcknowledgment to the moderator with status of the request.
onRoomModeSwitchedNotification to everyone in the room when the mode of operation of the room is switched to the desired mode.

Sample Code

enxRoom.setEnxSwitchRoomObserver(this);
enxRoom.switchRoomMode("group"); // To switch to group mode
// Moderator is acknowledged
public void onAckSwitchedRoom(JSONObject jsonobject){
/* JSONObject example:
{
"result": 1715,
"moderator": "String",
"msg": "Room switched to lecture mode",
"mode": "lecture"
}
*/
}
// Everyone is notified
public void onRoomModeSwitched(JSONObject jsonObject){
/* JSONObject example:
{
"result": 1715,
"moderator": "String",
"msg": "Room switched to lecture mode",
"mode": "lecture"
}
*/
}

Error Codes and Exceptions

CodeDescription
5003Unauthorized access. A user with the participant role invokes switchRoomMode().
5126Invalid room mode.
5086Room is not connected.
5136Non-contextual method call.
1716The room is in Lecture mode. Trying to switch to the Lecture mode while being in the same mode.
1717The room is in Group mode. Trying to switch to the Group mode while being in the same mode.