diff --git a/lib/src/mediadevices_impl.dart b/lib/src/mediadevices_impl.dart index f8511d2..5051c96 100644 --- a/lib/src/mediadevices_impl.dart +++ b/lib/src/mediadevices_impl.dart @@ -27,6 +27,28 @@ class MediaDevicesWeb extends MediaDevices { print( '[getUserMedia] failed to remove facingMode from mediaConstraints'); } + try { + if (mediaConstraints['audio'] is Map && + Map.from(mediaConstraints['audio']).containsKey('optional') && + mediaConstraints['audio']['optional'] + is List>) { + List> optionalValues = + mediaConstraints['audio']['optional']; + final audioMap = {}; + + optionalValues.forEach((option) { + option.forEach((key, value) { + audioMap[key] = value; + }); + }); + + mediaConstraints['audio'].remove('optional'); + mediaConstraints['audio'].addAll(audioMap); + } + } catch (e, s) { + print( + '[getUserMedia] failed to translate optional audio constraints, $e, $s'); + } final mediaDevices = web.window.navigator.mediaDevices;