Device Manager
Manage audio and video device settings.
info
Always make sure to call deviceManager.storeConstraints() after devices have changed, so that a following start_stream event will actually use them.
import { DeviceManager } from '@eyeson/js';
const deviceManager = new DeviceManager();
deviceManager.onChange(event => { // changeHandler
event.error; // if set it contains { name, message }, default null
event.cameras; // available cameras
event.microphones; // available microphones
event.speakers; // available speakers
event.sinkId; // available sinkId (audio output selection)
event.stream; // stream to test devices with
event.constraints; // selected media constraints
event.options; // selected options
});
deviceManager.start(isMobile); // start checking device changes, isMobile defaults to false
deviceManager.setVideoInput(deviceId); // switch camera
deviceManager.setAudioInput(deviceId, { preventUpdate }); // switch microphone; preventUpdate is default false
deviceManager.setAudioPassthrough(enabled, { preventUpdate }); // switch audio-passthrough; preventUpdate is default false
deviceManager.setAudioOutput(sinkId); // switch audio output, speakers
deviceManager.storeConstraints(); // store current selection
deviceManager.removeListener(changeHandler); // remove listeners if registered via onChange
deviceManager.updateWithOptions(options, isMobile); // options = { audio: true/false, video: true/false, eco: true/false }, isMobile defaults to false
deviceManager.stop(); // stop checking device changes
Event Object Properties
| Property | Description |
|---|---|
| error | If set, it contains { name, message }, default null |
| cameras | Available cameras |
| microphones | Available microphones |
| speakers | Available speakers |
| sinkId | Available sinkId (audio output selection) |
| stream | Stream to test devices with |
| constraints | Selected media constraints |
| options | Selected options |
DeviceManager Methods
| Method | Parameters | Description |
|---|---|---|
| onChange | changeHandler | Register event handler for device changes |
| start | isMobile | Start checking device changes, isMobile defaults to false |
| setVideoInput | deviceId | Switch camera |
| setAudioInput | deviceId, { preventUpdate } | Switch microphone; preventUpdate is default false |
| setAudioPassthrough | enabled, { preventUpdate } | Switch audio-passthrough; preventUpdate is default false |
| setAudioOutput | sinkId | Switch audio output, speakers |
| storeConstraints | - | Store current selection |
| removeListener | changeHandler | Remove listeners if registered via onChange |
| updateWithOptions | options, isMobile | options = { audio: true/false, video: true/false, eco: true/false }, isMobile defaults to false |
| stop | - | Stop checking device changes |