updateAudioDevice method

Future<void> updateAudioDevice([
  1. MediaStreamTrack? track
])

Implementation

Future<void> updateAudioDevice([MediaStreamTrack? track]) async {
  final sender = usermediaSenders
      .firstWhereOrNull((element) => element.track!.kind == 'audio');
  await sender?.track?.stop();
  if (track != null) {
    await sender?.replaceTrack(track);
  } else {
    final stream =
        await voip.delegate.mediaDevices.getUserMedia({'audio': true});
    final audioTrack = stream.getAudioTracks().firstOrNull;
    if (audioTrack != null) {
      await sender?.replaceTrack(audioTrack);
    }
  }
}