more docs
This commit is contained in:
@@ -74,7 +74,7 @@ class _ControlsWidgetState extends State<ControlsWidget> {
|
|||||||
if (track == null) return;
|
if (track == null) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final newPosition = position.swap();
|
final newPosition = position.switched();
|
||||||
await track.setCameraPosition(newPosition);
|
await track.setCameraPosition(newPosition);
|
||||||
setState(() {
|
setState(() {
|
||||||
position = newPosition;
|
position = newPosition;
|
||||||
|
|||||||
@@ -85,7 +85,8 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
|
|||||||
return pub;
|
return pub;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Publish a video track to the room
|
/// Publish a [LocalVideoTrack] to the [Room].
|
||||||
|
/// For most cases, using [setCameraEnabled] would be simpler and recommended.
|
||||||
Future<LocalTrackPublication<LocalVideoTrack>> publishVideoTrack(
|
Future<LocalTrackPublication<LocalVideoTrack>> publishVideoTrack(
|
||||||
LocalVideoTrack track, {
|
LocalVideoTrack track, {
|
||||||
VideoPublishOptions? publishOptions,
|
VideoPublishOptions? publishOptions,
|
||||||
@@ -174,7 +175,7 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
|
|||||||
return pub;
|
return pub;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unpublish a track that's already published
|
/// Unpublish a [LocalTrackPublication] that's already published by this [LocalParticipant].
|
||||||
@override
|
@override
|
||||||
Future<void> unpublishTrack(String trackSid, {bool notify = true}) async {
|
Future<void> unpublishTrack(String trackSid, {bool notify = true}) async {
|
||||||
logger.finer('Unpublish track sid: $trackSid, notify: $notify');
|
logger.finer('Unpublish track sid: $trackSid, notify: $notify');
|
||||||
@@ -279,6 +280,7 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A convenience method to publish a track for a specific [TrackSource].
|
/// A convenience method to publish a track for a specific [TrackSource].
|
||||||
|
/// This is the recommended method to publish tracks.
|
||||||
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)');
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ import '../publication/track_publication.dart';
|
|||||||
import '../room.dart';
|
import '../room.dart';
|
||||||
import '../support/disposable.dart';
|
import '../support/disposable.dart';
|
||||||
import '../track/track.dart';
|
import '../track/track.dart';
|
||||||
|
import '../track/local.dart';
|
||||||
import '../types.dart';
|
import '../types.dart';
|
||||||
import 'remote_participant.dart';
|
import 'remote_participant.dart';
|
||||||
|
import 'local_participant.dart';
|
||||||
|
|
||||||
/// Represents a Participant in the room, notifies changes via delegates as
|
/// Represents a Participant in the room, notifies changes via delegates as
|
||||||
/// well as ChangeNotifier/providers.
|
/// well as ChangeNotifier/providers.
|
||||||
@@ -63,27 +65,29 @@ abstract class Participant<T extends TrackPublication>
|
|||||||
return DateTime.now();
|
return DateTime.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// if participant is currently speaking
|
/// if [Participant] is currently speaking.
|
||||||
bool get isSpeaking => _isSpeaking;
|
bool get isSpeaking => _isSpeaking;
|
||||||
|
|
||||||
/// true if participant is publishing an audio track and is muted
|
/// true if [Participant] is publishing an [AudioTrack] and is muted.
|
||||||
bool get isMuted => audioTracks.firstOrNull?.muted ?? true;
|
bool get isMuted => audioTracks.firstOrNull?.muted ?? true;
|
||||||
|
|
||||||
|
/// true if this [Participant] has more than 1 [AudioTrack].
|
||||||
bool get hasAudio => audioTracks.isNotEmpty;
|
bool get hasAudio => audioTracks.isNotEmpty;
|
||||||
|
|
||||||
|
/// true if this [Participant] has more than 1 [VideoTrack].
|
||||||
bool get hasVideo => videoTracks.isNotEmpty;
|
bool get hasVideo => videoTracks.isNotEmpty;
|
||||||
|
|
||||||
/// Connection quality of the participant
|
/// Connection quality between the [Participant] and the Server.
|
||||||
ConnectionQuality get connectionQuality => _connectionQuality;
|
ConnectionQuality get connectionQuality => _connectionQuality;
|
||||||
|
|
||||||
/// tracks that are subscribed to
|
/// [Track]s that this [Participant] is subscribed to.
|
||||||
List<T> 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<T> get videoTracks;
|
List<T> get videoTracks;
|
||||||
|
|
||||||
// Must be implemented by child class
|
// Must be implemented by child class.
|
||||||
List<T> get audioTracks;
|
List<T> get audioTracks;
|
||||||
|
|
||||||
/// for internal use
|
/// for internal use
|
||||||
@@ -220,11 +224,11 @@ abstract class Participant<T extends TrackPublication>
|
|||||||
e.name == Track.screenShareName));
|
e.name == Track.screenShareName));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equality operators
|
/// (Equality operator) [Participant.hashCode] is same as [sid.hashCode].
|
||||||
// Object is considered equal when sid is equal
|
|
||||||
@override
|
@override
|
||||||
int get hashCode => sid.hashCode;
|
int get hashCode => sid.hashCode;
|
||||||
|
|
||||||
|
/// (Equality operator) [Participant] is considered equal when [sid]'s are equal.
|
||||||
@override
|
@override
|
||||||
bool operator ==(Object other) => other is Participant && sid == other.sid;
|
bool operator ==(Object other) => other is Participant && sid == other.sid;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,22 @@ import '../proto/livekit_models.pb.dart' as lk_models;
|
|||||||
import '../types.dart';
|
import '../types.dart';
|
||||||
import 'options.dart';
|
import 'options.dart';
|
||||||
import 'track.dart';
|
import 'track.dart';
|
||||||
|
import '../track/local/audio.dart';
|
||||||
|
import '../track/local/video.dart';
|
||||||
|
import '../track/remote/audio.dart';
|
||||||
|
import '../track/remote/video.dart';
|
||||||
|
import '../events.dart';
|
||||||
|
import '../participant/remote_participant.dart';
|
||||||
|
|
||||||
|
/// Used to group [LocalVideoTrack] and [RemoteVideoTrack].
|
||||||
mixin VideoTrack on Track {}
|
mixin VideoTrack on Track {}
|
||||||
|
|
||||||
|
/// Used to group [LocalAudioTrack] and [RemoteAudioTrack].
|
||||||
mixin AudioTrack on Track {}
|
mixin AudioTrack on Track {}
|
||||||
|
|
||||||
|
/// Base class for [LocalAudioTrack] and [LocalVideoTrack].
|
||||||
abstract class LocalTrack extends Track {
|
abstract class LocalTrack extends Track {
|
||||||
// Options used for this track
|
/// Options used for this track
|
||||||
abstract LocalTrackOptions currentOptions;
|
abstract LocalTrackOptions currentOptions;
|
||||||
|
|
||||||
LocalTrack(
|
LocalTrack(
|
||||||
@@ -31,8 +41,9 @@ abstract class LocalTrack extends Track {
|
|||||||
mediaStreamTrack,
|
mediaStreamTrack,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Only local tracks can set muted.
|
/// Mutes this [LocalTrack]. This will stop the sending of track data
|
||||||
// Returns true if muted, false if unchanged.
|
/// and notify the [RemoteParticipant] with [TrackMutedEvent].
|
||||||
|
/// Returns true if muted, false if unchanged.
|
||||||
Future<bool> mute() async {
|
Future<bool> mute() async {
|
||||||
logger.fine('LocalTrack.mute() muted: $muted');
|
logger.fine('LocalTrack.mute() muted: $muted');
|
||||||
if (muted) return false; // already muted
|
if (muted) return false; // already muted
|
||||||
@@ -44,7 +55,9 @@ abstract class LocalTrack extends Track {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if unmuted, false if unchanged.
|
/// Un-mutes this [LocalTrack]. This will re-start the sending of track data
|
||||||
|
/// and notify the [RemoteParticipant] with [TrackUnmutedEvent].
|
||||||
|
/// Returns true if un-muted, false if unchanged.
|
||||||
Future<bool> unmute() async {
|
Future<bool> unmute() async {
|
||||||
logger.fine('LocalTrack.unmute() muted: $muted');
|
logger.fine('LocalTrack.unmute() muted: $muted');
|
||||||
if (!muted) return false; // already un-muted
|
if (!muted) return false; // already un-muted
|
||||||
@@ -67,7 +80,7 @@ abstract class LocalTrack extends Track {
|
|||||||
return didStop;
|
return didStop;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a [rtc.MediaStream] from LocalTrackOptions.
|
/// Creates a [rtc.MediaStream] from [LocalTrackOptions].
|
||||||
@internal
|
@internal
|
||||||
static Future<rtc.MediaStream> createStream(
|
static Future<rtc.MediaStream> createStream(
|
||||||
LocalTrackOptions options,
|
LocalTrackOptions options,
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
||||||
|
import '../track/local/video.dart';
|
||||||
|
import '../track/local/audio.dart';
|
||||||
|
|
||||||
enum LocalVideoTrackType {
|
/// A type that represents front or back of the camera.
|
||||||
camera,
|
|
||||||
display,
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CameraPosition {
|
enum CameraPosition {
|
||||||
front,
|
front,
|
||||||
back,
|
back,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convenience extension for [CameraPosition].
|
||||||
extension CameraPositionExt on CameraPosition {
|
extension CameraPositionExt on CameraPosition {
|
||||||
/// Return a [CameraPosition] which front and back is switched.
|
/// Return a [CameraPosition] which front and back is switched.
|
||||||
CameraPosition swap() => {
|
CameraPosition switched() => {
|
||||||
CameraPosition.front: CameraPosition.back,
|
CameraPosition.front: CameraPosition.back,
|
||||||
CameraPosition.back: CameraPosition.front,
|
CameraPosition.back: CameraPosition.front,
|
||||||
}[this]!;
|
}[this]!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Options used when creating a [LocalVideoTrack] that captures the camera.
|
||||||
class CameraTrackOptions extends LocalVideoTrackOptions {
|
class CameraTrackOptions extends LocalVideoTrackOptions {
|
||||||
final CameraPosition cameraPosition;
|
final CameraPosition cameraPosition;
|
||||||
|
|
||||||
@@ -44,6 +44,7 @@ class CameraTrackOptions extends LocalVideoTrackOptions {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Options used when creating a [LocalVideoTrack] that captures the screen.
|
||||||
class ScreenShareTrackOptions extends LocalVideoTrackOptions {
|
class ScreenShareTrackOptions extends LocalVideoTrackOptions {
|
||||||
const ScreenShareTrackOptions();
|
const ScreenShareTrackOptions();
|
||||||
}
|
}
|
||||||
@@ -55,7 +56,7 @@ abstract class LocalTrackOptions {
|
|||||||
Map<String, dynamic> toMediaConstraintsMap();
|
Map<String, dynamic> toMediaConstraintsMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Options when creating a LocalVideoTrack.
|
/// Base class for options when creating a [LocalVideoTrack].
|
||||||
abstract class LocalVideoTrackOptions extends LocalTrackOptions {
|
abstract class LocalVideoTrackOptions extends LocalTrackOptions {
|
||||||
// final LocalVideoTrackType type;
|
// final LocalVideoTrackType type;
|
||||||
final VideoParameters params;
|
final VideoParameters params;
|
||||||
@@ -69,6 +70,7 @@ abstract class LocalVideoTrackOptions extends LocalTrackOptions {
|
|||||||
params.toMediaConstraintsMap();
|
params.toMediaConstraintsMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A type that represents video encoding information.
|
||||||
class VideoEncoding {
|
class VideoEncoding {
|
||||||
final int maxFramerate;
|
final int maxFramerate;
|
||||||
final int maxBitrate;
|
final int maxBitrate;
|
||||||
@@ -83,6 +85,7 @@ class VideoEncoding {
|
|||||||
'${runtimeType}(maxFramerate: ${maxFramerate}, maxBitrate: ${maxBitrate})';
|
'${runtimeType}(maxFramerate: ${maxFramerate}, maxBitrate: ${maxBitrate})';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convenience extension for [VideoEncoding].
|
||||||
extension VideoEncodingExt on VideoEncoding {
|
extension VideoEncodingExt on VideoEncoding {
|
||||||
rtc.RTCRtpEncoding toRTCRtpEncoding({
|
rtc.RTCRtpEncoding toRTCRtpEncoding({
|
||||||
String? rid,
|
String? rid,
|
||||||
@@ -242,12 +245,29 @@ class VideoParameters {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Options when creating an LocalAudioTrack. Placeholder for now.
|
/// Options used when creating a [LocalAudioTrack].
|
||||||
class LocalAudioTrackOptions extends LocalTrackOptions {
|
class LocalAudioTrackOptions extends LocalTrackOptions {
|
||||||
|
/// Attempt to use noiseSuppression option (if supported by the platform)
|
||||||
|
/// See https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackSettings/noiseSuppression
|
||||||
|
/// Defaults to true.
|
||||||
final bool noiseSuppression;
|
final bool noiseSuppression;
|
||||||
|
|
||||||
|
/// Attempt to use echoCancellation option (if supported by the platform)
|
||||||
|
/// See https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackSettings/echoCancellation
|
||||||
|
/// Defaults to true.
|
||||||
final bool echoCancellation;
|
final bool echoCancellation;
|
||||||
|
|
||||||
|
/// Attempt to use autoGainControl option (if supported by the platform)
|
||||||
|
/// See https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints/autoGainControl
|
||||||
|
/// Defaults to true.
|
||||||
final bool autoGainControl;
|
final bool autoGainControl;
|
||||||
|
|
||||||
|
/// Attempt to use highPassFilter options (if supported by the platform)
|
||||||
|
/// Defaults to false.
|
||||||
final bool highPassFilter;
|
final bool highPassFilter;
|
||||||
|
|
||||||
|
/// Attempt to use typingNoiseDetection option (if supported by the platform)
|
||||||
|
/// Defaults to true.
|
||||||
final bool typingNoiseDetection;
|
final bool typingNoiseDetection;
|
||||||
|
|
||||||
const LocalAudioTrackOptions({
|
const LocalAudioTrackOptions({
|
||||||
|
|||||||
Reference in New Issue
Block a user