tests and mocks for e2e testing (#78)
* tests and mocks for e2e testing * formatting * fix analyze errors
This commit is contained in:
+17
-10
@@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
||||
import 'package:livekit_client/src/support/websocket.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../constants.dart';
|
||||
@@ -28,11 +29,10 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
static const _lossyDCLabel = '_lossy';
|
||||
static const _reliableDCLabel = '_reliable';
|
||||
|
||||
// Reference to the Room
|
||||
final Room room;
|
||||
|
||||
final SignalClient signalClient;
|
||||
|
||||
final PeerConnectionCreate _peerConnectionCreate;
|
||||
|
||||
@internal
|
||||
PCTransport? publisher;
|
||||
|
||||
@@ -60,6 +60,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
// remember url and token for reconnect
|
||||
String? url;
|
||||
String? token;
|
||||
ConnectOptions? connectOptions;
|
||||
|
||||
bool _subscriberPrimary = false;
|
||||
|
||||
@@ -71,9 +72,11 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
final delays = CancelableDelayManager();
|
||||
|
||||
Engine({
|
||||
required this.room,
|
||||
SignalClient? signalClient,
|
||||
}) : signalClient = signalClient ?? SignalClient() {
|
||||
PeerConnectionCreate? peerConnectionCreate,
|
||||
}) : signalClient = signalClient ?? SignalClient(LiveKitWebSocket.connect),
|
||||
_peerConnectionCreate =
|
||||
peerConnectionCreate ?? rtc.createPeerConnection {
|
||||
if (kDebugMode) {
|
||||
// log all EngineEvents
|
||||
events.listen((event) => logger.fine('[EngineEvent] $objectId ${event}'));
|
||||
@@ -92,9 +95,11 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
Future<void> connect(
|
||||
String url,
|
||||
String token,
|
||||
ConnectOptions? connectOptions,
|
||||
) async {
|
||||
this.url = url;
|
||||
this.token = token;
|
||||
this.connectOptions = connectOptions ?? const ConnectOptions();
|
||||
|
||||
_updateConnectionState(ConnectionState.connecting);
|
||||
|
||||
@@ -103,7 +108,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
await signalClient.connect(
|
||||
url,
|
||||
token,
|
||||
connectOptions: room.connectOptions,
|
||||
connectOptions: this.connectOptions,
|
||||
);
|
||||
|
||||
// wait for join response
|
||||
@@ -272,7 +277,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
await signalClient.connect(
|
||||
url!,
|
||||
token!,
|
||||
connectOptions: room.connectOptions,
|
||||
connectOptions: connectOptions,
|
||||
reconnect: true,
|
||||
);
|
||||
|
||||
@@ -331,7 +336,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
|
||||
// RTCConfiguration? config;
|
||||
// use server-provided iceServers if not provided by user
|
||||
final connectOptions = room.connectOptions ?? const ConnectOptions();
|
||||
final connectOptions = this.connectOptions ?? const ConnectOptions();
|
||||
final serverIceServers =
|
||||
_serverProvidedIceServers.map((e) => e.toSDKType()).toList();
|
||||
|
||||
@@ -342,8 +347,10 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
.copyWith(iceServers: serverIceServers);
|
||||
}
|
||||
|
||||
publisher = await PCTransport.create(rtcConfiguration);
|
||||
subscriber = await PCTransport.create(rtcConfiguration);
|
||||
publisher =
|
||||
await PCTransport.create(_peerConnectionCreate, rtcConfiguration);
|
||||
subscriber =
|
||||
await PCTransport.create(_peerConnectionCreate, rtcConfiguration);
|
||||
|
||||
publisher?.pc.onIceCandidate = (rtc.RTCIceCandidate candidate) {
|
||||
logger.fine('publisher onIceCandidate');
|
||||
|
||||
Reference in New Issue
Block a user