Get Stream Information
- getId(): Provides the Stream ID.
- getAttributes(): Provides the attributes of a stream.
- updateConfiguration(): Reconfigures a stream by adding new attributes or updating the existing attributes.
- setAttributes(): Updates the attributes object of your local stream.
- ifAudio(): Checks if a stream includes an audio track.
- ifVideo(): Checks if a stream includes a video track.
- ifData(): Checks if a stream includes a data track.
- ifScreen(): Checks if a stream includes screen sharing.
- play(): Plays any stream in an HTML5 audio or video player.
- stop(): Stops playing an audio or a video stream in the HTML5 player.
Get Stream ID
The EnxStream.getId()
method provides the ID of a given stream. The Stream ID is used to identify a stream, be it a local or a remote stream, a canvas stream, or a screen-share stream.
- Method:
EnxStream.getID()
- Returns: String stream Id
Sample Code
var myStreamID = localStream.getID();
Get Stream Attributes
The EnxStream.getAttributes()
method provides the attributes of a stream defined as custom keys under attributes in the JSON payload during the Stream Initialization process.
- Method:
EnxStream.getAttributes()
- Returns: Attributes of a stream as a JSON object.
Sample Code
var attrbutes = stream.getAttributes();// Returns the attribute object of Stream Configuration/*{"name": "Stream Name","custom_key": "String","custom_key2": Number}*/
Configure a Stream
The EnxStream.updateConfiguration()
method is used to reconfigure a stream by adding new attributes or updating the existing attributes of a stream. This API applies to both remote and local streams.
- Method:
updateConfiguration(ConfigSpecs, Callback)
- Parameter:
ConfigSpecs
: JSON Object. New configuration options of a stream.maxVideoBW
: Max Video BandwidthmaxAudioBW
: Max Audio Bandwidth
Sample Code
// Define Config Specs for Local Streamvar ConfigSpecs = {"maxVideoBW": 400,"maxAudioBW": "400"};localstream.updateConfiguration( ConfigSpecs, function(result) {});
Update Stream Attributes
The EnxStream.setAttributes()
method allows you to update the attribute object of your local stream by adding new attributes or changing the existing attributes. You can also use custom attribute names for your stream. This API is applicable only for local streams.
- Method:
EnxStream.setAttributes(attributes)
- Parameters:
attributes
: JSON Object. Stream attributes with custom key and value.
- Event Notifications:
stream-attributes-updated
: Notification to all subscribers of a stream when stream attributes are updated.
Sample Code
// Define attributesvar Attributes = {"name": "Stream Name","age": "21","employee_id": "XXX","custom_key": "XXX"};LocalStream.setAttributes(Attributes);// Notification: Stream Attributes are updatedroom.addEventListener("stream-attributes-updated", function(evt) {// evt.attributes - updated attributes of stream});
Verify the Availability of Media Tracks in a Stream
The EnxStream
class provides the following methods to check the presence of a particular media track in a stream.
- Methods:
EnxStream.ifAudio()
: To check if a stream includes an audio track.EnxStream.ifVideo()
: To check if a stream includes a video track.EnxStream.ifData()
: To check if a stream includes a data track.EnxStream.ifScreen()
: To check if a stream includes screen sharing.
Sample Code
if (stream.ifVideo()) {// The Stream has Video Track} else {// The Stream doesn't have Video Track}
You can make use of the other methods the same way as shown above.
Play a Stream
The EnxStream.play()
method allows you to play any stream in an HTML5 audio or video player within HTML DOM. This creates a related audio or video HTML tag within the HTML DOM Element ID to play the audio or the video.
- Method:
play(DOMElementID, PlayerOpt)
- Parameters:
DOMElementID
: String. The DIV ID in which the player is drawn.PlayerOpt
: String. Configurable player options. For a complete list of options, see Appendix for the complete list.
Sample Code
// CPlayer Optionsvar PlayerOpt = {player: {'height': '150px','width': '100%','minHeight': 'inherit','minWidth': 'inherit'},toolbar: {displayMode: false,branding: {display: false}}};stream.play("PlayerDiv", PlayerOpt);
Stop Playing a Video
The EnxStream.stop()
method allows you to stop playing an audio or a video stream in the HTML5 player.
- Method:
stop()
Sample Code
stream.stop();