createDeviceWatcher

View as Markdown

createDeviceWatcher

  • Const createDeviceWatcher(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
CreateDeviceWatcherOptions

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:

1await SignalWire.WebRTC.getUserMedia({ audio: true, video: false });
2h = await SignalWire.WebRTC.createDeviceWatcher();
3h.on("changed", (c) => console.log(c));

Getting notified only for audio input and output devices:

1h = await SignalWire.WebRTC.createDeviceWatcher({
2 targets: ["microphone", "speaker"],
3});
4h.on("changed", (c) => console.log(c));