createDeviceWatcher
createDeviceWatcher
ConstcreateDeviceWatcher(options?):Promise<EventEmitter<DeviceWatcherEvents, any>>
Asynchronously returns an event emitter that notifies changes in the devices. The possible events are:
"added": A device has been added."removed": A device has been removed."updated": A device has been updated."changed": Any of the previous events occurred.
In all cases, your event handler gets as parameter an object e with the following keys:
e.changes: The changed devices. For"added","removed", and"updated"event handlers, you only get the object associated to the respective event (i.e., only a list of added devices, removed devices, or updated devices). For"changed"event handlers, you get all three lists.e.devices: The new list of devices.
For device-specific helpers, see createCameraDeviceWatcher, createMicrophoneDeviceWatcher, and createSpeakerDeviceWatcher.
Parameters
options
If omitted, the event emitter is associated to all devices for which we have permission. Otherwise, pass an object { targets: string[] }, where targets is a list of categories. Allowed categories are "camera", "microphone", and "speaker".
Returns
Promise<EventEmitter<DeviceWatcherEvents, any>>
Examples
Creating an event listener on the "changed" event:
Getting notified only for audio input and output devices: