selectAudioInput method
Sets the selected device as the audio input device. Use getAudioInputs for getting the list of available audio input devices
Implementation
Future<void> selectAudioInput(String deviceId) async {
// return Helper.selectAudioInput(deviceId);
try {
this.selectedAudioInputDevice = deviceId;
if (kIsWeb) {
var newMediaStream = await navigator.mediaDevices.getUserMedia({
'audio': {'deviceId': selectedAudioInputDevice},
'video': false,
});
var oldAudioStream = localStream!.getAudioTracks()[0];
await localStream?.removeTrack(oldAudioStream);
oldAudioStream.stop();
await localStream?.addTrack(newMediaStream.getAudioTracks()[0]);
channels.forEach((userId, peerConnection) async {
await peerConnection
.replaceAudioTrack(newMediaStream.getAudioTracks()[0]);
});
return Future.value();
} else {
return Helper.selectAudioInput(selectedAudioInputDevice!);
}
} catch (error) {
return Future.error(error);
}
}