more docs

This commit is contained in:
Hiroshi Horie
2021-12-09 13:22:03 +07:00
parent b6b48ea310
commit 6003258089
5 changed files with 66 additions and 26 deletions
+8 -2
View File
@@ -12,13 +12,16 @@ import '../options.dart';
import '../proto/livekit_models.pb.dart' as lk_models;
import '../publication/local_track_publication.dart';
import '../rtc_engine.dart';
import '../track/local.dart';
import '../track/local/audio.dart';
import '../track/local/video.dart';
import '../types.dart';
import '../utils.dart';
import '../room.dart';
import 'participant.dart';
/// Represents the current participant in the room.
/// Represents the current participant in the room. Instance of [LocalParticipant] is automatically
/// created after successfully connecting to a [Room] and will be accessible from [Room.localParticipant].
class LocalParticipant extends Participant<LocalTrackPublication> {
@internal
final VideoPublishOptions? defaultVideoPublishOptions;
@@ -40,7 +43,8 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
updateFromInfo(info);
}
/// publish an audio track to the room
/// Publish an [AudioTrack] to the [Room].
/// For most cases, using [setMicrophoneEnabled] would be simpler and recommended.
Future<LocalTrackPublication<LocalAudioTrack>> publishAudioTrack(
LocalAudioTrack track, {
AudioPublishOptions? options,
@@ -250,12 +254,14 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
List<LocalTrackPublication> get subscribedTracks =>
super.subscribedTracks.cast<LocalTrackPublication>().toList();
/// A convenience property to get all video tracks.
@override
List<LocalTrackPublication<LocalVideoTrack>> get videoTracks =>
trackPublications.values
.whereType<LocalTrackPublication<LocalVideoTrack>>()
.toList();
/// A convenience property to get all audio tracks.
@override
List<LocalTrackPublication<LocalAudioTrack>> get audioTracks =>
trackPublications.values
+24 -19
View File
@@ -29,30 +29,31 @@ abstract class Participant<T extends TrackPublication>
@internal
final RTCEngine engine;
/// map of track sid => published track
/// Map of track sid => published track
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;
/// server assigned unique id
/// Server assigned unique id.
final String sid;
/// user-assigned identity
/// User-assigned identity.
String identity;
/// client-assigned metadata, opaque to livekit
/// Client-assigned metadata, opaque to livekit.
String? metadata;
/// when the participant had last spoken
/// When the participant had last spoken.
DateTime? lastSpokeAt;
lk_models.ParticipantInfo? _participantInfo;
bool _isSpeaking = false;
/// Connection quality between the [Participant] and the server.
ConnectionQuality _connectionQuality = ConnectionQuality.unknown;
// suppport for multiple event listeners
// Suppport for multiple event listeners.
final EventsEmitter<RoomEvent> roomEvents;
/// when the participant joined the room
@@ -169,9 +170,10 @@ abstract class Participant<T extends TrackPublication>
trackPublications[pub.sid] = pub;
}
// Must implement
// Must be implemented by subclasses.
Future<void> unpublishTrack(String trackSid, {bool notify = true});
/// Convenience method to unpublish all tracks.
Future<void> unpublishAllTracks({bool notify = true}) async {
final trackSids = trackPublications.keys.toSet();
for (final trackid in trackSids) {
@@ -179,31 +181,26 @@ abstract class Participant<T extends TrackPublication>
}
}
//
// Equality operators
// Object is considered equal when sid is equal
//
@override
int get hashCode => sid.hashCode;
@override
bool operator ==(Object other) => other is Participant && sid == other.sid;
/// Convenience property to check whether [TrackSource.camera] is published or not.
bool isCameraEnabled() {
return !(getTrackPublicationBySource(TrackSource.camera)?.muted ?? true);
}
/// Convenience property to check whether [TrackSource.microphone] is published or not.
bool isMicrophoneEnabled() {
return !(getTrackPublicationBySource(TrackSource.microphone)?.muted ??
true);
}
/// Convenience property to check whether [TrackSource.screenShareVideo] is published or not.
bool isScreenShareEnabled() {
return !(getTrackPublicationBySource(TrackSource.screenShareVideo)?.muted ??
true);
}
/// Find a track publication by its [TrackSource]
/// 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.
T? getTrackPublicationBySource(TrackSource source) {
if (source == TrackSource.unknown) return null;
// try to find by source
@@ -226,4 +223,12 @@ abstract class Participant<T extends TrackPublication>
e.kind == lk_models.TrackType.AUDIO &&
e.name == Track.screenShareName));
}
// Equality operators
// Object is considered equal when sid is equal
@override
int get hashCode => sid.hashCode;
@override
bool operator ==(Object other) => other is Participant && sid == other.sid;
}