Pass adaptive_stream when connecting (#109)
* impl * ignore fvm files * Update pubspec.lock * comment
This commit is contained in:
+4
-1
@@ -79,4 +79,7 @@ build/
|
||||
*.code-workspace
|
||||
|
||||
# Windows
|
||||
_build
|
||||
_build
|
||||
|
||||
# FVM
|
||||
.fvm/
|
||||
|
||||
@@ -61,7 +61,9 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
// remember url and token for reconnect
|
||||
String? url;
|
||||
String? token;
|
||||
ConnectOptions? connectOptions;
|
||||
|
||||
ConnectOptions connectOptions;
|
||||
RoomOptions roomOptions;
|
||||
|
||||
bool _subscriberPrimary = false;
|
||||
|
||||
@@ -71,6 +73,8 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
late final _signalListener = signalClient.createListener(synchronized: true);
|
||||
|
||||
Engine({
|
||||
required this.connectOptions,
|
||||
required this.roomOptions,
|
||||
SignalClient? signalClient,
|
||||
PeerConnectionCreate? peerConnectionCreate,
|
||||
}) : signalClient = signalClient ?? SignalClient(LiveKitWebSocket.connect),
|
||||
@@ -93,12 +97,15 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
|
||||
Future<void> connect(
|
||||
String url,
|
||||
String token,
|
||||
String token, {
|
||||
ConnectOptions? connectOptions,
|
||||
) async {
|
||||
RoomOptions? roomOptions,
|
||||
}) async {
|
||||
this.url = url;
|
||||
this.token = token;
|
||||
this.connectOptions = connectOptions ?? const ConnectOptions();
|
||||
// update new options (if exists)
|
||||
this.connectOptions = connectOptions ?? this.connectOptions;
|
||||
this.roomOptions = roomOptions ?? this.roomOptions;
|
||||
|
||||
_updateConnectionState(ConnectionState.connecting);
|
||||
|
||||
@@ -108,6 +115,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
url,
|
||||
token,
|
||||
connectOptions: this.connectOptions,
|
||||
roomOptions: this.roomOptions,
|
||||
);
|
||||
|
||||
// wait for join response
|
||||
@@ -262,6 +270,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
url!,
|
||||
token!,
|
||||
connectOptions: connectOptions,
|
||||
roomOptions: roomOptions,
|
||||
reconnect: true,
|
||||
);
|
||||
|
||||
@@ -320,7 +329,6 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
|
||||
// RTCConfiguration? config;
|
||||
// use server-provided iceServers if not provided by user
|
||||
final connectOptions = this.connectOptions ?? const ConnectOptions();
|
||||
final serverIceServers =
|
||||
_serverProvidedIceServers.map((e) => e.toSDKType()).toList();
|
||||
|
||||
|
||||
+19
-22
@@ -27,8 +27,11 @@ import 'engine.dart';
|
||||
/// * active speakers are different
|
||||
/// {@category Room}
|
||||
class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
|
||||
// expose engine's params
|
||||
/// connection state of the room
|
||||
ConnectionState get connectionState => engine.connectionState;
|
||||
ConnectOptions get connectOptions => engine.connectOptions;
|
||||
RoomOptions get roomOptions => engine.roomOptions;
|
||||
|
||||
/// map of SID to RemoteParticipant
|
||||
UnmodifiableMapView<String, RemoteParticipant> get participants =>
|
||||
@@ -64,12 +67,6 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
|
||||
UnmodifiableListView<Participant>(_activeSpeakers);
|
||||
List<Participant> _activeSpeakers = [];
|
||||
|
||||
ConnectOptions? get connectOptions => _connectOptions;
|
||||
ConnectOptions? _connectOptions;
|
||||
|
||||
RoomOptions? get roomOptions => _roomOptions;
|
||||
RoomOptions? _roomOptions;
|
||||
|
||||
final Engine engine;
|
||||
// suppport for multiple event listeners
|
||||
late final EventsListener<EngineEvent> _engineListener;
|
||||
@@ -77,12 +74,15 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
|
||||
late final EventsListener<SignalEvent> _signalListener;
|
||||
|
||||
Room({
|
||||
ConnectOptions? connectOptions,
|
||||
RoomOptions? roomOptions,
|
||||
ConnectOptions connectOptions = const ConnectOptions(),
|
||||
RoomOptions roomOptions = const RoomOptions(),
|
||||
Engine? engine,
|
||||
}) : _connectOptions = connectOptions,
|
||||
_roomOptions = roomOptions,
|
||||
engine = engine ?? Engine() {
|
||||
}) : engine = engine ??
|
||||
Engine(
|
||||
connectOptions: connectOptions,
|
||||
roomOptions: roomOptions,
|
||||
) {
|
||||
//
|
||||
_engineListener = this.engine.createListener();
|
||||
_setUpEngineListeners();
|
||||
|
||||
@@ -116,13 +116,13 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
|
||||
String token, {
|
||||
ConnectOptions? connectOptions,
|
||||
RoomOptions? roomOptions,
|
||||
}) async {
|
||||
// update options if provided
|
||||
_connectOptions = connectOptions ?? _connectOptions;
|
||||
_roomOptions = roomOptions ?? this.roomOptions;
|
||||
|
||||
return engine.connect(url, token, this.connectOptions);
|
||||
}
|
||||
}) =>
|
||||
engine.connect(
|
||||
url,
|
||||
token,
|
||||
connectOptions: connectOptions,
|
||||
roomOptions: roomOptions,
|
||||
);
|
||||
|
||||
void _setUpSignalListeners() => _signalListener
|
||||
..on<SignalJoinResponseEvent>((event) {
|
||||
@@ -157,10 +157,8 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
|
||||
..on<SignalStreamStateUpdatedEvent>(
|
||||
(event) => _onSignalStreamStateUpdateEvent(event.updates))
|
||||
..on<SignalSubscribedQualityUpdatedEvent>((event) {
|
||||
// Signal for Dynacast
|
||||
final options = roomOptions ?? const RoomOptions();
|
||||
// Dynacast is off or is unsupported
|
||||
if (!options.dynacast || _serverVersion == '0.15.1') {
|
||||
if (!roomOptions.dynacast || _serverVersion == '0.15.1') {
|
||||
logger.fine('Received subscribed quality update'
|
||||
' but Dynacast is off or server version is not supported.');
|
||||
return;
|
||||
@@ -456,7 +454,6 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
|
||||
}
|
||||
|
||||
Future<void> _sendSyncState() async {
|
||||
final connectOptions = this.connectOptions ?? const ConnectOptions();
|
||||
final sendUnSub = connectOptions.autoSubscribe;
|
||||
final participantTracks =
|
||||
participants.values.map((e) => e.participantTracks());
|
||||
|
||||
@@ -45,13 +45,15 @@ class SignalClient extends Disposable with EventsEmittable<SignalEvent> {
|
||||
Future<void> connect(
|
||||
String uriString,
|
||||
String token, {
|
||||
ConnectOptions? connectOptions,
|
||||
required ConnectOptions connectOptions,
|
||||
required RoomOptions roomOptions,
|
||||
bool reconnect = false,
|
||||
}) async {
|
||||
final rtcUri = await Utils.buildUri(
|
||||
uriString,
|
||||
token: token,
|
||||
connectOptions: connectOptions,
|
||||
roomOptions: roomOptions,
|
||||
reconnect: reconnect,
|
||||
);
|
||||
|
||||
@@ -85,6 +87,7 @@ class SignalClient extends Disposable with EventsEmittable<SignalEvent> {
|
||||
uriString,
|
||||
token: token,
|
||||
connectOptions: connectOptions,
|
||||
roomOptions: roomOptions,
|
||||
validate: true,
|
||||
forceSecure: rtcUri.isSecureScheme,
|
||||
);
|
||||
|
||||
@@ -50,14 +50,14 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
|
||||
|
||||
// Use defaultPublishOptions if options is null
|
||||
publishOptions =
|
||||
publishOptions ?? room.roomOptions?.defaultAudioPublishOptions;
|
||||
publishOptions ?? room.roomOptions.defaultAudioPublishOptions;
|
||||
|
||||
final trackInfo = await room.engine.addTrack(
|
||||
cid: track.getCid(),
|
||||
name: track.name,
|
||||
kind: track.kind,
|
||||
source: track.source.toPBType(),
|
||||
dtx: publishOptions?.dtx,
|
||||
dtx: publishOptions.dtx,
|
||||
);
|
||||
|
||||
await track.start();
|
||||
@@ -105,7 +105,7 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
|
||||
|
||||
// Use defaultPublishOptions if options is null
|
||||
publishOptions =
|
||||
publishOptions ?? room.roomOptions?.defaultVideoPublishOptions;
|
||||
publishOptions ?? room.roomOptions.defaultVideoPublishOptions;
|
||||
|
||||
// use constraints passed to getUserMedia by default
|
||||
VideoDimensions dimensions = track.currentOptions.params.dimensions;
|
||||
@@ -202,8 +202,7 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
|
||||
|
||||
final track = pub.track;
|
||||
if (track != null) {
|
||||
final roomOptions = room.roomOptions ?? const RoomOptions();
|
||||
if (roomOptions.stopLocalTrackOnUnpublish) {
|
||||
if (room.roomOptions.stopLocalTrackOnUnpublish) {
|
||||
await track.stop();
|
||||
}
|
||||
|
||||
@@ -304,15 +303,15 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
|
||||
} else if (enabled) {
|
||||
if (source == TrackSource.camera) {
|
||||
final track = await LocalVideoTrack.createCameraTrack(
|
||||
room.roomOptions?.defaultCameraCaptureOptions);
|
||||
room.roomOptions.defaultCameraCaptureOptions);
|
||||
return await publishVideoTrack(track);
|
||||
} else if (source == TrackSource.microphone) {
|
||||
final track = await LocalAudioTrack.create(
|
||||
room.roomOptions?.defaultAudioCaptureOptions);
|
||||
room.roomOptions.defaultAudioCaptureOptions);
|
||||
return await publishAudioTrack(track);
|
||||
} else if (source == TrackSource.screenShareVideo) {
|
||||
final track = await LocalVideoTrack.createScreenShareTrack(
|
||||
room.roomOptions?.defaultScreenShareCaptureOptions);
|
||||
room.roomOptions.defaultScreenShareCaptureOptions);
|
||||
return await publishVideoTrack(track);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import '../core/signal_client.dart';
|
||||
import '../events.dart';
|
||||
import '../extensions.dart';
|
||||
import '../logger.dart';
|
||||
import '../options.dart';
|
||||
import '../participant/remote.dart';
|
||||
import '../proto/livekit_models.pb.dart' as lk_models;
|
||||
import '../proto/livekit_rtc.pb.dart' as lk_rtc;
|
||||
@@ -187,7 +186,7 @@ class RemoteTrackPublication<T extends RemoteTrack>
|
||||
_cancelPendingTrackSettingsUpdateRequest?.call();
|
||||
_visibilityTimer?.cancel();
|
||||
|
||||
final roomOptions = participant.room.roomOptions ?? const RoomOptions();
|
||||
final roomOptions = participant.room.roomOptions;
|
||||
if (roomOptions.adaptiveStream && newValue is RemoteVideoTrack) {
|
||||
// Start monitoring visibility
|
||||
_visibilityTimer = Timer.periodic(
|
||||
|
||||
+3
-3
@@ -141,13 +141,12 @@ class Utils {
|
||||
static Future<Uri> buildUri(
|
||||
String uriString, {
|
||||
required String token,
|
||||
ConnectOptions? connectOptions,
|
||||
required ConnectOptions connectOptions,
|
||||
required RoomOptions roomOptions,
|
||||
bool reconnect = false,
|
||||
bool validate = false,
|
||||
bool forceSecure = false,
|
||||
}) async {
|
||||
connectOptions ??= const ConnectOptions();
|
||||
|
||||
final Uri uri = Uri.parse(uriString);
|
||||
|
||||
final useSecure = uri.isSecureScheme || forceSecure;
|
||||
@@ -173,6 +172,7 @@ class Utils {
|
||||
queryParameters: <String, String>{
|
||||
'access_token': token,
|
||||
'auto_subscribe': connectOptions.autoSubscribe ? '1' : '0',
|
||||
'adaptive_stream': roomOptions.adaptiveStream ? '1' : '0',
|
||||
if (reconnect) 'reconnect': '1',
|
||||
'protocol': connectOptions.protocolVersion.toStringValue(),
|
||||
'sdk': 'flutter',
|
||||
|
||||
+6
-6
@@ -42,7 +42,7 @@ packages:
|
||||
name: build
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.2.1"
|
||||
version: "2.3.0"
|
||||
built_collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -56,7 +56,7 @@ packages:
|
||||
name: built_value
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "8.1.4"
|
||||
version: "8.2.0"
|
||||
characters:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -112,7 +112,7 @@ packages:
|
||||
name: dart_style
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.2.2"
|
||||
version: "2.2.3"
|
||||
dart_webrtc:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -126,7 +126,7 @@ packages:
|
||||
name: device_info_plus
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.2.2"
|
||||
version: "3.2.3"
|
||||
device_info_plus_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -140,7 +140,7 @@ packages:
|
||||
name: device_info_plus_macos
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.2.2"
|
||||
version: "2.2.3"
|
||||
device_info_plus_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -405,7 +405,7 @@ packages:
|
||||
name: source_gen
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.1"
|
||||
version: "1.2.2"
|
||||
source_span:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -12,6 +12,9 @@ import '../mock/test_data.dart';
|
||||
import '../mock/websocket_mock.dart';
|
||||
|
||||
void main() {
|
||||
const connectOptions = ConnectOptions();
|
||||
const roomOptions = RoomOptions();
|
||||
|
||||
late SignalClient client;
|
||||
late MockWebSocketConnector connector;
|
||||
setUp(() async {
|
||||
@@ -29,7 +32,12 @@ void main() {
|
||||
predicate<SignalConnectionStateUpdatedEvent>(
|
||||
(event) => event.newState == ConnectionState.connected),
|
||||
]));
|
||||
await client.connect(exampleUri, token);
|
||||
await client.connect(
|
||||
exampleUri,
|
||||
token,
|
||||
connectOptions: connectOptions,
|
||||
roomOptions: roomOptions,
|
||||
);
|
||||
});
|
||||
test('reconnect', () async {
|
||||
expect(
|
||||
@@ -41,13 +49,24 @@ void main() {
|
||||
event.newState == ConnectionState.connected &&
|
||||
event.didReconnect == true),
|
||||
]));
|
||||
await client.connect(exampleUri, token, reconnect: true);
|
||||
await client.connect(
|
||||
exampleUri,
|
||||
token,
|
||||
connectOptions: connectOptions,
|
||||
roomOptions: roomOptions,
|
||||
reconnect: true,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('messaging', () {
|
||||
test('join', () async {
|
||||
await client.connect(exampleUri, token);
|
||||
await client.connect(
|
||||
exampleUri,
|
||||
token,
|
||||
connectOptions: connectOptions,
|
||||
roomOptions: roomOptions,
|
||||
);
|
||||
expect(client.events.streamCtrl.stream,
|
||||
emits(isA<SignalJoinResponseEvent>()));
|
||||
connector.handlers?.onData!(joinResponse.writeToBuffer());
|
||||
|
||||
@@ -15,7 +15,11 @@ class E2EContainer {
|
||||
wsConnector = MockWebSocketConnector();
|
||||
client = SignalClient(wsConnector.connect);
|
||||
engine = Engine(
|
||||
signalClient: client, peerConnectionCreate: MockPeerConnection.create);
|
||||
signalClient: client,
|
||||
peerConnectionCreate: MockPeerConnection.create,
|
||||
connectOptions: const ConnectOptions(),
|
||||
roomOptions: const RoomOptions(),
|
||||
);
|
||||
room = Room(engine: engine);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user