getTrackPublicationBySource method
- TrackSource source
Tries to find a TrackPublication by its TrackSource. Otherwise, will return a compatible type of TrackPublication for the TrackSource specified. returns null when not found.
Implementation
T? 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) ||
(source == TrackSource.screenShareVideo &&
e.kind == lk_models.TrackType.VIDEO) ||
(source == TrackSource.screenShareAudio &&
e.kind == lk_models.TrackType.AUDIO));
}