addSimulcastTrack method

Future<RTCRtpSender> addSimulcastTrack(
  1. MediaStreamTrack track, {
  2. required RTCVideoCodec vCodec,
  3. required MediaStream stream,
  4. RtcTrackKind kind = RtcTrackKind.video,
  5. required bool isSingleTrack,
})

Implementation

Future<RTCRtpSender> addSimulcastTrack(
  MediaStreamTrack track, {
  required RTCVideoCodec vCodec,
  required MediaStream stream,
  RtcTrackKind kind = RtcTrackKind.video,
  required bool isSingleTrack,
}) async {
  final List<RTCRtpEncoding> encodings = [];

  if (kind == RtcTrackKind.video) {
    if (vCodec == RTCVideoCodec.vp9) {
      encodings.addAll(RTCConfigurations.svcEncodings);
    } else {
      encodings.addAll(RTCConfigurations.simulcastEncodings);
    }
  }

  final transceiver = await addTransceiver(
    track: track,
    kind: kind == RtcTrackKind.video
        ? RTCRtpMediaType.RTCRtpMediaTypeVideo
        : RTCRtpMediaType.RTCRtpMediaTypeAudio,
    init: RTCRtpTransceiverInit(
      direction: TransceiverDirection.SendOnly,
      streams: [stream],
      sendEncodings: encodings,
    ),
  );

  final sender = transceiver.sender;

  if (kind != RtcTrackKind.video) return sender;

  await _setPreferredCodec(
    transceiver: transceiver,
    vCodec: vCodec.codec,
    kind: kind,
  );

  return sender;
}