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().

See MDN: MediaDeviceInfo.

Parameters:
  • device_id (str) – The ID of the device.

  • kind (webrtc.MediaDeviceKind) – Whether it’s a microphone, a speaker or a camera.

  • label (str) – The human-readable name of the device.

  • group_id (str) – The ID shared by the devices of one physical device.

property device_id: str

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

See MDN: MediaDeviceInfo/deviceId.

Type:

str

property kind: webrtc.MediaDeviceKind

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

See MDN: MediaDeviceInfo/kind.

Type:

webrtc.MediaDeviceKind

property label: str

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

See MDN: MediaDeviceInfo/label.

Type:

str

property group_id: str

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

See MDN: MediaDeviceInfo/groupId.

Type:

str

to_json()

Returns the device as a JSON-serializable dictionary.

See MDN: MediaDeviceInfo/toJSON.

Returns:

dict – deviceId, kind, label and groupId.

Return type:

dict[str, 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.

Parameters:
  • device_id (str) – The ID of the device.

  • kind (webrtc.MediaDeviceKind) – Whether it’s a microphone or a camera.

  • label (str) – The human-readable name of the device.

  • group_id (str) – The ID shared by the devices of one physical device.

  • capabilities (webrtc.MediaTrackCapabilities) – What the device can do.

get_capabilities()

Returns what the device can do. This matches webrtc.MediaStreamTrack.get_capabilities() of its tracks.

See MDN: InputDeviceInfo/getCapabilities.

Returns:

webrtc.MediaTrackCapabilities – A copy of the capabilities.

Return type:

webrtc.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 or webrtc.MediaStreamTrackGenerator.

See MDN: MediaDevices.

Events:

devicechange (webrtc.DeviceChangeEvent) – The devices changed. It never fires, because the devices are fixed.

Events

Handlers are registered with on().

async enumerate_devices()

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

See MDN: MediaDevices/enumerateDevices.

Returns:

list of webrtc.MediaDeviceInfo – The devices, all of them webrtc.InputDeviceInfo.

Return type:

list[webrtc.MediaDeviceInfo]

get_supported_constraints()

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

See MDN: MediaDevices/getSupportedConstraints.

Returns:

webrtc.MediaTrackSupportedConstraints – The constraints, with every member set to True.

Return type:

webrtc.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() shows.

See MDN: MediaDevices/getUserMedia.

Parameters:

constraints (webrtc.MediaStreamConstraints, optional) – Whether to get an audio and a video track, and the constraints of each.

Returns:

webrtc.MediaStream – The stream.

Raises:
  • TypeError – If neither audio nor video is requested, or a double isn’t finite.

  • webrtc.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

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.

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

Alias for media_devices