From dc362d57964519efe11a3f27e920d76461ceb819 Mon Sep 17 00:00:00 2001 From: td Date: Wed, 5 Jun 2024 16:00:35 +0530 Subject: [PATCH] fix: translate audio constraints for web --- lib/src/mediadevices_impl.dart | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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;