no casting required for getTrackPublicationBySource
This commit is contained in:
@@ -18,15 +18,12 @@ import '../utils.dart';
|
|||||||
import 'participant.dart';
|
import 'participant.dart';
|
||||||
|
|
||||||
/// Represents the current participant in the room.
|
/// Represents the current participant in the room.
|
||||||
class LocalParticipant extends Participant {
|
class LocalParticipant extends Participant<LocalTrackPublication> {
|
||||||
@internal
|
@internal
|
||||||
final VideoPublishOptions? defaultVideoPublishOptions;
|
final VideoPublishOptions? defaultVideoPublishOptions;
|
||||||
@internal
|
@internal
|
||||||
final AudioPublishOptions? defaultAudioPublishOptions;
|
final AudioPublishOptions? defaultAudioPublishOptions;
|
||||||
|
|
||||||
@override
|
|
||||||
final Map<String, LocalTrackPublication> trackPublications = {};
|
|
||||||
|
|
||||||
LocalParticipant({
|
LocalParticipant({
|
||||||
required RTCEngine engine,
|
required RTCEngine engine,
|
||||||
required lk_models.ParticipantInfo info,
|
required lk_models.ParticipantInfo info,
|
||||||
@@ -261,9 +258,7 @@ class LocalParticipant extends Participant {
|
|||||||
trackPublications.values
|
trackPublications.values
|
||||||
.whereType<LocalTrackPublication<LocalAudioTrack>>()
|
.whereType<LocalTrackPublication<LocalAudioTrack>>()
|
||||||
.toList();
|
.toList();
|
||||||
}
|
|
||||||
|
|
||||||
extension LocalParticipantTrackSourceExt on LocalParticipant {
|
|
||||||
/// Shortcut for publishing a [TrackSource.camera]
|
/// Shortcut for publishing a [TrackSource.camera]
|
||||||
Future<LocalTrackPublication?> setCameraEnabled(bool enabled) async {
|
Future<LocalTrackPublication?> setCameraEnabled(bool enabled) async {
|
||||||
return setSourceEnabled(TrackSource.camera, enabled);
|
return setSourceEnabled(TrackSource.camera, enabled);
|
||||||
@@ -283,8 +278,7 @@ extension LocalParticipantTrackSourceExt on LocalParticipant {
|
|||||||
Future<LocalTrackPublication?> setSourceEnabled(
|
Future<LocalTrackPublication?> setSourceEnabled(
|
||||||
TrackSource source, bool enabled) async {
|
TrackSource source, bool enabled) async {
|
||||||
logger.fine('setSourceEnabled(source: $source, enabled: $enabled)');
|
logger.fine('setSourceEnabled(source: $source, enabled: $enabled)');
|
||||||
final publication =
|
final publication = getTrackPublicationBySource(source);
|
||||||
getTrackPublicationBySource(source) as LocalTrackPublication?;
|
|
||||||
if (publication != null) {
|
if (publication != null) {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
await publication.unmute();
|
await publication.unmute();
|
||||||
|
|||||||
@@ -23,14 +23,14 @@ import 'remote_participant.dart';
|
|||||||
|
|
||||||
/// Base for [RemoteParticipant] and [LocalParticipant],
|
/// Base for [RemoteParticipant] and [LocalParticipant],
|
||||||
/// can not be instantiated directly.
|
/// can not be instantiated directly.
|
||||||
abstract class Participant extends DisposableChangeNotifier
|
abstract class Participant<T extends TrackPublication>
|
||||||
with EventsEmittable<ParticipantEvent> {
|
extends DisposableChangeNotifier with EventsEmittable<ParticipantEvent> {
|
||||||
/// Reference to [RTCEngine]
|
/// Reference to [RTCEngine]
|
||||||
@internal
|
@internal
|
||||||
final RTCEngine engine;
|
final RTCEngine engine;
|
||||||
|
|
||||||
/// map of track sid => published track
|
/// 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
|
/// audio level between 0-1, 1 being the loudest
|
||||||
double audioLevel = 0;
|
double audioLevel = 0;
|
||||||
@@ -79,14 +79,14 @@ abstract class Participant extends DisposableChangeNotifier
|
|||||||
ConnectionQuality get connectionQuality => _connectionQuality;
|
ConnectionQuality get connectionQuality => _connectionQuality;
|
||||||
|
|
||||||
/// tracks that are subscribed to
|
/// tracks that are subscribed to
|
||||||
List<TrackPublication> get subscribedTracks =>
|
List<T> get subscribedTracks =>
|
||||||
trackPublications.values.where((e) => e.subscribed).toList();
|
trackPublications.values.where((e) => e.subscribed).toList();
|
||||||
|
|
||||||
// Must be implemented by child class
|
// Must be implemented by child class
|
||||||
List<TrackPublication> get videoTracks;
|
List<T> get videoTracks;
|
||||||
|
|
||||||
// Must be implemented by child class
|
// Must be implemented by child class
|
||||||
List<TrackPublication> get audioTracks;
|
List<T> get audioTracks;
|
||||||
|
|
||||||
/// for internal use
|
/// for internal use
|
||||||
/// {@nodoc}
|
/// {@nodoc}
|
||||||
@@ -164,7 +164,7 @@ abstract class Participant extends DisposableChangeNotifier
|
|||||||
/// for internal use
|
/// for internal use
|
||||||
/// {@nodoc}
|
/// {@nodoc}
|
||||||
@internal
|
@internal
|
||||||
void addTrackPublication(TrackPublication pub) {
|
void addTrackPublication(T pub) {
|
||||||
pub.track?.sid = pub.sid;
|
pub.track?.sid = pub.sid;
|
||||||
trackPublications[pub.sid] = pub;
|
trackPublications[pub.sid] = pub;
|
||||||
}
|
}
|
||||||
@@ -188,9 +188,7 @@ abstract class Participant extends DisposableChangeNotifier
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(Object other) => other is Participant && sid == other.sid;
|
bool operator ==(Object other) => other is Participant && sid == other.sid;
|
||||||
}
|
|
||||||
|
|
||||||
extension ParticipantTrackSourceExt on Participant {
|
|
||||||
bool isCameraEnabled() {
|
bool isCameraEnabled() {
|
||||||
return !(getTrackPublicationBySource(TrackSource.camera)?.muted ?? true);
|
return !(getTrackPublicationBySource(TrackSource.camera)?.muted ?? true);
|
||||||
}
|
}
|
||||||
@@ -206,7 +204,7 @@ extension ParticipantTrackSourceExt on Participant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Find a track publication by its [TrackSource]
|
/// Find a track publication by its [TrackSource]
|
||||||
TrackPublication? getTrackPublicationBySource(TrackSource source) {
|
T? getTrackPublicationBySource(TrackSource source) {
|
||||||
if (source == TrackSource.unknown) return null;
|
if (source == TrackSource.unknown) return null;
|
||||||
// try to find by source
|
// try to find by source
|
||||||
final result =
|
final result =
|
||||||
|
|||||||
@@ -16,10 +16,7 @@ import '../types.dart';
|
|||||||
import 'participant.dart';
|
import 'participant.dart';
|
||||||
|
|
||||||
/// Represents other participant in the [Room].
|
/// Represents other participant in the [Room].
|
||||||
class RemoteParticipant extends Participant {
|
class RemoteParticipant extends Participant<RemoteTrackPublication> {
|
||||||
@override
|
|
||||||
final Map<String, RemoteTrackPublication> trackPublications = {};
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<RemoteTrackPublication> get subscribedTracks =>
|
List<RemoteTrackPublication> get subscribedTracks =>
|
||||||
super.subscribedTracks.cast<RemoteTrackPublication>().toList();
|
super.subscribedTracks.cast<RemoteTrackPublication>().toList();
|
||||||
|
|||||||
Reference in New Issue
Block a user