more docs & clean up
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
|
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
@@ -11,6 +10,7 @@ import '../events.dart';
|
|||||||
import '../exceptions.dart';
|
import '../exceptions.dart';
|
||||||
import '../extensions.dart';
|
import '../extensions.dart';
|
||||||
import '../internal/events.dart';
|
import '../internal/events.dart';
|
||||||
|
import '../internal/types.dart';
|
||||||
import '../logger.dart';
|
import '../logger.dart';
|
||||||
import '../managers/delay.dart';
|
import '../managers/delay.dart';
|
||||||
import '../managers/event.dart';
|
import '../managers/event.dart';
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
|||||||
|
|
||||||
import '../constants.dart';
|
import '../constants.dart';
|
||||||
import '../extensions.dart';
|
import '../extensions.dart';
|
||||||
|
import '../internal/types.dart';
|
||||||
import '../logger.dart';
|
import '../logger.dart';
|
||||||
import '../support/disposable.dart';
|
import '../support/disposable.dart';
|
||||||
import '../types.dart';
|
import '../types.dart';
|
||||||
|
|||||||
@@ -1,18 +1,32 @@
|
|||||||
|
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
@internal
|
@internal
|
||||||
|
@immutable
|
||||||
class RendererVisibility {
|
class RendererVisibility {
|
||||||
final String rendererId;
|
final String rendererId;
|
||||||
final String trackId;
|
final String trackId;
|
||||||
final bool visible;
|
final bool visible;
|
||||||
final Size size;
|
final Size size;
|
||||||
RendererVisibility({
|
const RendererVisibility({
|
||||||
required this.rendererId,
|
required this.rendererId,
|
||||||
required this.trackId,
|
required this.trackId,
|
||||||
required this.visible,
|
required this.visible,
|
||||||
required this.size,
|
required this.size,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@internal
|
||||||
|
@immutable
|
||||||
|
class RTCOfferOptions {
|
||||||
|
final bool iceRestart;
|
||||||
|
|
||||||
|
const RTCOfferOptions({
|
||||||
|
this.iceRestart = false,
|
||||||
|
});
|
||||||
|
|
||||||
|
Map<String, dynamic> toMap() => <String, dynamic>{
|
||||||
|
if (iceRestart) 'iceRestart': true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -86,22 +86,6 @@ abstract class EventsListenable<T> extends Disposable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @override
|
|
||||||
// @mustCallSuper
|
|
||||||
// Future<bool> dispose() async {
|
|
||||||
// // mark as disposed
|
|
||||||
// final didDispose = await super.dispose();
|
|
||||||
// if (didDispose && _listeners.isNotEmpty) {
|
|
||||||
// // Stop listening to all events
|
|
||||||
// logger.fine('${objectId} dispose() cancelling ${_listeners.length} event(s)');
|
|
||||||
// for (final listener in _listeners) {
|
|
||||||
// await listener.cancel();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return didDispose;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// listens to all events, guaranteed to be cancelled on dispose
|
// listens to all events, guaranteed to be cancelled on dispose
|
||||||
CancelListenFunc listen(FutureOr<void> Function(T) onEvent) {
|
CancelListenFunc listen(FutureOr<void> Function(T) onEvent) {
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
import '../core/room.dart';
|
import '../core/room.dart';
|
||||||
import '../events.dart';
|
import '../events.dart';
|
||||||
@@ -19,7 +20,7 @@ import 'participant.dart';
|
|||||||
/// Represents the current participant in the room. Instance of [LocalParticipant] is automatically
|
/// 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].
|
/// created after successfully connecting to a [Room] and will be accessible from [Room.localParticipant].
|
||||||
class LocalParticipant extends Participant<LocalTrackPublication> {
|
class LocalParticipant extends Participant<LocalTrackPublication> {
|
||||||
//
|
@internal
|
||||||
LocalParticipant({
|
LocalParticipant({
|
||||||
required Room room,
|
required Room room,
|
||||||
required lk_models.ParticipantInfo info,
|
required lk_models.ParticipantInfo info,
|
||||||
@@ -240,10 +241,6 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
|
|||||||
await room.engine.sendDataPacket(packet);
|
await room.engine.sendDataPacket(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
List<LocalTrackPublication> get subscribedTracks =>
|
|
||||||
super.subscribedTracks.cast<LocalTrackPublication>().toList();
|
|
||||||
|
|
||||||
/// A convenience property to get all video tracks.
|
/// A convenience property to get all video tracks.
|
||||||
@override
|
@override
|
||||||
List<LocalTrackPublication<LocalVideoTrack>> get videoTracks =>
|
List<LocalTrackPublication<LocalVideoTrack>> get videoTracks =>
|
||||||
|
|||||||
@@ -80,21 +80,16 @@ abstract class Participant<T extends TrackPublication>
|
|||||||
/// Connection quality between the [Participant] and the Server.
|
/// Connection quality between the [Participant] and the Server.
|
||||||
ConnectionQuality get connectionQuality => _connectionQuality;
|
ConnectionQuality get connectionQuality => _connectionQuality;
|
||||||
|
|
||||||
/// [Track]s that this [Participant] is subscribed to.
|
|
||||||
List<T> get subscribedTracks =>
|
|
||||||
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
|
|
||||||
/// {@nodoc}
|
|
||||||
@internal
|
@internal
|
||||||
bool get hasInfo => _participantInfo != null;
|
bool get hasInfo => _participantInfo != null;
|
||||||
|
|
||||||
|
@internal
|
||||||
Participant({
|
Participant({
|
||||||
required this.room,
|
required this.room,
|
||||||
required this.sid,
|
required this.sid,
|
||||||
|
|||||||
@@ -17,22 +17,7 @@ import 'participant.dart';
|
|||||||
|
|
||||||
/// Represents other participant in the [Room].
|
/// Represents other participant in the [Room].
|
||||||
class RemoteParticipant extends Participant<RemoteTrackPublication> {
|
class RemoteParticipant extends Participant<RemoteTrackPublication> {
|
||||||
@override
|
@internal
|
||||||
List<RemoteTrackPublication> get subscribedTracks =>
|
|
||||||
super.subscribedTracks.cast<RemoteTrackPublication>().toList();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<RemoteTrackPublication<RemoteVideoTrack>> get videoTracks =>
|
|
||||||
trackPublications.values
|
|
||||||
.whereType<RemoteTrackPublication<RemoteVideoTrack>>()
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<RemoteTrackPublication<RemoteAudioTrack>> get audioTracks =>
|
|
||||||
trackPublications.values
|
|
||||||
.whereType<RemoteTrackPublication<RemoteAudioTrack>>()
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
RemoteParticipant({
|
RemoteParticipant({
|
||||||
required Room room,
|
required Room room,
|
||||||
required String sid,
|
required String sid,
|
||||||
@@ -43,6 +28,7 @@ class RemoteParticipant extends Participant<RemoteTrackPublication> {
|
|||||||
identity: identity,
|
identity: identity,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@internal
|
||||||
RemoteParticipant.fromInfo({
|
RemoteParticipant.fromInfo({
|
||||||
required Room room,
|
required Room room,
|
||||||
required lk_models.ParticipantInfo info,
|
required lk_models.ParticipantInfo info,
|
||||||
@@ -54,6 +40,25 @@ class RemoteParticipant extends Participant<RemoteTrackPublication> {
|
|||||||
updateFromInfo(info);
|
updateFromInfo(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A convenience property to get all video tracks.
|
||||||
|
@override
|
||||||
|
List<RemoteTrackPublication<RemoteVideoTrack>> get videoTracks =>
|
||||||
|
trackPublications.values
|
||||||
|
.whereType<RemoteTrackPublication<RemoteVideoTrack>>()
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
/// A convenience property to get all audio tracks.
|
||||||
|
@override
|
||||||
|
List<RemoteTrackPublication<RemoteAudioTrack>> get audioTracks =>
|
||||||
|
trackPublications.values
|
||||||
|
.whereType<RemoteTrackPublication<RemoteAudioTrack>>()
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
List<RemoteTrackPublication> get subscribedTracks => trackPublications.values
|
||||||
|
.where((e) => e.subscribed)
|
||||||
|
.cast<RemoteTrackPublication>()
|
||||||
|
.toList();
|
||||||
|
|
||||||
RemoteTrackPublication? getTrackPublication(String sid) {
|
RemoteTrackPublication? getTrackPublication(String sid) {
|
||||||
final pub = trackPublications[sid];
|
final pub = trackPublications[sid];
|
||||||
if (pub is RemoteTrackPublication) return pub;
|
if (pub is RemoteTrackPublication) return pub;
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ import '../proto/livekit_models.pb.dart' as lk_models;
|
|||||||
import '../track/local/local.dart';
|
import '../track/local/local.dart';
|
||||||
import 'track_publication.dart';
|
import 'track_publication.dart';
|
||||||
|
|
||||||
|
/// A [TrackPublication] which belongs to the [LocalParticipant].
|
||||||
class LocalTrackPublication<T extends LocalTrack> extends TrackPublication<T> {
|
class LocalTrackPublication<T extends LocalTrack> extends TrackPublication<T> {
|
||||||
|
/// The [LocalParticipant] this instance belongs to.
|
||||||
@override
|
@override
|
||||||
final LocalParticipant participant;
|
final LocalParticipant participant;
|
||||||
|
|
||||||
|
|||||||
+13
-14
@@ -3,9 +3,12 @@ import 'dart:math' as math;
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'extensions.dart';
|
import 'extensions.dart';
|
||||||
|
import 'participant/participant.dart';
|
||||||
|
|
||||||
typedef CancelListenFunc = Function();
|
typedef CancelListenFunc = Function();
|
||||||
|
|
||||||
|
/// Protocol version to use when connecting to server.
|
||||||
|
/// Usually it's not recommended to change this.
|
||||||
enum ProtocolVersion {
|
enum ProtocolVersion {
|
||||||
v2,
|
v2,
|
||||||
v3,
|
v3,
|
||||||
@@ -13,12 +16,14 @@ enum ProtocolVersion {
|
|||||||
v5,
|
v5,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Connection state type used throughout the SDK.
|
||||||
enum ConnectionState {
|
enum ConnectionState {
|
||||||
disconnected,
|
disconnected,
|
||||||
connected,
|
connected,
|
||||||
reconnecting,
|
reconnecting,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Connection quality between the [Participant] and server.
|
||||||
enum ConnectionQuality {
|
enum ConnectionQuality {
|
||||||
unknown,
|
unknown,
|
||||||
poor,
|
poor,
|
||||||
@@ -26,6 +31,7 @@ enum ConnectionQuality {
|
|||||||
excellent,
|
excellent,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reliability used for publishing data through data channel.
|
||||||
enum Reliability {
|
enum Reliability {
|
||||||
reliable,
|
reliable,
|
||||||
lossy,
|
lossy,
|
||||||
@@ -39,6 +45,8 @@ enum TrackSource {
|
|||||||
screenShareAudio,
|
screenShareAudio,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The state of track data stream.
|
||||||
|
/// This is controlled by server to optimize bandwidth.
|
||||||
enum StreamState {
|
enum StreamState {
|
||||||
paused,
|
paused,
|
||||||
active,
|
active,
|
||||||
@@ -49,6 +57,7 @@ enum CloseReason {
|
|||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The reason why a track failed to publish.
|
||||||
enum TrackSubscribeFailReason {
|
enum TrackSubscribeFailReason {
|
||||||
invalidServerResponse,
|
invalidServerResponse,
|
||||||
notTrackMetadataFound,
|
notTrackMetadataFound,
|
||||||
@@ -56,24 +65,13 @@ enum TrackSubscribeFailReason {
|
|||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The iceTransportPolicy used for [RTCConfiguration].
|
||||||
|
/// See https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection
|
||||||
enum RTCIceTransportPolicy {
|
enum RTCIceTransportPolicy {
|
||||||
all,
|
all,
|
||||||
relay,
|
relay,
|
||||||
}
|
}
|
||||||
|
|
||||||
@immutable
|
|
||||||
class RTCOfferOptions {
|
|
||||||
final bool iceRestart;
|
|
||||||
|
|
||||||
const RTCOfferOptions({
|
|
||||||
this.iceRestart = false,
|
|
||||||
});
|
|
||||||
|
|
||||||
Map<String, dynamic> toMap() => <String, dynamic>{
|
|
||||||
if (iceRestart) 'iceRestart': true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@immutable
|
@immutable
|
||||||
class RTCConfiguration {
|
class RTCConfiguration {
|
||||||
final int? iceCandidatePoolSize;
|
final int? iceCandidatePoolSize;
|
||||||
@@ -135,6 +133,7 @@ class RTCIceServer {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A simple class that represents dimensions of video.
|
||||||
@immutable
|
@immutable
|
||||||
class VideoDimensions {
|
class VideoDimensions {
|
||||||
final int width;
|
final int width;
|
||||||
@@ -146,7 +145,7 @@ class VideoDimensions {
|
|||||||
);
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() => 'VideoDimensions(${width}×${height})';
|
String toString() => '${runtimeType}(${width}x${height})';
|
||||||
|
|
||||||
/// Returns the larger value
|
/// Returns the larger value
|
||||||
int max() => math.max(width, height);
|
int max() => math.max(width, height);
|
||||||
|
|||||||
Reference in New Issue
Block a user