Handle a Local Stream

The Cordova SDK provides the following methods to handle a local stream:

Switch to Source Media Devices of Published Streams

Users can switch to alternate media devices for their published stream. EnableX API allows media device switching on the fly.

The window.EnxRtc.switchMediaDevice() method is used to switch microphone, bluetooth devices, or speakers. You can use the window.EnxRtc.getDevices() method to fetch a list of all audio devices and use one of the audio device names to make the switch.

  • Method: switchMediaDevice(Device)
  • Parameter:
    • device: String. The device name as received from the getDevices() API.
  • Event Listeners:
    • onNotifyDeviceUpdate: When the audio device change is complete.
  • Returns: Switched Audio Device name

Sample Code

// deviceName is received from getDevice api
window.EnxRtc.switchMediaDevice(deviceName, function (data) {
console.log(JSON.stringify(data.data));
}, function (err) {
console.log('Uh oh… error resizeLocalView ' + JSON.stringify(err)
);
});
// To listen event listener
window.EnxRtc.addEventListner("onNotifyDeviceUpdate", function(data) {
console.log(JSON.stringify(data.data));
});

Switch between Rear and Front Camera

The window.EnxRtc.switchCamera() method allows you to switch between the rear and front camera as a source for published stream.

  • Method: switchCamera()

Sample Code

window.EnxRtc.switchCamera(false, function (data) {
console.log(JSON.stringify(data.data));
}, function (err) {
console.log(JSON.stringify(err)
);
});

Mute or Unmute Audio in a Stream

The window.EnxRtc.muteSelfAudio() method allows you to mute and unmute audio from local stream. When a user mutes or unmutes audio from their published stream, the self-user notifies with event onAudioEvent, and all other connected users of the room are notified with event listeners onRemoteStreamAudioMute and onRemoteStreamAudioUnMute callbacks, respectively. Listen to these events to update related UI elements.

  • Method: muteSelfAudio(audio)
  • Parameter:
    • audio: Boolean. Set it to true to mute audio. Set it to false to unmute audio.
  • Event Listeners:
    • onRemoteStreamAudioMute : Notification to all the participants that the user had muted audio.
    • onRemoteStreamAudioUnMute: Notification to all the participants that the user had unmuted audio.
    • onAudioEvent : Notification to the user that the audio is either muted or unmuted.

Sample Code

// To mute audio
window.EnxRtc.muteSelfAudio(true);
// To unmute audio
window.EnxRtc.muteSelfAudio(false);
// Add event listeners
// To self. Audio is muted/unmuted.
window.EnxRtc.addEventListner("onAudioEvent", function(data) {
console.log(JSON.stringify(data.data));
});
// To all. Audio muted by Remote user
window.EnxRtc.addEventListner("onRemoteStreamAudioMute", function(data) {
console.log(JSON.stringify(data.data));
});
// To all. Audio unmuted by Remote user
window.EnxRtc.addEventListner("onRemoteStreamAudioUnMute", function(data) {
console.log(JSON.stringify(data.data));
});

Mute or Unmute Video in a Stream

The window.EnxRtc.muteSelfVideo() method allows you to mute and unmute video from local stream. When users mute or unmute video from their published stream, the self-user notifies with event onVideoEvent, and all other connected users of the room are notified with onRemoteStreamVideoMute and onRemoteStreamVideoUnMute callbacks, respectively.

  • Method: muteSelfVideo(video)
  • Parameter:
    • video: Boolean. Set it to true to mute video.
      Set it to false to unmute video.
  • Event Listeners:
    • onRemoteStreamVideoMute : Notification to all the participants that the user had muted video.
    • onRemoteStreamVideoUnMute : Notification to all the participants that the user had unmuted video.
    • onVideoEvent : Notification to the user that the video is either muted or unmuted.

Sample Code

// To mute video
window.EnxRtc.muteSelfVideo(true);
// To unmute video
window.EnxRtc.muteSelfVideo(false);
//Add event listeners// To self. Video is muted/unmuted.
window.EnxRtc.addEventListner("onVideoEvent", function(data) {
console.log(JSON.stringify(data.data));
});
// To all. Video muted by Remote user
window.EnxRtc.addEventListner("onRemoteStreamVideoMute", function(data) {
console.log(JSON.stringify(data.data));
});
// To all. Video unmuted by Remote user
window.EnxRtc.addEventListner("onRemoteStreamVideoUnMute", function(data) {
console.log(JSON.stringify(data.data));
});

Update Stream Configuration

The window.EnxRtc.updateConfiguration() method updates the parameters of a stream when you re-configure your stream by adding new or updating existing specification parameters of a stream. Both remote and local streams can use this method of updating the stream parameters.

  • Method: updateConfiguration( configurationOptions, successCallback, errorCallback )
  • Paramters:
    • configurationOptions : JSON Object. Configuration Options.
    • successCallback: Callable Function. Success Notification.
    • errorCallback: Callable Function. Error Notification.

Sample Code

var videoQualityOptions = {
maxVideoBW: "900",
minVideoBW: "150",
maxAudioBW: "150",
minAudioBW: "150"
};
window.EnxRtc.updateConfiguration(configuarationOptions,function (data) {
console.log('Excelsior success! ' + JSON.stringify(data.data));
}, function (err) {
console.log('Uh oh… error' + JSON.stringify(err));
}
);