Table of Contents

Switch Source Media Devices of Published Stream

A user may want to switch to alternate Media Devices for his published stream. EnableX API allows Media Device switching on the fly.

The window.EnxRtc.switchMediaDevice() method allows you to switch Microphone, Bluetooth devices, or speakers. You can use 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)

Parameters:

  • @param {String} device – The device name as received from getDevices() API

Event Listeners:

  • onNotifyDeviceUpdate – When the Audio Device change is complete.

Returns:

Switched Audio Device name

// 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",
(data)
function
{
console.log(JSON.stringify(data.data));
});

Switch between Rear & Front Camera

If the user looks to switch between Rear and Front Camera as a source for published Stream, use window.EnxRtc.switchCamera() method.

Method: switchCamera() – No parameter needed

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