The following methods provide Stream-related Information such as the Stream type, media tracks, state, etc.
Table of Contents
- Get Stream ID
- Get Stream Attributes
- Configure Stream
- Update Stream Attributes
- Verify availability of Media Tracks in Stream
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: EnxRtc
Method: EnxRtc.getID()
Returns: String Stream Id.
var myStreamID = localStream.getID()
;
Get Stream Attributes
The EnxStream.getAttributes()
method provides the Stream attributes that are defined as custom keys under attributes
in the JSON Payload during the Stream Initialization process.
var StreamOpt = { "attributes": { "name": "Stream Name", "custom_key": "String", "custom_key2": Number } }
Class: EnxStream
Method: EnxStream.getAttributes()
– No parameter required.
Returns: Streams Attributes JSON object.
var attrbutes = stream.getAttributes();
Configure Stream
The EnxStream.updateConfiguration()
method is used to reconfigure a Stream by adding new or updating existing attributes of the Stream. This API is applicable to both Remote and Local Streams.
Method: EnxStream.updateConfiguration(ConfigSpecs, Callback)
Parameter:
ConfigSpecs
– New Stream configuration options JSON Object.
// Define Config Specs for Local Stream var ConfigSpecs = { "maxVideoBW
": 400, "maxAudioBW
": "400" }; localstream.updateConfiguration( ConfigSpecs, function(result) { });
Update Stream Attributes
The EnxStream.setAttributes()
method allows you to update your Local Stream’s attributes
object by adding new attributes or changing existing attributes. You can use custom-attribute names for your stream. This API is applicable only on Local Stream.
Method: EnxStream.setAttributes(attributes)
Parameter:
attributes
– Stream attributes JSON Object with custom key and value.
Event Notification:
stream-attributes-updated
– Notification to all the Stream subscribers when the stream attributes are updated.
// Define attributes var Attributes = { "name": "Stream Name", "age": "21", "employee_id": "XXX", "custom_key": "XXX" }; LocalStream.setAttributes(Attributes); // Update room.addEventListener("stream-attributes-updated", function(evt) { // evt.attributes - updated attributes of stream });
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:
EnxStream.ifAudio()
– No Parameter required.
- To check if Stream has a Video Track:
EnxStream.ifVideo()
– No Parameter required.
- To check if Stream has a Data Track:
-
EnxStream.ifData()
– No Parameter required.
-
- To check if Stream has Screen-share:
EnxStream.ifScreen()
– No Parameter required.
if (stream.ifVideo()) { // The Stream has a Video Track in it } // Other methods are also used similar way