Skip to main content

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​

PropertyDescription
errorIf set, it contains { name, message }, default null
camerasAvailable cameras
microphonesAvailable microphones
speakersAvailable speakers
sinkIdAvailable sinkId (audio output selection)
streamStream to test devices with
constraintsSelected media constraints
optionsSelected options

DeviceManager Methods​

MethodParametersDescription
onChangechangeHandlerRegister event handler for device changes
startisMobileStart checking device changes, isMobile defaults to false
setVideoInputdeviceIdSwitch camera
setAudioInputdeviceId, { preventUpdate }Switch microphone; preventUpdate is default false
setAudioPassthroughenabled, { preventUpdate }Switch audio-passthrough; preventUpdate is default false
setAudioOutputsinkIdSwitch audio output, speakers
storeConstraints-Store current selection
removeListenerchangeHandlerRemove listeners if registered via onChange
updateWithOptionsoptions, isMobileoptions = { audio: true/false, video: true/false, eco: true/false }, isMobile defaults to false
stop-Stop checking device changes