Skip to content

Commit a4b0d7a

Browse files
committed
fix: Fix for Chrome getUserMedia "ideal" Constraint Change.
1 parent 96c65f7 commit a4b0d7a

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

lib/src/support/platform.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,12 @@ class BrowserVersion {
6969
/// The patch version number: "3" in "1.2.3".
7070
final int patch;
7171
}
72+
73+
bool isChrome129OrLater() {
74+
if (lkPlatformIs(PlatformType.web) &&
75+
[BrowserType.chrome, BrowserType.edge].contains(lkBrowser())) {
76+
final version = lkBrowserVersion();
77+
return version.major > 129 || (version.major == 129 && version.minor >= 0);
78+
}
79+
return false;
80+
}

lib/src/track/options.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,13 @@ class CameraCaptureOptions extends VideoCaptureOptions {
8888
'facingMode':
8989
cameraPosition == CameraPosition.front ? 'user' : 'environment'
9090
};
91-
if (deviceId != null) {
91+
if (deviceId != null && deviceId!.isNotEmpty) {
9292
if (kIsWeb) {
93-
constraints['deviceId'] = deviceId;
93+
if (isChrome129OrLater()) {
94+
constraints['deviceId'] = {'exact': deviceId};
95+
} else {
96+
constraints['deviceId'] = {'ideal': deviceId};
97+
}
9498
} else {
9599
constraints['optional'] = [
96100
{'sourceId': deviceId}
@@ -331,9 +335,13 @@ class AudioCaptureOptions extends LocalTrackOptions {
331335
}
332336
}
333337

334-
if (deviceId != null) {
338+
if (deviceId != null && deviceId!.isNotEmpty) {
335339
if (kIsWeb) {
336-
constraints['deviceId'] = deviceId;
340+
if (isChrome129OrLater()) {
341+
constraints['deviceId'] = {'exact': deviceId};
342+
} else {
343+
constraints['deviceId'] = {'ideal': deviceId};
344+
}
337345
} else {
338346
constraints['optional']
339347
.cast<Map<String, dynamic>>()

0 commit comments

Comments
 (0)