getTrackPublicationBySource method Null safety

TrackPublication? getTrackPublicationBySource(
  1. TrackSource source
)

Find a track publication by its TrackSource

Implementation

TrackPublication? getTrackPublicationBySource(TrackSource source) {
  if (source == TrackSource.unknown) return null;
  // try to find by source
  final result =
      trackPublications.values.firstWhereOrNull((e) => e.source == source);
  if (result != null) return result;
  // try to find by compatibility
  return trackPublications.values
      .where((e) => e.source == TrackSource.unknown)
      .firstWhereOrNull((e) =>
          (source == TrackSource.microphone &&
              e.kind == lk_models.TrackType.AUDIO) ||
          (source == TrackSource.camera &&
              e.kind == lk_models.TrackType.VIDEO &&
              e.name != Track.screenShareName) ||
          (source == TrackSource.screenShareVideo &&
              e.kind == lk_models.TrackType.VIDEO &&
              e.name == Track.screenShareName) ||
          (source == TrackSource.screenShareAudio &&
              e.kind == lk_models.TrackType.AUDIO &&
              e.name == Track.screenShareName));
}