Room Connection

The Android SDK provides the following methods for room connection:

  • init(): To initiate a room.
  • connect(): To connect a client application to the virtual room.
  • joinRoom(): To join a room quickly.
  • disconnect(): To close the session and disconnect the client endpoint from the room.

Initiate a Room

An RTC session takes place in a virtual room hosted at EnableX. The Android SDK allows the client endpoint application to connect to it. The process starts with initializing a room object using the EnxRoom class.

Constructor: EnxRoom room = new EnxRoom( EnxRoomObserver-Instance, EnxStreamObserver-Instance)

After the room object is instantiated, call the EnxRoom.init() method.

Class: EnxRoom

Method: public void init( Context context )

Sample Code

EnxRoom room = new EnxRoom(
EnxRoomObserver-Instance,
EnxStreamObserver-Instance
);
room.init( activity-class-context );

Connect to a Room

The EnxRoom.connect() method connects a client application to the virtual room hosted on the EnableX server where the RTC session takes place. After initializing the room, the client endpoint must connect to the room to establish a bidirectional communication channel over a web socket.

As the communication takes place over the web sockets using socket events, any network issue leading to the disconnection of the web sockets causes the communication to fail. In such cases, EnableX offers the option to automatically reconnect with the room.

Note: The automatic reconnection is not applicable when:

  • The last participant has disconnected from the adhoc room.
  • The moderator has dropped the participant from the room.
  • The participant has explicitly disconnected from the room.

Class: EnxRoom

Method: public void connect(String token, JSONObject roomInfo, JSONObject advanceOptions)

Parameters Data Type Description
token String A JWT token to connect to the room. This token is received by the Server API call through the application server.
roomInfo JSON Object. Optional with reconnection options.
roomInfo.allow_reconnect: Boolean. The default value is true. This setting enables the automatic reconnection feature.
Set it to false if you do not want the client endpoint to try reconnecting with EnableX.
roomInfo.number_of_attempts: Numeric. The maximum number of attempts made by the client endpoint to reconnect to EnableX. The maximum value is not specified. You can use any random number.
The default value is 3.
The minimum value is 1.
roomInfo.timeout_interval: Numeric. Timeout interval in milliseconds required by the client endpoint to wait before attempting to reconnect.
roomInfo.audio_only: Boolean. Set it to true to join as an audio-only call.
advanceOptions JSON Object Optional with an array of advanced options.
advancedOptions.battery_updates: Boolean. Set it to true to enable the auto-battery update feature.
advanceOptions.notify-video-resolution-change: Boolean. Set it to true to enable the video resolution change notification feature.

Callbacks:

Callback Data Type Description
onRoomConnected JSON Object Acknowledgment to the client endpoint when it is connected to the room.
onRoomError JSON Object Acknowledgment to the client endpoint when it fails to connect to the room.
onUserConnected JSON Object Notification to everyone in a room when a new user is connected to the room.
onRoomAwaited JSON Object Notification to the client endpoint when it awaits the moderator's permission to enter a knock-enabled room or awaits the moderator to enter the room first in a wait-for-moderator enabled room.
The JSON structure of the event provides information on whether the room is knock-enabled { "event_type": "knock" } or wait-for-moderator enabled { "event_type": "wait_for_moderator" }.
onUserAwaited JSON Object Notify the moderator when a user awaits permission to enter the room. For more information, see Moderate a Participant's Entry to a Ssession.

Sample Code

String token = "XXX":
JSONObject roomInfo = {
"allow_recnnect": true,
"number_of_attempts": 3,
"timeout_interval": 10000,
"audio_only": true
}
JSONObject advancedOptions = {
[
{
"id": " battery_updates",
"enable": true,
},
{
"id": " notify-video-resolution-change",
"enable": true,
}
]
}
// Initiates a Room
EnxRoom room = new EnxRoom(this, this, this);
// Connects with Re-Connection & Advance Options
room.connect(token, roomInfo, advanceOptions);
public void onRoomConnected(EnxRoom room, JSONObject roomMetaData) {
// Connected.
//Callback received with room object and Room Meta JSON
}
public void onRoomError(JSONObject roomError) {
// Connection failed. Find error
}
public void onUserConnected(JSONObject userData) {
// Notification to all that a new user is connected.
// userData json has user information
}

Error Codes and Exceptions

CodeDescription
5086Unable to connect to the room.

Join a Room with a Stream

The typical process to connect to a room involves the following steps:

  1. Initiate a room and connect to it.
  2. Initiate streaming after connecting to the room, which requires you to check media accessibility.
  3. Publish a local stream.
  4. Check if the stream is successfully published.

To successfully join a room, you need to ensure the success of each step before proceeding to the next step, thus making it a complex process. The EnxRtc.joinRoom() method allows you to quickly join a room and get started without following every step of this procedure.

Class: EnxRtc

Method: public EnxStream joinRoom(String token, JSONObject publishStreamInfo, JSONObject roomInfo, JSONArray advanceOptions)

Parameters Data Type Description
token String A JWT token to connect to the room. The token is received using the Server API call through the application server.
publishStreamInfo JSON Object Optional. For more information, see Stream Initialization Meta Info.
roomInfo JSON Object roomInfo.allow_reconnect: Boolean. The default value is true. This setting enables the automatic reconnection feature.
Set it to false if you do not want the client endpoint to try reconnecting with EnableX.
roomInfo.number_of_attempts: Numeric. The maximum number of attempts made by the client endpoint to reconnect to EnableX. The maximum value is not specified. You can use any random number.
The default value is 3.
The minimum value is 1.
roomInfo.timeout_interval: Numeric. Timeout interval in millisecond required by the client endpoint to wait before attempting to reconnect.
roomInfo.activeviews: String. Values: list or view.
Set it to view to get a predefined view of all the video streams in a session.
Set it to list to get individual streams to create your own view with the video streams.
roomInfo.forceTurn: Boolean. The default value is false.
Set it to true to force the video streams through the TURN server.
roomInfo.chat_only: Boolean. The default value is false.
Set it to true to allow only text chat in the stream, thus disabling audio/video streams.
roomInfo.playerConfiguration: JSON Object with video player configurations.
  • audiomute: Boolean. The default value is true. This setting shows the audio mute/unmute button.
    Set it to false to hide the audio mute/unmute button.
  • videomute: Boolean. The default value is true. This setting shows the video mute/unmute button.
    Set it to false to hide the video mute/unmute button.
  • bandwidth: Boolean. The default value is true. This setting shows the low bandwidth notification button.
    Set it to false to hide the low bandwidth notification button.
  • screenshot: Boolean. The default value is true. This setting shows the screenshot button.
    Set it to false to hide the screenshot button.
  • avatar: Boolean.The default value is true. This setting shows the avatar for no-video streams.
    Set it to false to hide the avatar for no-video streams.
  • iconColor: String. HEX color code for icons.
    The default value is #FFFFFF
  • iconHeight: Number. Icon height in pixels.
    The default value is 30.
  • iconWidth: Number. Icon width in pixels.
    The default value is 30.
  • avatarHeight: Number. Avatar height in pixels.
    The default value is 200.
  • avatarWidth: Number. Avatar width in pixels.
    The default value is 200.
advanceOptions JSON Object advanceOptions.battery_updates: Boolean. Set it to true to enable auto-battery update feature.
advanceOptions.notify-video-resolution-change: Boolean. Set it to true to enable the video resolution change notification feature.

Returns: JSON object containing the details of the published local stream.

Sample Code

JSONObject publishStreamInfo = {
video: true,
audio: true,
data: true,
attributes: { name: "XX" }
};
JSONObject roomInfo = {
allow_reconnect: true,
number_of_attempts: 3,
timeout_interval: 15,
activeviews: "view",
forceTurn: false,
chat_only: false,
playerConfiguration: {
audiomute: true,
videomute: true,
bandwidth: true,
screenshot: true,
avatar: true,
iconColor: "#FFFFFF",
iconHeight: 30,
iconWidth: 30,
avatarHeight: 200,
avatarWidth: 200
}
};
JSONObject advanceOptions = [
{"id": "notify-video-resolution-change",
"enable": true
}​​​​​,
{​​​​​ "id": "battery_updates",
"enable": true
}
]
String token = "XXX";
EnxRtc enxRtc = new EnxRtc(
Current-Class-Context,
EnxRoomOberver-Instance,
EnxStreamObserver-Instance);
EnxStream localStream = enxRtc.joinRoom(token, publishStreamInfo, roomInfo, advanceOptions);
public void onRoomConnected(EnxRoom room, JSONObject roomMetaData) {
// Connected.
//Callback received with room object and Room Meta JSON
}
public void onRoomError(JSONObject roomError) {
// Connection failed. Find error
}

Disconnect from a Room

The EnxRoom.disconnect() method closes the session and disconnects the client endpoint from the room. The media and signaling sockets are also released in this process.

Class: EnxRoom

Method: public void disconnect()

Observers:

Observer NameDescription
onRoomDisconnectedAcknowledgment to a user when the user is disconnected. The callback allows you to update the UI of the user post disconnection.
onUserDisconnectedNotification to everyone in a room when a user is disconnected from the room. The callback allows you to update the UI of other connected users.

Sample Code

room.disconnect();
public void onRoomDisConnected( JSONObject jsonobject) {
// You are disconnected
}
public void onUserDisconnected( JSONObject userData ) {
// A user is disconnected
// User Information of disconnected user
}

Error Codes and Exceptions

CodeDescription
5031Repeated disconnect() call made while previous disconnection request is in process
5032When the user tries to disconnect after getting disconnected from the room.

Handle Network Disconnection and Reconnection

A client endpoint is connected with EnableX over a secured web socket, which is susceptible to network failures. The client endpoint is notified of the failure through the following callbacks:

Event Notification NameDescription
onConnectionLostNotification to a client endpoint when the endpoint is disconnected.
onConnectionInterruptedNotification to a client endpoint when the connection is interrupted. Fr example, when the connection is switched from WiFi to 4G and vice versa.

Sample Code

public void onConnectionLost(JSONObject json){
// Disconnected. Handle UI
}
public void onConnectionInterrupted(JSONObject json){
// Interrupted. Handle UI
}

EnableX provides the Auto-Reconnection functionality for disconnected endpoints to ensure a better user experience. To use this feature, you must Connect to the Room with Reconnection options. Note that this feature is not applicable under the following circumstances:

  • The last participant has disconnected from the adhoc room.
  • The moderator has dropped the participant from the room.
  • The participant has explicitly disconnected from the room.

Callbacks

Event Notification NameDescription
onUserReconnectSuccessNotification to the user when the client endpoint is successfully reconnected with EnableX.
onReconnectNotification to the user when the client endpoint fails to reconnect within the specified period of time.

Sample Code

//To receive and handle reconnection events,
// you need to pass an argument called roomInfo (its is an optional parameter) while connecting to the room through the room api - joinRoom() or connect(). For example,
JSONObject roomInfo = {
"allow_reconnect": true,
"number_of_attempts": 3,
"timeout_interval": 10000,
"audio_only": false
};
//This will helps the end-point user to auto-reconnect to the same room.
public void onUserReconnectSuccess(EnxRoom room, JSONObject roomMetaData){
// Got reconnected
}
public void onReconnect(String message){
// Reconnecting
}

Error Codes and Exceptions

CodeDecription
5073The connection is switched to the current network.
5074Network disconnected. The reconnection attempt is timed-out.
5086When a method is called while the room is not connected.
5087Reconnection failed.

Video Quality Adaption based on Bandwidth

EnableX offers Automatic Bandwidth Detection (ABWD) to ensure optimum audio or video communication based on the available bandwidth at the client endpoint. The ABWD detects a change in the available bandwidth when it cannot continue to support all the videos being received and notifies the client endpoint with callback onRoomBandwidthAlert. You can handle this event by reducing the number of Active Talker videos received or switching to audio-only mode. It helps users facing deplorable network conditions to go into audio-only mode without disrupting the session.

Callback: onRoomBandwidthAlert

  • Notification is sent to the affected client endpoint when:
    • Bandwidth at the endpoint reduces to a level where all videos being received cannot be supported;
    • Bandwidth at the endpoint increases to a level where more videos than those currently being received can be supported.
  • Notification is not triggered for any bandwidth fluctuation that does not affect the number of videos being received at the client endpoint.

Sample Code

// To receive callback
-public void onRoomBandwidthAlert(JSONObject jsonObject) {
// jsonObject examplel given below
}

onRoomBandwidthAlert JSON Payload:

Data Description
bandwidth Updated (Reduced or Increased) bandwidth at the client endpoint.
number_of_videos Number of videos that can be supported at the available bandwidth.

Sample Code

[
{ "bandwidth": 240,
"stream_bandwidth": 80,
"number_of_videos": 2
}
]