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
- Verify availability of Media Tracks in Stream
- Check Audio Video Track Status in Stream
- Know if Stream is Local or Remote
- Know current state of Stream
- Get Media of a 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: 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();