replaceTrack method

void replaceTrack(
  1. MediaStreamTrack mediaStreamTrack

Replace current audio or video track that is being broadcasted.

mediaStreamTrack - New audio or video track to replace the current one.


void replaceTrack(MediaStreamTrack mediaStreamTrack) async {
  if (peer == null) {
    _logger.e('Could not change track if there is not an active connection.');

  try {
    RTCRtpSender? currentSender = (await peer!.getSenders()).firstWhere(
        (s) => s.track?.kind == mediaStreamTrack.kind,
        orElse: () => throw Exception());
  } catch (e) {
        .e('There is no ${mediaStreamTrack.kind} track in active broadcast.');