Local Stream
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.
Getting Device Access
The audio or 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 devices (as applicable). The user must allow access for the successful initiation of the stream.
More Infomration: How to get Device Access
Initiate a Local Stream
To initialize a local stream before publishing it in the room, instantiate the EnxStream
class, a sub-class of the 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
: JSON Pbject.audio
: As Boolean (Set to true to use default Micxrophone). As Object (Set Device ID of Microphone)video
: As Boolean (Set to true to use default Camera). As Object (Set Device ID of Camera)data
: Boolean. Set to true to Data to streamscreen
: Boolean. Set to true to Screen Share to streamaudioMuted
: Boolean. Set to true for audio-muted entry to roomvideoMuted
: Boolean. Set to true for video-muted entry to roomattributes
: JSON Pbject. Object to carry custom datacustom_data
: Variant. Any key you may use
videoSize
: Array. e.g. In numbers. [minWidth, minHeight, maxWidth, maxHeight]maxVideoLayers
: Number. Total 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
Sample Code
var streamOpt = {"audio": true,"video": true,"data": true,"screen": false,"audioMuted": true,"videoMuted": true,"attributes": {"name": "John"},"videoSize": [minWidth, minHeight, maxWidth, maxHeight],"maxVideoLayers": 1};var localStream = EnxRtc.EnxStream( streamOpt ).init();
Stream with Default Devices
To initiate a stream with audio and 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.
Sample Code
var streamOpt = {"audio": true,"video": true,"data": true,"attributes": {"name": "John"}};var localStream = EnxRtc.EnxStream( streamOpt ).init();
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 elements, allowing users to choose an audio device from the list.
Sample Code
var streamOpt = {"audio": { "deviceId": "ID-AUDIO12345"},"video": { "deviceId": "ID-VIDEO92939"},"data": true,"attributes": {"name": "John"}};var localStream = EnxRtc.EnxStream( streamOpt ).init();
Stream with Mobile Browsers
When the client application is used in a mobile browser, it generally starts a video stream using the rear camera. To use front or rear camera, instad of using deviceId
, use facingMode
.
facingMode
: Enumerated values:user
,environment
user
: To use Front Cameraenvironment
: To use Rear Camera
Sample Code
var streamOpt = {"audio": { "deviceId": "ID-AUDIO12345"},"video": { "facingMode": "user"}, // Front Camera"data": true,"attributes": {"name": "John"}};var localStream = EnxRtc.EnxStream( streamOpt ).init();
Stream with Local File and Remote URL
You can also initiate a stream using remote URL or local file path to a .mkv file.
Sample Code
var streamOpt = {"audio": true,"video": true,"url": "rtsp://FQDN/video-resource-path" // Remove URL"url": "file://video-file-path" // Local Path};var localStream = EnxRtc.EnxStream( streamOpt ).init();
Stream with Screen Share
A Screen Share may be ininiated as a Stream. When invoked, browser will prompt the user to allow Sharing Requst and will present different type of screen share options. If user allow/opts for one of the option, the Stream is initiated.
Sample Code
var streamOpt = {"screen": true,};var localScreenStream = EnxRtc.EnxStream( streamOpt ).init();
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.
Sample Code
var streamOpt = {"audio": true,"video": true,"maxVideoLayers": 3 // Carry 3 layers. 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};var localMultiLayerStream = EnxRtc.EnxStream( streamOpt ).init();
Error Codes
Error Code | Description |
---|---|
1142 | The Device Id is invalid. |
1143 | The requested device is not found. |
1144 | Access to the device access is denied. |
1145 | Failed to start the video source. |
1146 | Failed to execute getUserMedia on the media devices. |
1147 | The video width constraint is not satisfied. |
1148 | The video height constraint is not satisfied. |
1149 | Either the video height or width, or Device ID is not satisfied. |
1150 | Unknown reason. |