Basic Functions of EnableX Web 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 more advanced use cases, please refer to Advance Features & Moderator Controls.

Table of Contents

Get list of Audio, Video and Speaker 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.

Method: EnxRtc.getDevices(Callback)

Returns: List of Devices

EnxRtc.getDevices( function(response) { 
     if( response.result === 0 ) {   // success                     
         /* Device Lists in response.devices */ 
         var camList =  response.devices.cam; 
         var micList =  response.devices.mic; 
	 var speakerList = response.devices.speaker;
     }
     else if(response.result === 1144){ // Error case  
       
     }
 });

Response JSON

{
     "result": 0,       
     "devices": { 
             "cam":[ 
                 { 
                 "deviceId": "", 
                 "groupId": "", 
                 "label": "" , 
                 "kind" : "" 
                 } 
             ], 
             "mic": [ 
                 { 
                 "deviceId": "", 
                 "groupId": "", 
                 "label": "" , 
                 "kind" : "" 
                 } 
             ],
	     "speaker": [ 
                 { 
                 "deviceId": "", 
                 "groupId": "", 
                 "label": "" , 
                 "kind" : "" 
                 } 
             ] 
         } 
 } 

Error Codes / Exceptions

Initiate a Room

An RTC session takes place in a Virtual Room hosted at EnableX and the Web SDK allows the Client endpoint application to connect to it. The process starts with initializing a Room Object using the EnxRoom Class.

To initialize a Room, you need to pass a token that is created using Create Room Server API and an optional Speaker ID to play the Video.

var room = EnxRtc.EnxRoom({token:'xxxx', speakerId: 'SPEAKER_ID' });

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: EnxRoom.connect(ReConnectOpt)

Parameters:

ReConnectOpt – 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_interval: Numeric. Timeout Interval in Millisecond required by the Client endpoint to wait before attempting to reconnect.

Event Notifications:

  • room-connected – Acknowledgment to the Client endpoint when it gets connected to the Room with complete run-time Meta Information of the Room. However, if the Room is knock-enabled or requires Moderator to join first, the user needs to wait till they are allowed to join the Session.
  • room-error – Acknowledgment to the Client endpoint when it fails to connect to the Room.
  • user-connected – Notification to everyone in the Room when a new user is connected to the Room.
  • user-awaited – Notification to the Moderator when a user awaits their permission to enter the Room. Refer to Moderator Controls.
  • room-allowed – Notification to the user when they are allowed to join the session after waiting in a knock-enabled or wait-for-moderator enabled Room.
  • active-talkers-updated – Notification to the Client Endpoint with list of Talkers after receiving room-connected event. Refer how to handle Active Talkers
var initOpt = { "token": "XXX" };
var room = EnxRtc.EnxRoom(initOpt); // Initiates Room 

var reConnectOpt = {
    "allow_reconnect": true,
    "number_of_attempts": 3,
    "timeout_interval": 10000
};

room.connect( reConnectOpt, function() {
	if (success && success != null) {
		if (room.waitRoom && room.me.role != "moderator") {
			// Wait for Moderator
		}
	}
});

/*
// Alternate Connection 
room.connect();    // Connects with Default Re-Connection Option
room.connect({})   // Connects with Default Re-Connection Option 
room.connect({"allow_recnnect": false})   // Connects  without Re-Connection feature 
*/

room.addEventListener("room-connected", function(event) {
     // Connected. event receives Room Meta JSON
});

room.addEventListener("room-error", function(error) {
     // Connection failed. Find error
});
 
room.addEventListener("room-allowed", function(event) {
	// User is allowed into the room after being awaited
});

room.addEventListener("user-connected", function(event, user) {
     // A new user connected. user JSON has user information
});

room.addEventListener("user-awaited", function(event, user) {
     // A new user awaited permission to get connected
     // user JSON has user information
});

room.addEventListener("active-talkers-updated", function(event) {
     // List of talkers in the Room
     // Received after room-connected
});

Error Codes / Exceptions

CodeDescription
1130Wait for Moderator to join first.
1171Room not connected.
1172Failed to connect to the Room.

Initiate Local Stream

To initialize a local Stream before you can publish it in the Room, instantiate the EnxStream Class that is a sub-class of EnxRtc Class using the EnxStream Constructor. A JSON Object consisting of Stream attributes such as media source specification and custom attributes is passed as a parameter to the constructor.

Method: EnxRtc.EnxStream(StreamOpt)

Parameters:

StreamOpt – A JSON Object with 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
     "screen": false,        // Whether to add Screen Share to stream
     "audioMuted": true,     // Audio muted on entry to room  
     "videoMuted": true,     // Video muted on entry to room  
     "attributes": {         // Object to carry custom data  
         "custom1": ""
     },
     "options": {}           // Video Player Options */
     "videoSize": [minWidth, minHeight, maxWidth, maxHeight],
     "maxVideoLayers": Number // Number of Video Layers in Stream
                              // Enumerated Values: 1, 2, 3
                              // 1=HD 720p layer only
                              // 2=HD 720p & SD 480p layers only
                              // 3=HD 720p, SD 480p & LD 240p/180p layers
                                     
 } 

Initiate Stream with Default Devices

To initiate a stream with audio, video using default media devices and data tracks, set the respective keys in the JSON Payload to true. You can also provide custom keys within attributes to define additional information for the Stream to carry.

var streamOpt = {
     audio: true, 
     video: true, 
     data: true, 
     attributes: { name:'My-Stream-Name' }
 };

 var localStream = EnxRtc.EnxStream( streamOpt );

Initiate Stream with specific 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.

 var streamOpt = {
     audio: {deviceId: "XXX"}, 
     video: {deviceId: "XXX"}, 
     data: true, 
     attributes: { name:'My-Stream-Name' }
 };

 var localStream = EnxRtc.EnxStream( streamOpt ); 

When the Client Application is used in Mobile browser, it generally starts video stream using Rear Camera. To use the Front Camera instead of Rear Camera, use facingMode: 'user'. To use Rear Camera, use facingMode: 'environment'.

var streamOpt = {
     audio: {deviceId: 'XXX'}, 
     video: {facingMode: 'user'}, 
     data: true, 
     attributes: { name:'My-Stream-Name' }
 };

 var localStream = EnxRtc.EnxStream( streamOpt );

Handle Device Access for Audio / Video Stream

The audio/video stream initiation process requires access to the Microphone and the Camera to act as a source for the stream. The browser thus prompts the user to grant access to the application for one or both the devices (as applicable). The user must allow access for successful initiation of the stream. 

Event Listeners:

  • media-access-allowed – When the user grants permission to the application to access the media devices. 
  • media-access-denied – When the user denies permission to the application to access the media devices. 
stream.addEventListner('media-access-allowed', function (response) {
	/* response = {
		stream: StreamObject,
		type: "media-access-allowed"
	}*/
});

stream.addEventListner('media-access-denied', function (response) {
	/* response = { type: 'media-access-denied', msg: err }*/
});

Initiate Stream with Local File & Remote URL

You can also initiate a stream using Remote URL or Local File Path to a .mkv file.

var streamOpt = {
      audio: true, 
      video: true, 
      url:"rtsp://FQDN/video-resource-path"
 };

var streamOpt = {
      audio: true, 
      video: true, 
      url:"file://video-file-path"
 };

var localStream = EnxRtc.EnxStream( streamOpt );

Initiate Stream with Screen Share

Screen Share on Chrome browser is supported by Chrome extension. Even though EnableX SDK uses its own extension by default, you can specify a different Extension ID to start screen sharing on Chrome.

var streamOpt = {
      screen: true, 
      data: true, 
      desktopStreamId:'EXTENSION_ID'
};

var screenStream = EnxRtc.EnxStream( streamOpt );

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.

var 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 

var screenStream = EnxRtc.EnxStream( streamOpt );

Join a Room without or 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: EnxRtc.joinRoom( Token, StreamOpt, Callback, ReConnectOpt )

Parameters:

  • Token – String. A JWT Token to connect to the Room as received using Server API Call via Application Server.
  • StreamOpt Stream Initialization Meta Info. Optional. If you don’t want to publish your local Stream, pass blank JSON object i.e { }.
  • ReConnectOpt – 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, 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_interval: Numeric. Timeout Interval in Millisecond required by the Client endpoint to wait before attempting to reconnect.

Returns: Published Local Stream JSON Object

var VideoSize = {
     "HD": [320, 180, 1280, 720], 
     "SD": [320, 180, 640, 480],
     "LD": [80, 45, 640, 360]
};

var StreamOpt = {
         video: true,
         audio: true,
         data: true,
         videoSize: VideoSize.HD,
         attributes: { name: "XX" }
};

var reConnectOpt = {
    "allow_recnnect": true,
    "number_of_attempts": 3,
    "timeout_interval": 10000
}; 

localStream = EnxRtc.joinRoom(Token, StreamOpt, function (success, error) {
     if (error && error != null) {
         // Look for error.type and error.msg.name to handle Exception
         if(error.type == "media-access-denied") {
              // Media Media Inaccessibility
         }
     }
    
     if (success && success != null) { 
		room = success.room;
		if (room.waitRoom && room.me.role != "moderator") {
			// Wait for Moderator
		} else {
			remoteStreams = success.room.streams; 
		}
     }
 },
 reConnectOpt
)

Error Codes / Exceptions

CodeDescription
1000Unsupported browser.
1142OverconstrainedError: Invalid Device Id.
1130Moderator not present/Wait for Moderator.
1144NotAllowedError: The request is not allowed by the user agent or the platform in the current context.
1145NotReadableError: Could not start video source.
1146TypeError: At least one of the audio and video must be requested.
1149One of the constraints (Height, Width, Device Id) is not satisfied.
1153Non-supported browser.
1152Only Audio-only calls are allowed with your current browser version.
1170Feature is not supported under current Service subscription or not enabled in the Room’s setting.
1171Room not connected.
1172Failed to connect Room.
1176Moderator declined right to control media devices.

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.  

ClassEnxRoom

Method: EnxRoom.disconnect() – No parameter required.

Notification Events:

  • room-disconnected – Acknowledgment to the user when disconnected. The Callback allows you to update the UI of the user post disconnect.
  • user-disconnected – 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();

room.addEventListener("room-disconnected", function(event) {
     // You are disconnected
});

room.addEventListener("user-disconnected", function(event) {
     // One user is disconnected
     // event - User Information of disconnected user
 });

Error Codes / Exceptions:

CodeReason
2001Disconnected by Moderator.
2002Unexpected disconnection.
2003Conference expired.
2004Network failure.
2005Media handshake failure.
2006Room access denied.

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. 

Method: EnxRoom.publish(LocalStream, PublishOpt, Callback)

Parameters:

  • LocalStream – Initiated Stream Object.
  • PublishOpt – Configurable options for publishing.

Notification Events:

  • stream-added – Notification to everyone in the Room when a new stream is published in the Room.
  • stream-failed – Notification to the Stream publisher when stream publishing fails.
// Configure Optional Publishing Options
var PublishOpt = {
     "minVideoBW":"Number",  
     "maxVideoBW": "Number" 
};

room.publish(localStream, PublishOpt, function(StreamId) {
});

// New Stream in Room Notification
room.addEventListener("stream-added", function(event) {
     if (localStream.getID() === event.stream.getID()) {
         // Your stream published
     } else {
         // Someone else has published
     }
});

room.addEventListener("stream-failed", function(event) {
     // Failed to publish
});

Error Codes / Exceptions

CodeDescription
1170The feature is not enabled because of room configuration or lack of license.

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.  

Method: EnxRoom.unpublish(localStream, Callback)

Parameters:

localStream – Local Stream Object to be unpublished.

Notification:

stream-removed – Notification to everyone in the Room when a Stream is removed from the Room.

room.unpublish(localStream, function(result, error) {
    if (result === undefined) {
        // Failed       
     } else {
        // Unpublished      
     }  
});  

Close Local Stream

The EnxStream.close() method allows you to disconnect the local Stream from the Room similar to the unpublishing process. Closing the Stream leads to the following:

  • If stream has audio and video tracks, it stops capturing media stream from camera & microphone.
  • If the stream is published into the room, it unpublishes the stream.
  • If the stream is being played in Player, it stops playing.

Class: EnxStream

Method: EnxStream.close()

localStream.close();

Subscribe / Unsubscribe Remote Streams

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

After being connected to the Room, the client application can access the list of streams in the Room through the Room Meta Information ie. { streams: [] } and call the EnxRoom.subscribe() on each stream. The user can subscribe to a maximum of 12 active talkers in the room, one stream for screen sharing (StreamID# 11), and one stream for canvas streaming (StreamID# 21) if the client application supports screen sharing or canvas streaming. This means that the user can see a maximum 12 participants on the UI and these participants keep getting updated as per their activity in the Room. This is further explained in the Handle Active Talkers section.

The user does not need to subscribe to their local stream and EnableX also 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 remote streams in the room. 

Method: EnxRoom.subscribe(RemoteStream, SubsOptions, Callback)

Parameters:

  • RemoteStream – The Stream object that needs to be subscribed/received.
  • SubsOptions – Lists configurable stream subscription options as given below: 
    • audio – Boolean. Set to true to subscribe to Audio of the Stream.
    • video – Boolean. Set to true to subscribe to Video of the Stream.
    • data – Boolean. Set to true to subscribe to Data of the Stream.

Event Notification:

  • stream-subscribed – Acknowledgment to the subscriber when they have subscribed to the Stream successfully.
var subsOptiions = {
    audio: true,
    video: true,
    data: true
};

// Subscribe to all Streams in Room Metaa
for (var i = 0; i < success.streams.length; i++) {
    room.subscribe(success.streams[i],  subsOptiions  );  
}  

room.addEventListener("stream-subscribed", function(event) {
    // Stream subscribed
});  

Handle Active Talkers

During a multi-party video conference, more server and Client-End-Point resources are consumed. Therefore, EnableX sends only 6 streams of users actively talking (generating sound) in the Room to each end-point. Additionally, it sends 2 streams, viz. Screen Share (Stream# 101) and Canvas Stream (Stream# 102).

The list of Active-Talkers is available in JSON format along with an event active-talkers-updated whenever there is a change in the talkers list. The list of Active Talkers comprises list will have talkers in ascending order i.e. latest talker will be listed first. Therefore, you may expect to receive the event too frequently in a noisy room.

EnableX v1.8 introduces pinning of user-streams that forces pinned users also in the Active Talkers List irrespective they are talking or not. So, active talkers appear first in the list and then pinned non-talkers. All the pinned users are shown with pinned: true in the Active Talkers JSON.

Event Notifications: active-talkers-updated

Active Talkers List JSON

{    "active" : true,
      "activeList": [
           {   "clientId" : "String", 
               "mediatype" : "audiovideo", // Enum: audiovideo, audioonly
               "name" : "String",
               "reason" : "user",
               "streamId" : Number,
               "videoaspectratio" : "16:9", 
               "videomuted" : Boolean,
               "pinned" : Boolean
           }
       ]
   }

This Active Talkers JSON is used for managing the UI and to play audio/video streams from remote users. To play a specific stream, you need the  Remote Stream object from room.remoteStreams related to the streamId of a Talker. Please remember before you can play any stream from the Active Talkers list, you should have subscribed to all “dummy” streams available in the Room’s meta information i.e room.streams.

room.addEventListener('active-talkers-updated', function (event) {
       TalkerList = event.message.activeList;
       for (var i = 0; i < TalkerList.length; i++) {
           if (ATUserList[i] && ATUserList[i].streamId) {
               var stream  = room.remoteStreams.get(ATUserList[i].streamId);
               var stream_id   = ATUserList[i].streamId;
               var username    = ATUserList[i].name;
               stream.play("DOM_ELEMENT_ID", PlayerOptions);
           }
       }                       
 }

Note: The local Stream will not  be included in the Active Talkers JSON list sent to an End-Point even if the End Point is talking. Hence the Active Talker JSON list sent to different End Points varies. In case you need to play own stream, please use the local stream.

Get Talker Count

It may be necessary to know how many talkers are expected to receive with active-talkers-updated event, i.e. to know either the preset value of talkers or any custom value in effect which is either by the Application Developer or opted by End-Point User.

Method: EnxRoom.getTalkerCount( Callback ) – returns max. Talker Count effective at the End Point

room.getTalkerCount( function(response) {
     // Talker info in response JSON:
     // { "result": 0, "maxTalkers": 4 } 
});

Set Talker Count

EnableX sets a maximum of 6 active talkers in the active talker-list with active-talkers-updated event. However, you may opt to receive less talkers at a Client End Point if you so require. This may either be a predefined value, or this value may be set at run-time in a connected session. If needed, you can create UI for the connected user to opt for number of active-talkers the user wants to receive.

Method: EnxRoom.setTalkerCount(numTalkers, Callback )

Parameters: numTalkers – No. of talkers you want to receive. Range 0-6

  • If you set numTalkers to any value from 1 to 6 – you will receive those many talkers in the list.
  • If you set numTalkers to 0 (zero), then list doesn’t become empty. Rather, you would start receiving 3 audio streams only. Video Streams will not be carried.
room.setTalkerCount(5, function(response) {
     // Set Talker info in response JSON:
     // { "result": 0, "maxTalkers": 5 } 
 });

Error Codes / Exceptions

CodeDescription
4106Failed to set our of range Talker Count. Valid range: 1-12

Get Maximum Allowed Talker Count

It may be necessary to know how many maximum talkers allowed in the room to which the end-point is connected. The End-Point may opt to receive less active talkers than the allowed number of talkers.

MethodEnxRoom.getMaxTalkers( Callback ) – returns maximum number of talkers allowed in the Room

room.getMaxTalkers( function(response) {
     // Maximum Talker info in response JSON:
     // { "result": 0, "maxTalkers": 6 } 
});

Handle Network Disconnection & Re-Connection

A Client End Point is connected with EnableX over Secured Web Socket. A connected End Point might get disconnected from EnableX due to network issues. The End Point gets notified with an event network-disconnected.

Event Notification: network-disconnected – when End Point gets disconnected.

room.addEventListener('network-disconnected', function(event){ 
      // Handle UI or prompt user. 
});

For disconnected end-points, EnableX supports Auto Re-connection to the Session ensuring better user experience. To use Automatic Re-Connection feature, you must initiate the Connection with Room with Re-Connection options. Note that Auto-Re-Connect doesn’t work when:

  • Last Participant disconnected from Adhoc Room
  • User is dropped from Room by Moderator
  • User disconnects explicitly using EnxRoom.disconnect() method

Event Notifications:

  • network-reconnected – When End-Point successfully gets reconnected with EnableX
  • network-reconnect-timeout – When End-Point fails to reconnect within specified time period
  • network-reconnect-failed – When End-Point fails to reconnect for other reasons
var reConnectOpt = {              // Re-Connect Options
    "allow_reconnect": true,
    "number_of_attempts": 3,
    "timeout_interval": 10000
}; 

room.connect( reConnectOpt ); 

room.addEventListener('network-reconnected', function(event){
     // Got reconnected
});
 
room.addEventListener('network-reconnect-timeout', function(event){  
     // Re-Connect Attempt timed-out 
});

room.addEventListener('network-reconnect-failed', function(event){
     // Re-Connect Attempt failed 
});

Error Codes / Exceptions

CodeDescription
1163Network disconnected. Socket or media connection has failed due to network error
1164Network reconnected
1165Time-Out. All re-attempts failed to reconnect Room
1167Failed to publish and subscribe streams after re-connection
1178Reconnection is not allowed for a single participant in the room
4118Reconnect failed because room has been deleted

Play Stream

You can play a local stream, all subscribed remote streams including screen-share, canvas streams within HTML5 Video Player.

Please use EnxStream.play() method to play a stream in a HTML5 audio or video player within HTML DOM. The method will create related audio/video HTML tag within the given HTML DOM Element ID to play the video or audio. Player Optional JSON parameter makes it easy to configure Player.

Method: EnxStream.play(DOMElementID, PlayerOpt)

Parameters:

  • DOMElementID – DIV Id in which Player will be drawn
  • PlayerOpt Refer Appendix for complete list
// Configure Desired Player Options
var PlayerOpt = {
     player: {
         'height': '150px',
         'width': '100%',
         'minHeight': 'inherit',
         'minWidth': 'inherit'
     },
     toolbar: {
         displayMode: false,
         branding: {
             display: false
         }
     }
 };

stream.play("PlayerDiv",  PlayerOpt);

Stop Playing Video

You can stop playing Audio Video Stream in the HTML5 player by using EnxRtc.stop() method.

Method: EnxStream.stop() – No parameter

stream.stop();

Know Stream Information

EnableX API provides different methods to access stream information.

Get Stream ID

Every Stream is identified by its Stream ID, be it a local or a remote stream, a canvas stream or a screen share stream. You may obtain the ID of the stream using EnxRtc.getID() method.

Method: EnxRtc.getID()

Return: StreamID

 var myStreamID = localStream.getID();

Get Stream Attributes

Stream attributes are defined as part of stream initialization process in the JSON Payload as custom keys in attributes. e.g.

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

After stream initialization, use EnxStream.setAttribues() method to redefine or update the stream attributes. You may use EnxStream.getAttributes() method to obtain  all the current keys and their values in the attributes object of stream definition,

Method: EnxStream.getAttributes() – No parameter needed.

Returns: Attributes JSON object of the Stream.

var attrbutes = stream.getAttributes();

Verify availability of Media Tracks in Stream

EnxStream class has number of methods to verify whether the stream has one or more type of media tracks.. The  methods (with no parameters) returning a true/false are listed below:

Methods:

  • EnxStream.ifAudio() – To check if Stream has Audio Track
  • EnxStream.ifVideo() – To check if Stream has Video Track
  • EnxStream.ifData() – To check if Stream has Data Track
  • EnxStream.ifScreen() – To check if Stream has Screen Share
if (stream.ifVideo()) {
     // The Stream has a Video Track in it
}

// Other methods are also used similar way

Explore Web SDK