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 == TrackType.AUDIO) ||
(source == TrackSource.camera && e.kind == TrackType.VIDEO) ||
(source == TrackSource.screenShareVideo && e.kind == TrackType.VIDEO) ||
(source == TrackSource.screenShareAudio && e.kind == TrackType.AUDIO));
}