# MediaDevices

MediaDevices of Media Capture and Streams, which provides the synthetic microphone and camera of the library.

### *class* webrtc.interfaces.media_devices.MediaDeviceInfo(\*, device_id, kind, label, group_id)

A media device, as listed by [`MediaDevices.enumerate_devices()`](#webrtc.interfaces.media_devices.MediaDevices.enumerate_devices).

See [MDN: MediaDeviceInfo](https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo).

* **Parameters:**
  * **device_id** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The ID of the device.
  * **kind** ([`webrtc.MediaDeviceKind`](../enums.md#webrtc.enums.MediaDeviceKind)) – Whether it’s a microphone, a speaker or a camera.
  * **label** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The human-readable name of the device.
  * **group_id** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The ID shared by the devices of one physical device.

#### *property* device_id *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*

The ID of the device. It’s `'synthetic-microphone'` or `'synthetic-camera'`.

See [MDN: MediaDeviceInfo/deviceId](https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo/deviceId).

* **Type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### *property* kind *: [webrtc.MediaDeviceKind](../enums.md#webrtc.enums.MediaDeviceKind)*

Whether it’s a microphone, a speaker or a camera.

See [MDN: MediaDeviceInfo/kind](https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo/kind).

* **Type:**
  [`webrtc.MediaDeviceKind`](../enums.md#webrtc.enums.MediaDeviceKind)

#### *property* label *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*

The human-readable name of the device. It’s always given, since no permission is needed.

See [MDN: MediaDeviceInfo/label](https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo/label).

* **Type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### *property* group_id *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*

The ID shared by the devices of one physical device. Both devices use `'synthetic'`.

See [MDN: MediaDeviceInfo/groupId](https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo/groupId).

* **Type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### to_json()

Returns the device as a JSON-serializable dictionary.

See [MDN: MediaDeviceInfo/toJSON](https://developer.mozilla.org/en-US/docs/Web/API/MediaDeviceInfo/toJSON).

* **Returns:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict) – `deviceId`, `kind`, `label` and `groupId`.
* **Return type:**
  [dict](https://docs.python.org/3/builtins/stdtypes.html#dict)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), [str](https://docs.python.org/3/builtins/stdtypes.html#str)]

### *class* webrtc.interfaces.media_devices.InputDeviceInfo(\*, device_id, kind, label, group_id, capabilities)

An input device, which is the synthetic microphone or the synthetic camera.

See [MDN: InputDeviceInfo](https://developer.mozilla.org/en-US/docs/Web/API/InputDeviceInfo).

* **Parameters:**
  * **device_id** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The ID of the device.
  * **kind** ([`webrtc.MediaDeviceKind`](../enums.md#webrtc.enums.MediaDeviceKind)) – Whether it’s a microphone or a camera.
  * **label** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The human-readable name of the device.
  * **group_id** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The ID shared by the devices of one physical device.
  * **capabilities** ([`webrtc.MediaTrackCapabilities`](../models/media_track_constraints.md#webrtc.models.media_track_constraints.MediaTrackCapabilities)) – What the device can do.

#### get_capabilities()

Returns what the device can do. This matches [`webrtc.MediaStreamTrack.get_capabilities()`](media_stream_track.md#webrtc.interfaces.media_stream_track.MediaStreamTrack.get_capabilities) of its tracks.

See [MDN: InputDeviceInfo/getCapabilities](https://developer.mozilla.org/en-US/docs/Web/API/InputDeviceInfo/getCapabilities).

* **Returns:**
  [`webrtc.MediaTrackCapabilities`](../models/media_track_constraints.md#webrtc.models.media_track_constraints.MediaTrackCapabilities) – A copy of the capabilities.
* **Return type:**
  [webrtc.MediaTrackCapabilities](../models/media_track_constraints.md#webrtc.models.media_track_constraints.MediaTrackCapabilities)

### *class* webrtc.interfaces.media_devices.MediaDevices

The media devices of the library, which are a synthetic microphone and camera. Use `webrtc.media_devices`.

No hardware is opened. The microphone plays quiet noise and the camera draws a moving pattern. To send real
media, write it to a [`webrtc.VideoTrackGenerator`](track_generator.md#webrtc.interfaces.track_generator.VideoTrackGenerator) or [`webrtc.MediaStreamTrackGenerator`](track_generator.md#webrtc.interfaces.track_generator.MediaStreamTrackGenerator).

See [MDN: MediaDevices](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices).

* **Events:**
  **devicechange** ([`webrtc.DeviceChangeEvent`](../models/events.md#webrtc.models.events.DeviceChangeEvent)) – The devices changed. It never fires, because the
  devices are fixed.

### Events

- `devicechange`: [`Event`](../models/events.md#webrtc.models.events.Event)

Handlers are registered with [`on()`](../events.md#webrtc.utils.events.UniformEventTarget.on).

#### *async* enumerate_devices()

Lists the synthetic microphone and camera. Labels are included and no permission prompt is shown.

See [MDN: MediaDevices/enumerateDevices](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices).

* **Returns:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list) of [`webrtc.MediaDeviceInfo`](#webrtc.interfaces.media_devices.MediaDeviceInfo) – The devices, all of them [`webrtc.InputDeviceInfo`](#webrtc.interfaces.media_devices.InputDeviceInfo).
* **Return type:**
  [list](https://docs.python.org/3/builtins/stdtypes.html#list)[[webrtc.MediaDeviceInfo](#webrtc.interfaces.media_devices.MediaDeviceInfo)]

#### get_supported_constraints()

Returns the constraints the library recognizes, which are all of them.

See [MDN: MediaDevices/getSupportedConstraints](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getSupportedConstraints).

* **Returns:**
  [`webrtc.MediaTrackSupportedConstraints`](../models/media_track_constraints.md#webrtc.models.media_track_constraints.MediaTrackSupportedConstraints) – The constraints, with every member set to [`True`](https://docs.python.org/3/builtins/constants.html#True).
* **Return type:**
  [webrtc.MediaTrackSupportedConstraints](../models/media_track_constraints.md#webrtc.models.media_track_constraints.MediaTrackSupportedConstraints)

#### *async* get_user_media(constraints=None)

Returns a stream with a track of the synthetic microphone, the synthetic camera, or both.

The camera starts at 640x480 and 30 frames per second, adjusted to fit the constraints. The microphone has a
fixed format. The constraints become the constraints of the tracks, as
[`webrtc.MediaStreamTrack.get_constraints()`](media_stream_track.md#webrtc.interfaces.media_stream_track.MediaStreamTrack.get_constraints) shows.

See [MDN: MediaDevices/getUserMedia](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia).

* **Parameters:**
  **constraints** ([`webrtc.MediaStreamConstraints`](../models/media_track_constraints.md#webrtc.models.media_track_constraints.MediaStreamConstraints), optional) – Whether to get an audio and a video track,
  and the constraints of each.
* **Returns:**
  [`webrtc.MediaStream`](media_stream.md#webrtc.interfaces.media_stream.MediaStream) – The stream.
* **Raises:**
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – If neither audio nor video is requested, or a double isn’t finite.
  * [**webrtc.OverconstrainedError**](../exceptions.md#webrtc.exceptions.OverconstrainedError) – If an `exact`, `min` or `max` value is beyond what the device can
        do, like a camera more than 4096 pixels wide or faster than 120 frames per second. Other values
        are clamped to the capabilities.
* **Return type:**
  [webrtc.MediaStream](media_stream.md#webrtc.interfaces.media_stream.MediaStream)

### webrtc.interfaces.media_devices.media_devices *= <webrtc.interfaces.media_devices.MediaDevices object>*

The media devices of the library, `navigator.mediaDevices` in a browser. See [MDN: Navigator/mediaDevices](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/mediaDevices).

### webrtc.interfaces.media_devices.mediaDevices *= <webrtc.interfaces.media_devices.MediaDevices object>*

Alias for [`media_devices`](#webrtc.interfaces.media_devices.media_devices)
