no casting required for getTrackPublicationBySource
This commit is contained in:
@@ -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<LocalTrackPublication> {
|
||||
@internal
|
||||
final VideoPublishOptions? defaultVideoPublishOptions;
|
||||
@internal
|
||||
final AudioPublishOptions? defaultAudioPublishOptions;
|
||||
|
||||
@override
|
||||
final Map<String, LocalTrackPublication> trackPublications = {};
|
||||
|
||||
LocalParticipant({
|
||||
required RTCEngine engine,
|
||||
required lk_models.ParticipantInfo info,
|
||||
@@ -261,9 +258,7 @@ class LocalParticipant extends Participant {
|
||||
trackPublications.values
|
||||
.whereType<LocalTrackPublication<LocalAudioTrack>>()
|
||||
.toList();
|
||||
}
|
||||
|
||||
extension LocalParticipantTrackSourceExt on LocalParticipant {
|
||||
/// Shortcut for publishing a [TrackSource.camera]
|
||||
Future<LocalTrackPublication?> setCameraEnabled(bool enabled) async {
|
||||
return setSourceEnabled(TrackSource.camera, enabled);
|
||||
@@ -283,8 +278,7 @@ extension LocalParticipantTrackSourceExt on LocalParticipant {
|
||||
Future<LocalTrackPublication?> 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();
|
||||
|
||||
@@ -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<ParticipantEvent> {
|
||||
abstract class Participant<T extends TrackPublication>
|
||||
extends DisposableChangeNotifier with EventsEmittable<ParticipantEvent> {
|
||||
/// Reference to [RTCEngine]
|
||||
@internal
|
||||
final RTCEngine engine;
|
||||
|
||||
/// map of track sid => published track
|
||||
abstract final Map<String, TrackPublication> trackPublications;
|
||||
final Map<String, T> 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<TrackPublication> get subscribedTracks =>
|
||||
List<T> get subscribedTracks =>
|
||||
trackPublications.values.where((e) => e.subscribed).toList();
|
||||
|
||||
// Must be implemented by child class
|
||||
List<TrackPublication> get videoTracks;
|
||||
List<T> get videoTracks;
|
||||
|
||||
// Must be implemented by child class
|
||||
List<TrackPublication> get audioTracks;
|
||||
List<T> 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 =
|
||||
|
||||
@@ -16,10 +16,7 @@ import '../types.dart';
|
||||
import 'participant.dart';
|
||||
|
||||
/// Represents other participant in the [Room].
|
||||
class RemoteParticipant extends Participant {
|
||||
@override
|
||||
final Map<String, RemoteTrackPublication> trackPublications = {};
|
||||
|
||||
class RemoteParticipant extends Participant<RemoteTrackPublication> {
|
||||
@override
|
||||
List<RemoteTrackPublication> get subscribedTracks =>
|
||||
super.subscribedTracks.cast<RemoteTrackPublication>().toList();
|
||||
|
||||
Reference in New Issue
Block a user