A Media Stream is created using accessible / allowed Media Devices to play locally or to publish into a connected Video Room. There are varied ways for stream initiation based on requirement.

Table of Contents

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).init()

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 ).init();

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 ).init(); 

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 ).init();

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 ).init();

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 ).init();

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 ).init();

Error Codes

Error CodeDescription
1142 Invalid Device Id
1143 Requested device not found
1144 Device Access denied
1145 Failed to start video source
1146 Failed to execute getUserMedia on MediaDevices
1147 Video width constraint not satisfied
1148 Video height constraint not satisfied
1149 Either Video height, width or Device ID not satisfied
1150Unknown Reason