generics instead of covariant implementing for TrackPublication

This commit is contained in:
Hiroshi Horie
2021-12-03 01:53:59 +07:00
parent adc97a154b
commit c38f192a07
3 changed files with 12 additions and 17 deletions
@@ -6,10 +6,7 @@ import '../proto/livekit_models.pb.dart' as lk_models;
import '../track/local.dart'; import '../track/local.dart';
import 'track_publication.dart'; import 'track_publication.dart';
class LocalTrackPublication<T extends LocalTrack> extends TrackPublication { class LocalTrackPublication<T extends LocalTrack> extends TrackPublication<T> {
@override
covariant T? track;
@override @override
final LocalParticipant participant; final LocalParticipant participant;
@@ -27,7 +24,7 @@ class LocalTrackPublication<T extends LocalTrack> extends TrackPublication {
} }
@override @override
Future<bool> updateTrack(covariant T? newValue) async { Future<bool> updateTrack(T? newValue) async {
final didUpdate = await super.updateTrack(newValue); final didUpdate = await super.updateTrack(newValue);
if (newValue != null) { if (newValue != null) {
@@ -30,10 +30,8 @@ class RendererVisibility {
/// Represents a track publication from a RemoteParticipant. Provides methods to /// Represents a track publication from a RemoteParticipant. Provides methods to
/// control if we should subscribe to the track, and its quality (for video). /// control if we should subscribe to the track, and its quality (for video).
class RemoteTrackPublication<T extends RemoteTrack> extends TrackPublication { class RemoteTrackPublication<T extends RemoteTrack>
@override extends TrackPublication<T> {
covariant T? track;
@override @override
final RemoteParticipant participant; final RemoteParticipant participant;
+8 -8
View File
@@ -13,16 +13,16 @@ import '../types.dart';
/// Base for [RemoteTrackPublication] and [LocalTrackPublication], /// Base for [RemoteTrackPublication] and [LocalTrackPublication],
/// can not be instantiated directly. /// can not be instantiated directly.
abstract class TrackPublication extends Disposable { abstract class TrackPublication<T extends Track> extends Disposable {
final String sid; final String sid;
final String name; final String name;
final lk_models.TrackType kind; final lk_models.TrackType kind;
final TrackSource source; final TrackSource source;
// Relevant type must be implemented /// The current [Track] for this publication (readonly).
abstract Track? track; T? get track => _track;
T? _track;
// Relevant type must be implemented
/// The [Participant] this publication belongs to. /// The [Participant] this publication belongs to.
abstract final Participant participant; abstract final Participant participant;
@@ -71,11 +71,11 @@ abstract class TrackPublication extends Disposable {
// Returns true if value has changed. // Returns true if value has changed.
// Intended for internal use only. // Intended for internal use only.
@internal @internal
Future<bool> updateTrack(Track? newValue) async { Future<bool> updateTrack(T? newValue) async {
if (track == newValue) return false; if (_track == newValue) return false;
// dispose previous track (if exists) // dispose previous track (if exists)
await track?.dispose(); await _track?.dispose();
track = newValue; _track = newValue;
return true; return true;
} }
} }