From adc97a154b0656175a8467cab44e7b34a4dd2a25 Mon Sep 17 00:00:00 2001 From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Fri, 3 Dec 2021 01:36:22 +0700 Subject: [PATCH] no casting required for getTrackPublicationBySource --- lib/src/participant/local_participant.dart | 10 ++-------- lib/src/participant/participant.dart | 18 ++++++++---------- lib/src/participant/remote_participant.dart | 5 +---- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/lib/src/participant/local_participant.dart b/lib/src/participant/local_participant.dart index 832c691..2053d35 100644 --- a/lib/src/participant/local_participant.dart +++ b/lib/src/participant/local_participant.dart @@ -18,15 +18,12 @@ import '../utils.dart'; import 'participant.dart'; /// Represents the current participant in the room. -class LocalParticipant extends Participant { +class LocalParticipant extends Participant { @internal final VideoPublishOptions? defaultVideoPublishOptions; @internal final AudioPublishOptions? defaultAudioPublishOptions; - @override - final Map trackPublications = {}; - LocalParticipant({ required RTCEngine engine, required lk_models.ParticipantInfo info, @@ -261,9 +258,7 @@ class LocalParticipant extends Participant { trackPublications.values .whereType>() .toList(); -} -extension LocalParticipantTrackSourceExt on LocalParticipant { /// Shortcut for publishing a [TrackSource.camera] Future setCameraEnabled(bool enabled) async { return setSourceEnabled(TrackSource.camera, enabled); @@ -283,8 +278,7 @@ extension LocalParticipantTrackSourceExt on LocalParticipant { Future setSourceEnabled( TrackSource source, bool enabled) async { logger.fine('setSourceEnabled(source: $source, enabled: $enabled)'); - final publication = - getTrackPublicationBySource(source) as LocalTrackPublication?; + final publication = getTrackPublicationBySource(source); if (publication != null) { if (enabled) { await publication.unmute(); diff --git a/lib/src/participant/participant.dart b/lib/src/participant/participant.dart index 7b07f5e..179a345 100644 --- a/lib/src/participant/participant.dart +++ b/lib/src/participant/participant.dart @@ -23,14 +23,14 @@ import 'remote_participant.dart'; /// Base for [RemoteParticipant] and [LocalParticipant], /// can not be instantiated directly. -abstract class Participant extends DisposableChangeNotifier - with EventsEmittable { +abstract class Participant + extends DisposableChangeNotifier with EventsEmittable { /// Reference to [RTCEngine] @internal final RTCEngine engine; /// map of track sid => published track - abstract final Map trackPublications; + final Map trackPublications = {}; /// audio level between 0-1, 1 being the loudest double audioLevel = 0; @@ -79,14 +79,14 @@ abstract class Participant extends DisposableChangeNotifier ConnectionQuality get connectionQuality => _connectionQuality; /// tracks that are subscribed to - List get subscribedTracks => + List get subscribedTracks => trackPublications.values.where((e) => e.subscribed).toList(); // Must be implemented by child class - List get videoTracks; + List get videoTracks; // Must be implemented by child class - List get audioTracks; + List get audioTracks; /// for internal use /// {@nodoc} @@ -164,7 +164,7 @@ abstract class Participant extends DisposableChangeNotifier /// for internal use /// {@nodoc} @internal - void addTrackPublication(TrackPublication pub) { + void addTrackPublication(T pub) { pub.track?.sid = pub.sid; trackPublications[pub.sid] = pub; } @@ -188,9 +188,7 @@ abstract class Participant extends DisposableChangeNotifier @override bool operator ==(Object other) => other is Participant && sid == other.sid; -} -extension ParticipantTrackSourceExt on Participant { bool isCameraEnabled() { return !(getTrackPublicationBySource(TrackSource.camera)?.muted ?? true); } @@ -206,7 +204,7 @@ extension ParticipantTrackSourceExt on Participant { } /// Find a track publication by its [TrackSource] - TrackPublication? getTrackPublicationBySource(TrackSource source) { + T? getTrackPublicationBySource(TrackSource source) { if (source == TrackSource.unknown) return null; // try to find by source final result = diff --git a/lib/src/participant/remote_participant.dart b/lib/src/participant/remote_participant.dart index 444c330..4ecfc6c 100644 --- a/lib/src/participant/remote_participant.dart +++ b/lib/src/participant/remote_participant.dart @@ -16,10 +16,7 @@ import '../types.dart'; import 'participant.dart'; /// Represents other participant in the [Room]. -class RemoteParticipant extends Participant { - @override - final Map trackPublications = {}; - +class RemoteParticipant extends Participant { @override List get subscribedTracks => super.subscribedTracks.cast().toList();