add ability to select capture device ids (#89)
* add ability to select capture device ids * format fix
This commit is contained in:
@@ -19,20 +19,34 @@ extension CameraPositionExt on CameraPosition {
|
|||||||
|
|
||||||
/// Options used when creating a [LocalVideoTrack] that captures the camera.
|
/// Options used when creating a [LocalVideoTrack] that captures the camera.
|
||||||
class CameraCaptureOptions extends VideoCaptureOptions {
|
class CameraCaptureOptions extends VideoCaptureOptions {
|
||||||
|
/// The deviceId of the capture device to use.
|
||||||
|
/// Available deviceIds can be obtained through `flutter_webrtc`:
|
||||||
|
/// <pre>
|
||||||
|
/// import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
||||||
|
///
|
||||||
|
/// List<MediaDeviceInfo> devices = await rtc.navigator.mediaDevices.enumerateDevices();
|
||||||
|
/// </pre>
|
||||||
|
final String? deviceId;
|
||||||
final CameraPosition cameraPosition;
|
final CameraPosition cameraPosition;
|
||||||
|
|
||||||
const CameraCaptureOptions({
|
const CameraCaptureOptions({
|
||||||
|
this.deviceId,
|
||||||
this.cameraPosition = CameraPosition.front,
|
this.cameraPosition = CameraPosition.front,
|
||||||
VideoParameters params = VideoParametersPresets.h540_169,
|
VideoParameters params = VideoParametersPresets.h540_169,
|
||||||
}) : super(params: params);
|
}) : super(params: params);
|
||||||
|
|
||||||
CameraCaptureOptions.from({required VideoCaptureOptions captureOptions})
|
CameraCaptureOptions.from({required VideoCaptureOptions captureOptions})
|
||||||
: cameraPosition = CameraPosition.front,
|
: deviceId = null,
|
||||||
|
cameraPosition = CameraPosition.front,
|
||||||
super(params: captureOptions.params);
|
super(params: captureOptions.params);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, dynamic> toMediaConstraintsMap() => <String, dynamic>{
|
Map<String, dynamic> toMediaConstraintsMap() => <String, dynamic>{
|
||||||
...super.toMediaConstraintsMap(),
|
...super.toMediaConstraintsMap(),
|
||||||
|
'optional': [
|
||||||
|
{'sourceId': deviceId}
|
||||||
|
],
|
||||||
|
'deviceId': deviceId,
|
||||||
'facingMode':
|
'facingMode':
|
||||||
cameraPosition == CameraPosition.front ? 'user' : 'environment',
|
cameraPosition == CameraPosition.front ? 'user' : 'environment',
|
||||||
};
|
};
|
||||||
@@ -81,6 +95,15 @@ abstract class VideoCaptureOptions extends LocalTrackOptions {
|
|||||||
|
|
||||||
/// Options used when creating a [LocalAudioTrack].
|
/// Options used when creating a [LocalAudioTrack].
|
||||||
class AudioCaptureOptions extends LocalTrackOptions {
|
class AudioCaptureOptions extends LocalTrackOptions {
|
||||||
|
/// The deviceId of the capture device to use.
|
||||||
|
/// Available deviceIds can be obtained through `flutter_webrtc`:
|
||||||
|
/// <pre>
|
||||||
|
/// import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
||||||
|
///
|
||||||
|
/// List<MediaDeviceInfo> devices = await rtc.navigator.mediaDevices.enumerateDevices();
|
||||||
|
/// </pre>
|
||||||
|
final String? deviceId;
|
||||||
|
|
||||||
/// Attempt to use noiseSuppression option (if supported by the platform)
|
/// Attempt to use noiseSuppression option (if supported by the platform)
|
||||||
/// See https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackSettings/noiseSuppression
|
/// See https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackSettings/noiseSuppression
|
||||||
/// Defaults to true.
|
/// Defaults to true.
|
||||||
@@ -105,6 +128,7 @@ class AudioCaptureOptions extends LocalTrackOptions {
|
|||||||
final bool typingNoiseDetection;
|
final bool typingNoiseDetection;
|
||||||
|
|
||||||
const AudioCaptureOptions({
|
const AudioCaptureOptions({
|
||||||
|
this.deviceId,
|
||||||
this.noiseSuppression = true,
|
this.noiseSuppression = true,
|
||||||
this.echoCancellation = true,
|
this.echoCancellation = true,
|
||||||
this.autoGainControl = true,
|
this.autoGainControl = true,
|
||||||
@@ -114,7 +138,9 @@ class AudioCaptureOptions extends LocalTrackOptions {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, dynamic> toMediaConstraintsMap() => <String, dynamic>{
|
Map<String, dynamic> toMediaConstraintsMap() => <String, dynamic>{
|
||||||
|
'deviceId': deviceId,
|
||||||
'optional': <Map<String, dynamic>>[
|
'optional': <Map<String, dynamic>>[
|
||||||
|
<String, dynamic>{'sourceId': deviceId},
|
||||||
<String, dynamic>{'echoCancellation': echoCancellation},
|
<String, dynamic>{'echoCancellation': echoCancellation},
|
||||||
<String, dynamic>{'googDAEchoCancellation': echoCancellation},
|
<String, dynamic>{'googDAEchoCancellation': echoCancellation},
|
||||||
<String, dynamic>{'googEchoCancellation': echoCancellation},
|
<String, dynamic>{'googEchoCancellation': echoCancellation},
|
||||||
|
|||||||
Reference in New Issue
Block a user