Basic Functions of EnableX Android SDK are used to perform the necessary tasks required to achieve basic Audio/Video communication between participants connected from their endpoints to an EnableX hosted Room. For advanced functionalities, please refer to Advance Features & Moderator Controls.

Table of Contents

Get a list of Audio Devices

You can initiate a Stream using either the browser’s default Audio Device or by specifying the ID of the Audio Device connected to the device running the client application which requires you to get the Device IDs of all the connected devices.   

The EnxRoom.getDevices() method provides a list of all the Microphones connected to your Device. You can also use this method to build UI Element allowing users to choose an Audio Device from the list.

Class: EnxRoom

Method: public List <String> getDevices() – No parameter required.

Returns: List of Devices.

List deviceList = enxRoom.getDevices();

// Returns [SPEAKER_PHONE, WIRED_HEADSET, EARPIECE, BLUETOOTH, NONE ] 

Get selected Audio Device by User

The EnxRoom.getSelectedDevice() method provides the currently selected/in-use Audio Device for the Stream.

Class: EnxRoom

Method: public String getSelectedDevice() – No parameter required.

String selectedDevice = room.getSelectedDevice();

Initiate a Room

An RTC session takes place in a Virtual Room hosted at EnableX and 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 EnxRoom.init() method.

Class: EnxRoom

Method: public void init( Context context )

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

Connect to Room

The EnxRoom.connect() method connects the 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 bi-directional 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 would cause the communication to fail. In such cases, EnableX offers the option to Auto-Reconnect.

Note that Auto-Reconnect is not applicable under the following circumstances:

  • The last participant disconnected from Adhoc Room.
  • The participant is dropped from the Room by the Moderator.
  • The user disconnects explicitly.

Class: EnxRoom

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

Parameters

  • token: String. A JWT Token to connect to the Room as received using Server API Call via Application Server.
  • roomInfo – Optional. JSON Object with Reconnection Options. JSON keys are explained below:
    • allow_reconnect: Boolean. Default: true. Set to true to enable Auto-Reconnect feature. When set to false, the Client endpoint does not try to reconnect to EnableX.
    • number_of_attempts: Numeric. Min Value: 1. Max Value: Not specified, use any number. Default: 3. A maximum number of attempts made by the Client endpoint to reconnect to EnableX.
    • timeout_intervalNumeric. Timeout Interval in Millisecond required by the Client endpoint to wait before attempting to reconnect.
    • audio_only: Boolean. Set to true if you want to join as an audio-only call.
  • advanceOptions – Optional. JSON Object with an array of advanced options. Each element of the array consists of a key-value pair as given below:
    • battery_updates: Boolean. Set to true to enable Auto-Battery Update feature.
    • notify-video-resolution-change: Boolean. Set to true to enable Video Resolution Change Notification feature.

Callbacks:

  • onRoomConnected – Acknowledgment to the Client endpoint when it gets connected to the Room.
  • onRoomError – Acknowledgment to the Client endpoint when it fails to connect to the Room.
  • onUserConnected – Notification to everyone in the Room when a new user is connected to the Room.
  • onRoomAwaited – 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 event’s JSON structure provides information on whether the Room is Knock-enabled { "event_type": "knock" } or Wait-for-Moderator enabled { "event_type": "wait_for_moderator" }.
  • onUserAwaited – Notification to the Moderator when a user awaits their permission to enter the Room. Refer to Moderator Controls for more details.
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 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 / Exceptions:

CodeDescription
5086Unable to connect to Room.

Initiate Local Stream

The EnxRoom.getLocalStream() method is used to initialize a local stream at the Client endpoint before it can be published to the Room. The initialization process comprises specifying media tracks, adding custom attributes, etc. in the form of a JSON object passed as a parameter to the method.

ClassEnxRoom

Methodpublic EnxStream getLocalStream( JSONObject publishStreamInfo )

ParameterspublishStreamInfo - A JSON object with Local Stream Options as given below:

{
     "audio": true,          // Whether to add Audio to stream
     "video": true,          // Whether to add Video to stream
     "data": true,           // Whether to add Data to stream
     "videoSize":  {         // Video Frame Size
           "minWidth": number, 
           "minHeight": number,  
           "maxWidth": number,
           "maxHeight": number
       ), 
     "audioMuted": true,     // Audio muted on entry to room  
     "videoMuted": true,     // Video muted on entry to room  
     "attributes": {         // Object to carry custom data  
         "custom1": ""
      },
      "maxVideoBW": number,  // Max Bandwidth 
      "minVideoBW": number   // Min Bandwidth  
 } 

Error Codes / Exceptions

CodeDescription
5015Failed to initialize the Stream without Audio, Video, and Data track.
5016Failed to initialize the Stream due to incorrect values of JSON Keys in publishStreamInfo.
5017Unable to create Stream due to failure to access Camera and Microphone.
5018Unable to create Video Stream due to failure to access Camera. Only Audio Stream created.
5019Unable to create Stream due to failure to access Microphone.
5084Invalid Video Layer. Max allowed Video Layers: 3
5088Invalid Frame Rate. Max allowed Frame Rate: 30

Initiate Stream with Multiple Video Layers

To help stream subscribers receive the best video quality subject to the available bandwidth, stream publishers must ensure that their streams carry multiple video layers of different quality. The Auto Bandwidth Detection feature detects the subscriber’s bandwidth and switches to the respective video layer for a smooth video experience.

JSONObject streamOpt = {
       audio: true, 
       video: true, 
       maxVideoLayers: 3 // Carry 3 layers, viz HD 720p, SD 480p & LD 240p/180p 
 };

// Enumerated Values for  maxVideoLayers: 1, 2, 3                               
// 1=HD 720p layer only                               
// 2=HD 720p & SD 480p layers only                               
// 3=HD 720p, SD 480p & LD 240p/180p layers 

EnxStream localStream = room.getLocalStream(streamOpt); 

Error Codes / Exceptions

CodeDescription
5084Illegible Value for maxVideoLayers. Max 3 Video Layers supported.

Join a Room with Stream

A typical process to connect to a room is as follows: 

  1. Initiate a room and connect to it. 
  2. Initiate streaming after connecting which requires you to check media accessibility.
  3. Publish 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 thus making it a complex process.

The EnxRtc.joinRoom() method allows you to quickly join a room and get started without having to follow the above procedure step by step.

Class: EnxRtc

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

Parameters:

  • token – String. A JWT Token to connect to the Room as received using Server API Call via Application Server.
  • publishStreamInfo– Optional. Stream Initialization Meta Info.
  • roomInfo – Optional. JSON Object with Reconnection Options. JSON keys are explained below:
    • allow_reconnectBoolean. Default: true. Set to true to enable Auto-Reconnect feature. When set to false, Client endpoint does not try to reconnect to EnableX.
    • number_of_attemptsNumeric. Min Value: 1. Max Value: Not specified, use any number. Default: 3. A maximum number of attempts made by the Client endpoint to reconnect to EnableX.
    • timeout_intervalNumeric. Timeout Interval in Millisecond required by the Client endpoint to wait before attempting to reconnect.
    • activeviews: Enum. Values: list or view. Set to view to get a predefined view of all the video Streams in a session. Set to list to get individual streams to create your own view with the video streams.
    • forceTurn: Boolean. Default: false. If enabled, Video Streams are forced through a TURN Server.
    • chat_only: Boolean. Default: false. Set to true to allow only text-chat in the Stream thus disabling audio/video streams.
    • playerConfiguration: JSON Object with Video Player configurations.
      • audiomute: Boolean. Default: true. Set to true to show and false to hide the Audio Mute/Unmute button.
      • videomute: Boolean. Default: true. Set to true to show and false to hide the Video Mute/Unmute button.
      • bandwidth: Boolean. Default: true. Set to true to show and false hide the Low-Bandwidth notification button.
      • screenshot: Boolean. Default: true. Set to true to show and false to hide the Screenshot button.
      • avatar: Boolean. Default: true. Set true to show and false to hide Avatar for No-Video Stream.
      • iconColor: String. Default: #FFFFFF. HEX color code for icons.
      • iconHeight: Number. Default: 30. Icon height in pixel.
      • iconWidth: Number. Default: 30. Icon width in pixel.
      • avatarHeight: Number. Default: 200. Avatar height in pixel.
      • avatarWidth: Number. Default: 200. Avatar width in pixel.
  • advanceOptions – Optional. JSON Object with an array of advanced options. Each element of the array consists of a key-value pair as given below:
    • battery_updatesBoolean. Set to true to enable Auto-Battery Updates feature.
    • notify-video-resolution-changeBoolean. Set to true to enable Video Resolution Change Notification feature.

Returns: Published Local Stream JSON object.

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 is used to close the session and disconnect the client endpoint from the Room. The media and signaling sockets are also released in this process.  

Class: EnxRoom

Method: public void disconnect() – No parameter required.

Observers:

  • onRoomDisconnected – Acknowledgment to the user when disconnected. The Callback allows you to update the UI of the user post disconnect.
  • onUserDisconnected – Notification to everyone in the Room when a user gets disconnected. The Callback allows you to update the UI of other connected users.
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 / 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.

Publish / Unpublish Local Stream

After initializing the stream, you need to publish it in the room so that the other users in the room can see and hear the user.  The methods to publish, unpublish, and close a local stream are explained in this section.

Publish Local Stream

The EnxRoom.publish() method publishes a local stream in the connected room. 

Class: EnxRoom

Method: public void publish(EnxStream localStream)

Parameters:

  • localStream – Initiated Stream Object

Observers:

  • onPublishedStream – Acknowledgment to the Stream publisher when the stream gets published.
  • onStreamAdded – Notification to everyone in the Room when a new stream is published in the Room.
room.publish(localStream);  // To publish initialized Local Stream

public void onPublishedStream(EnxStream stream) {
     // Your Stream is published
}

public void onStreamAdded(EnxStream stream) {
     // Announcement of a new Stream in the Room
     // You may subscribe to the Stream
}

Error Codes / Exceptions

CodeDescription
5013Failed to publish Stream.
5015Unable to publish a Stream without audio, video, and data.
5016Unable to publish a Stream with illegible attributes.
5022Failed to publish Stream because Floor Access not received in lecture mode room.
5023The Stream has already been published.
5024Repeated publish() call while Stream Publishing is in process.
5025Failed to publish stream because publish() call is made on a Remote Stream.
1170The current subscription doesn’t support the publishing of Stream.

Unpublish Local Stream

The EnxRoom.unpublish() method disconnects the local stream from the room. Unpublishing a stream does not release the device access so that subsequent republishing does not require device-access-permission.  

Class: EnxRoom

Method: public void unpublish() – No Parameter required.

Observers: onRemoveStream - Notification to everyone in the Room when a Stream is removed from the Room.

room.unpublish();  // To unpublish all Local Streams

public void onRemoveStream(EnxStream stream) {
     // To announce in the room that a stream has been removed from the Room.
}

Error Codes / Exceptions

CodeDescription
5029Repeated unpublish() call made while previous unpublish request is in process.
5030Non-Contextual use of method when the user tries to unpublish a stream before publishing it.

Subscribe Remote Streams

The EnxRoom.subscribe() method is used to receive the media stream of other users connected to the Room. You must call this method for each participant’s media stream individually to receive it. 

You don’t need to subscribe to your Local Stream as EnableX facilitates the publisher to receive their own Screen Sharing and Canvas Streaming without explicitly subscribing to it. In short, a user must only subscribe to the Remote Streams in the Room. 

Refer to Handle Active Talkers section below for more details.

Class: EnxRoom

Method: public void subscribe(EnxStream remoteStream)

Parameters:

  • remoteStream – The Stream object that needs to be subscribed.

Observer:

  • onStreamAdded – Notification to everyone in the Room when a new Stream is added in the Room thus informing everyone to subscribe to it to receive it.
  • onSubscribedStream – Acknowledgment to the subscriber when they have subscribed to the Stream successfully.
public void onStreamAdded(EnxStream remoteStream) { // There is a new Stream
	room.subscribe(remoteStream); // Subscribe to it.
}

public void onSubscribedStream(EnxStream stream) {
	// You have subscribed to the Stream.
}

Error Codes / Exceptions

CodeDescription
5014Failed to subscribe to the Stream.
5026Stream has already been subscribed.
5027Repeated subscribe() call made while a previous subscription request is in process.
5028Failed to subscribe because subscribe() call is made on the Local Stream.

Handle Active Talkers

To avoid excessive consumption of the server and client resources, EnableX sends a maximum of 12 actively talking users in the Room to the client endpoint. Additionally, it sends Screen Sharing (StreamID# 101) and Canvas Stream (StreamID# 102) if the client application supports these features. The decision on which of the participant’s streams would be played depends upon the Active Talker List. 

After getting connected to the Room, your Client endpoint will also receive onStreamAdded() callback for all the Streams (as per the max_active_talkers configured during Room Creation) available in the Room. You need to subscribe to each of these Streams along with two extra Streams for Screen-Share and Canvas.

After you connect to the room and subscribe to the available Streams, the active-talkers-updated event is triggered, which creates a new entry in the Active Talker List. This list keeps getting updated depending upon the latest talker in the Room. Hence the Active Talker List contains a list of talkers in ascending order at any point in time which means that the latest talker would be moved up in the list. Therefore, you may expect to receive the event too frequently in a noisy room. The list of Active Talkers is available in JSON format and sent through Callback onActiveTalkerList() to each connected endpoint whenever there is a change in the Active Talker List if activeviews : list during joinRoom(). If activeviews: view then onActiveTalkerList() is called only once after joining the Room and subscribing to the Active Talker List.

Apart from the activity level, EnableX also allows pinning of user streams in the Active Talker List regardless of their activity level in the Room. So, the Active Talkers List consists of the inactive pinned users and active talkers in ascending order.  

It must also be noted that the Active Talkers List contains Remote Streams only and hence the Active Talkers List varies for each participant in the Room. 

Observer:

  • setActiveTalkerListObserver – This observer needs to be used when activeviews is set to "list” in the roomInfo parameter in joinRoom() method.
  • setActiveTalkerViewObserver – This observer needs to be used when activeviews is set to "view” in the roomInfo parameter in joinRoom() method.

Playing Active Talker Streams with a Customized View

You can choose to create your custom view for displaying the Remote Streams out of the Active Talker List by selecting activeviews : list during joinRoom(). To play a stream out of the Active Talker List, you need to fetch every Stream’s player (EnxPlayerView) from the list and attach it to your chosen UI.

Class: EnxRooom

Callback: onActiveTalkerList(List enxStreamList) 

Parameter:

enxStreamList – List of Streams received at the endpoint.

enxRoom.setActiveTalkerListObserver(this); // Called after getting connected to the Room

@Override

public void onActiveTalkerList(List<EnxStream> enxStreamList) {
     for(int i = 0 ; i <=enxStreamList.size();i++) {
	EnxPlayerView enxPlayerView = enxStreamList.get(i).mEnxPlayerView;
	yourview.addView(enxPlayerView);
     }
}

Playing Active Talker Streams with predefined Recycler View

You can also choose to play the Remote Streams in the Active Talker List with a custom-defined Recycler View by selecting activeviews : view during joinRoom(). In this case, you don’t have to handle the UI as the pre-defined Video Grid plays all the Streams received at the Client endpoint.

When choosing this option, you can use adjustLayout() method to adjust the Video player layout to fit within its parent view. This method helps when the user rotates the screen or when the view needs to be adjusted to fit properly.

Class: EnxRoom

Callback: onActiveTalkerList(RecyclerView recyclerView) 

Parameter:

recyclerView – Recycle View

Method: public void adjustLayout() – No Parameter required.

enxRoom.setActiveTalkerViewObserver(this); // Called after getting connected to the Room

@Override

public void onActiveTalkerList(RecyclerView recyclerView) {
	yourRemoteView.addView(recyclerView);
}
room.adjustLayout();

Note: The Local Stream will not be included in the RecycleView even if the endpoint is talking as Local Stream is not present in the Active Talker List.

Get maximum permissible Talker Count

The EnxRoom.getMaxTalkers() method provides the maximum active talkers allowed for the Room as per max_active_talkers configuration during Room Creation. This count could be of interest to the user if they choose to receive less active talkers in the Room. By default, the max_active_talkers is restricted to 12. 

Class: EnxRoom

Method: public void getMaxTalkers() – No Parameter required.

Observer: public void setTalkerObserver( EnxTalkerObserver Object )

Callback: onMaxTalkerCount()

// Initiate Talker Observer to receive Callbacks
room.setTalkerObserver(this);

room.getMaxTalkers();

public void onMaxTalkerCount(JSONObject jsonobject) {
     // Talker info in response jsonobject:
     // {"result": 0, "maxTalkers": 4} 
}

Set Talker Count

The EnxRoom.setTalkerCount() method is used to set the number of active talkers in the Active Talkers List to a particular value not exceeding the maximum permissible talker count. This could either be ingrained at the application level or be implemented as a UI feature where the end-user has the flexibility to control the number of remote streams they want to receive.  This method allows you to control how many Streams you would like to receive. 

Class: EnxRoom

Method: public void setTalkerCount(int numTalkers)

ParametersnumTalkers – The Number of Talker Streams you want to receive. Range limited by max_active_talkers, typically 0-12

  • If you set numTalkers to any value from 1 to 12, you receive those many talkers in the Active Talker List.
  • If you set numTalkers to 0 (zero), then the list doesn’t become empty, it carries 3 audio streams and no video Streams.

Observer: public void setTalkerObserver( EnxTalkerObserver Object )

Callback: onSetTalkerCount()

// Initiate Talker Observer to receive Callbacks
room.setTalkerObserver(this); 

int numTalkers = 5;
room.setTalkerCount(numTalkers);

public void onSetTalkerCount(JSONObject jsonobject) {
     // Talker info in response jsonobject:
     // {"result": 0, "maxTalkers": 4} 
}

Error Codes / Exceptions

CodeDescription
5055Repeated setTalkerCount () call made while a previous request is in process.

Get Talker Count

The EnxRoom.getTalkerCount() method provides you the number of active talkers to be received through onActiveTalkerList() callback. The method returns the number of currently active streams in the Room restricted either by the maximum permissible talker count or by the set talker count API when invoked by the application or the user through UI.  

Class: EnxRoom

Method: public void getTalkerCount() – No Parameter required.

Observer: public void setTalkerObserver( EnxTalkerObserver Object )

Callback: onGetTalkerCount()

 // Initiate Talker Observer to receive Callbacks
room.setTalkerObserver(this); 

room.getTalkerCount();

public void onGetTalkerCount(JSONObject jsonobject) {
     // Talker info in response jsonobject
     // { "result": 0, "numTalkers": 4 } 
}

Note: The Observer setTalkerObserver() needs to be initiated only once for any one or all of these method calls to receive callbacks.

Handle Disconnection & Reconnection

A Client endpoint is connected with EnableX over Secured Web Socket, which is susceptible to network failures. The Client endpoint is notified of the failure through the following Callbacks:

Callbacks:

  • onConnectionLost – Notification to the Client endpoint when the endpoint loses network connection.
  • onConnectionInterrupted – Notification to the Client endpoint when the connection is interrupted e.g Switch from WiFi to 4G and vice versa.
public void onConnectionLost(JSONObject json){
	// Disconnected. Handle UI 
} 

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

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

  1. The last participant disconnected from Adhoc Room.
  2. The participant is dropped from the Room by the Moderator.
  3. The user disconnects explicitly.

Callbacks:

  • onUserReconnectSuccess – Notification to the user when the Client endpoint successfully gets reconnected with EnableX.
  • onReconnect – Notification to the user when the Client endpoint attempts to reconnect within the given time period.
JSONObject jsonobject reconnectInfo = { // Reconnect Options
    "allow_reconnect": true,
    "number_of_attempts": 3,
    "timeout_interval": 10000,
    "audio_only": false
}; 

room.connect(String token, JSONObject reconnectInfo, JSONObject advOptions)

public void onUserReconnectSuccess(EnxRoom room, JSONObject roomMetaData){
 // Got reconnected
}

public void onReconnect(String message){
 // Reconnecting 
}

Error Codes / Exceptions

CodeDescription
5073Connection is switched to the current network.
5074Network disconnected. Reconnection attempt timed-out.
5086When any method is called while the Room is not connected.
5087Reconnection failed.

Play Stream

You can play a local stream and all subscribed remote streams including screen-share, canvas streams within EnxPlayerView Object. Therefore, you need to create an Object of EnxPlayerView Class and then attach the Stream to Player View using EnxStream.attachRenderer() method.

To stop playing a Stream, detach the Stream from PlayerView using EnxStream.detachRenderer().

Class:

  • EnxPlayerView – To initiate a Player View object.
  • EnxStream – To attach the Stream to the Player View.

Method: To play Stream

  • public void attachRenderer( EnxPlayerView playerView)

Parameter: playerView – A Player View Object

Method: To stop playing Stream

  • public void detachRenderer() – No Parameter required.
EnxPlayerView playerView = new EnxPlayerView(
 Current-Class-Context, ScalingType, mediaOverlay);

stream.attachRenderer(playerView);  // Attach stream to playerview to play
yourCustomView.addView(playerView); // Add playerView to your view 

stream.detachRenderer();            // Detach Renderer to stop playing 

Know Stream Information

The following methods provide Stream-related information such as the Stream type, media tracks, state, etc.

Get Stream ID

The EnxStream.getId() method provides the ID of the given Stream. The Stream ID is used to identify every Stream, be it a local or a remote stream, a canvas stream, or a screen-share stream.

Class: EnxStream

Method: public String getID()

Returns: String stream Id

 String streamID = stream.getId();

Get Stream Attributes

The EnxStream.getAttributes() method provides the Stream attributes that are defined in the JSON Payload during the Stream Initialization process.

var StreamOpt = {
    "attributes": {
        "name": "Stream Name",
        "custom_key": "String",
        "custom_key2": Number
     }
}

Class: EnxStream

Method: public JSONObject getAttributes() – No Parameter required.

Returns: Stream attributes JSON object.

JSONObject attributes = stream.getAttributes();

Verify availability of Media Tracks in Stream

The EnxStream class provides the following methods to check the presence of a particular media track in the Stream.

Class: EnxStream

Methods:

  • To check if Stream has an Audio Track:
    • public boolean hasAudio() – No Parameter required.
  • To check if Stream has a Video Track:
    • public boolean hasVideo() – No Parameter required.
  • To check if Stream has a Data Track:
    • public boolean hasData() – No Parameter required.
  • To check if Stream has Screen-share:
    • public boolean hasScreen() – No Parameter required.

Returns: Boolean

if (stream.hasVideo()) {
     // If the Stream has a Video Track in it.
}

// Other methods are also used in the similar manner.

Check Audio/Video Track Status in Stream

The EnxStream class provides the following methods to verify if the current status of Audio or Video Track in a Stream is active.

Class: EnxStream

Methods:

  • To know if Audio Track is currently active:
    • public boolean isAudioActive() – No Parameter required.
  • To know if Video Track is currently active:
    • public boolean isVideoActive() – No parameter required.

Returns: Boolean

if (stream.isAudioActive()) {
      // If the Audio track is active in the Stream
}

if (stream.isVideoActive()) {
      // If the Video track is active in the Stream
}

Know if Stream is Local or Remote

The EnxStream.ifLocal() method is used to know if the given Stream is a Local or a Remote Stream. It returns true for a Local Stream and false for a Remote Stream.

Class: EnxStream

Method: public boolean ifLocal() – No parameter required.

Returns: Boolean

if (stream.ifLocal()) {
     // It's a Local Stream
 }
 else {
     // It's a  Remote Stream
 }

Know current state of Stream

The EnxStream.getState() method is used to know the current state of the given Stream. It returns String Constants as listed below.

Class: EnxStream

Method: public String getState() – No parameter required.

Returns: One of the following String Constants:

  • UNKNOWN
  • OPENING
  • ACTIVE
  • CLOSING
  • DESTROYED
  • LOCAL
  • BLOCKED
String currentState = stream.getState();

Get Media of a Stream

The EnxStream.getMedia() method provides the Media Stream Object present in the given Stream.

Class: EnxStream

Method: public MediaStream getMedia() – No Parameter required.

Returns: Media Stream object

MediaStream mStream = stream.getMedia(); 

Know Room Information

The EnxRoom Class provides the following methods to access various room-related information.

Get Room ID

The EnxRoom.getRoomId() method provides the ID of the Room you are connected to. The Room ID is assigned to each Room during Room Creation.

Class: EnxRoom

Method: public String getRoomId() – No parameter required.

Returns: String Room ID.

String roomID = room.getRoomId(); 

Get Room Meta Information

The EnxRoom.getRoomMetaData() method provides the Meta Information of the Room to which you are connected. The Room Meta information JSON payload contains the complete Room definition along with many run-time parameters with their current values and room-stats of connected users and streams. All the endpoints receive this information through onRoomConnected observer after getting connected to the Room. Some of the run-time parameters are updated internally by the SDK on various events.

Class: EnxRoom

Method: public JSONObject getRoomMetaData() – No parameter needed

Returns: Room Meta Information JSON object

JSONObject roomMeta = getRoomMetaData();

Get Room Mode

The EnxRoom.getMode() method provides the mode in which the Room operates – group mode or lecture mode.

Class: EnxRoom

Method: public String getMode()

Returns: Enumerated Values: group, lecture.

String mode = room.getMode();

Get Client ID of the connected User

The EnxRoom.getClientId() method provides the Client ID of the connected endpoint. The Client ID is unique for each user connected to the Room for the session.

Class: EnxRoom

Method: public String getClientId() – No parameter required.

Returns: String Client ID

String clientId = room.getClientId(); 

Get Name of the connected User

The EnxRoom.getClientName() method provides the name of the user connected through the Client endpoint.

Class: EnxRoom

Method: public String getClientName() – No parameter required.

Returns: String Client name.

String clientName = room.getClientName(); 

Get Role of the connected User

The EnxRoom.getRole() method provides the role of the user connected to the Room for the session, either Moderator or Participant.

Class: EnxRoom

Method: public String getRole() – No parameter required.

Returns: Enumerated Values: moderator, participant.

String role = room.getRole();

Get Information of the connected User

The EnxRoom.whoami() method provides the complete User Meta Information of the connected user.

Class: EnxRoom

Method: public JSONObject whoami() – No parameter required.

Returns: User Meta Information JSON object.

JSONObject myinfo = room.whoami(); 

Get List of connected Users

The EnxRoom.getUserList() method provides a list of users connected to the Room.

Class: EnxRoom

Method: public JSONObject getUserList() – No parameter required.

Returns: User list JSON object.

JSONObject Users = room.getUserList()

// Return JSON Users
/*
[
      {
          "clientId": "",             // Unique Client ID assigned by EnableX
          "name": "",                 // User's name
          "user_ref": "",             // User's Reference
          "role": "participant",      // Enum: moderator, participant
          "permissions": {            // In-Session Permission of User
          "publish": Boolean,         // Whether user can pubish a local stream
          "subscribe": Boolean,       // Whether user can subscribe to remote streams
          "record": Boolean,          // Whether user can initiate recording
          "stats": Boolean,           // Whether user can view stream status
          "controlhandlers": Boolean  
          }
      }
  ] 
*/

Get Local Stream ID

The EnxRoom.getLocalStreamID() method provides the ID of your Local Stream published in the Room.

Class: EnxRoom

Method: public String getLocalStreamID() – No parameter required.

Returns: String Stream ID.

 String localStreamID = room.getLocalStreamId(); 

Get Stream by Stream ID

The EnxRoom.getStreamByStreamId() method provides the Stream information for the given Stream ID.

Class: EnxRoom

Method: public EnxStream getStreamByStreamId( String StreamId)

Returns: Stream Information JSON object.

EnxStream stream = room.getStreamByStreamId( StreamID );

Get list of Remote Streams

The EnxRoom.getRemoteStreams() method provides the list of Remote Streams available in the Room.

Class: EnxRoom

Method: public Map < String, EnxStream > getRemoteStreams() – No parameter required.

Returns: Map Remote Streams.

Map <String, EnxStream> remoteStreams = room.getRemoteStreams();

Get Publish Status of Local Stream

The EnxRoom.isPublishing() method is used to check if the Local Stream is currently being published into the Room.

Class: EnxRoom

Method: public boolean isPublishing() – No parameter required.

Result: Boolean.

if (room.isPublishing()) {
   // Local Stream is being published.
}
else {
   // Local Stream is not being published.
}

Explore Android SDK