chore: Make timeouts configurable. (#191)
This commit is contained in:
+21
-5
@@ -1,7 +1,23 @@
|
||||
class Timeouts {
|
||||
static const connection = Duration(seconds: 10);
|
||||
static const debounce = Duration(milliseconds: 100);
|
||||
static const publish = Duration(seconds: 10);
|
||||
static const peerConnection = Duration(seconds: 10);
|
||||
static const iceRestart = Duration(seconds: 10);
|
||||
final Duration connection;
|
||||
final Duration debounce;
|
||||
final Duration publish;
|
||||
final Duration peerConnection;
|
||||
final Duration iceRestart;
|
||||
|
||||
const Timeouts({
|
||||
required this.connection,
|
||||
required this.debounce,
|
||||
required this.publish,
|
||||
required this.peerConnection,
|
||||
required this.iceRestart,
|
||||
});
|
||||
|
||||
static const Timeouts defaultTimeouts = Timeouts(
|
||||
connection: Duration(seconds: 10),
|
||||
debounce: Duration(milliseconds: 100),
|
||||
publish: Duration(seconds: 10),
|
||||
peerConnection: Duration(seconds: 10),
|
||||
iceRestart: Duration(seconds: 10),
|
||||
);
|
||||
}
|
||||
|
||||
+10
-10
@@ -6,7 +6,6 @@ import 'package:collection/collection.dart';
|
||||
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../constants.dart';
|
||||
import '../events.dart';
|
||||
import '../exceptions.dart';
|
||||
import '../extensions.dart';
|
||||
@@ -136,7 +135,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
|
||||
// wait for join response
|
||||
await _signalListener.waitFor<SignalJoinResponseEvent>(
|
||||
duration: Timeouts.connection,
|
||||
duration: this.connectOptions.timeouts.connection,
|
||||
onTimeout: () => throw ConnectException(),
|
||||
);
|
||||
|
||||
@@ -145,7 +144,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
// wait until engine is connected
|
||||
await events.waitFor<EnginePeerStateUpdatedEvent>(
|
||||
filter: (event) => event.isPrimary && event.state.isConnected(),
|
||||
duration: Timeouts.connection,
|
||||
duration: this.connectOptions.timeouts.connection,
|
||||
onTimeout: () => throw ConnectException(),
|
||||
);
|
||||
|
||||
@@ -199,7 +198,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
// wait for response, or timeout
|
||||
final event = await _signalListener.waitFor<SignalLocalTrackPublishedEvent>(
|
||||
filter: (event) => event.cid == cid,
|
||||
duration: Timeouts.publish,
|
||||
duration: connectOptions.timeouts.publish,
|
||||
onTimeout: () => throw TrackPublishException(),
|
||||
);
|
||||
|
||||
@@ -242,7 +241,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
logger.fine('Waiting for publisher to ice-connect...');
|
||||
await events.waitFor<EnginePublisherPeerStateUpdatedEvent>(
|
||||
filter: (event) => event.state.isConnected(),
|
||||
duration: Timeouts.peerConnection,
|
||||
duration: connectOptions.timeouts.peerConnection,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -252,7 +251,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
logger.fine('Waiting for data channel ${reliability} to open...');
|
||||
await events.waitFor<PublisherDataChannelStateUpdatedEvent>(
|
||||
filter: (event) => event.type == reliability,
|
||||
duration: Timeouts.connection,
|
||||
duration: connectOptions.timeouts.connection,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -313,7 +312,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
|
||||
await events.waitFor<EnginePeerStateUpdatedEvent>(
|
||||
filter: (event) => event.isPrimary && event.state.isConnected(),
|
||||
duration: Timeouts.iceRestart,
|
||||
duration: connectOptions.timeouts.iceRestart,
|
||||
onTimeout: () => throw ConnectException(),
|
||||
);
|
||||
}
|
||||
@@ -361,9 +360,10 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
iceTransportPolicy: RTCIceTransportPolicy.relay);
|
||||
}
|
||||
|
||||
publisher = await Transport.create(_peerConnectionCreate, rtcConfiguration);
|
||||
subscriber =
|
||||
await Transport.create(_peerConnectionCreate, rtcConfiguration);
|
||||
publisher = await Transport.create(_peerConnectionCreate,
|
||||
rtcConfig: rtcConfiguration, connectOptions: connectOptions);
|
||||
subscriber = await Transport.create(_peerConnectionCreate,
|
||||
rtcConfig: rtcConfiguration, connectOptions: connectOptions);
|
||||
|
||||
publisher?.pc.onIceCandidate = (rtc.RTCIceCandidate candidate) {
|
||||
logger.fine('publisher onIceCandidate');
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
||||
import 'package:livekit_client/src/options.dart';
|
||||
|
||||
import '../constants.dart';
|
||||
import '../extensions.dart';
|
||||
import '../internal/types.dart';
|
||||
import '../logger.dart';
|
||||
@@ -23,9 +23,10 @@ class Transport extends Disposable {
|
||||
bool renegotiate = false;
|
||||
TransportOnOffer? onOffer;
|
||||
Function? _cancelDebounce;
|
||||
ConnectOptions connectOptions;
|
||||
|
||||
// private constructor
|
||||
Transport._(this.pc) {
|
||||
Transport._(this.pc, this.connectOptions) {
|
||||
//
|
||||
onDispose(() async {
|
||||
_cancelDebounce?.call();
|
||||
@@ -59,17 +60,18 @@ class Transport extends Disposable {
|
||||
}
|
||||
|
||||
static Future<Transport> create(PeerConnectionCreate peerConnectionCreate,
|
||||
[RTCConfiguration? rtcConfig]) async {
|
||||
{RTCConfiguration? rtcConfig,
|
||||
required ConnectOptions connectOptions}) async {
|
||||
rtcConfig ??= const RTCConfiguration();
|
||||
logger.fine('[PCTransport] creating ${rtcConfig.toMap()}');
|
||||
final pc = await peerConnectionCreate(rtcConfig.toMap());
|
||||
return Transport._(pc);
|
||||
return Transport._(pc, connectOptions);
|
||||
}
|
||||
|
||||
late final negotiate = Utils.createDebounceFunc(
|
||||
(void _) => createAndSendOffer(),
|
||||
cancelFunc: (f) => _cancelDebounce = f,
|
||||
wait: Timeouts.debounce,
|
||||
wait: connectOptions.timeouts.debounce,
|
||||
);
|
||||
|
||||
Future<void> setRemoteDescription(rtc.RTCSessionDescription sd) async {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'constants.dart';
|
||||
import 'core/room.dart';
|
||||
import 'publication/remote.dart';
|
||||
import 'track/local/audio.dart';
|
||||
@@ -38,10 +39,13 @@ class ConnectOptions {
|
||||
/// The protocol version to be used. Usually this doesn't need to be modified.
|
||||
final ProtocolVersion protocolVersion;
|
||||
|
||||
final Timeouts timeouts;
|
||||
|
||||
const ConnectOptions({
|
||||
this.autoSubscribe = true,
|
||||
this.rtcConfiguration = const RTCConfiguration(),
|
||||
this.protocolVersion = ProtocolVersion.v8,
|
||||
this.timeouts = Timeouts.defaultTimeouts,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../constants.dart';
|
||||
import '../core/room.dart';
|
||||
import '../events.dart';
|
||||
import '../exceptions.dart';
|
||||
@@ -88,7 +87,7 @@ class RemoteParticipant extends Participant<RemoteTrackPublication> {
|
||||
final event = await events.waitFor<TrackPublishedEvent>(
|
||||
filter: (event) =>
|
||||
event.participant == this && event.publication.sid == trackSid,
|
||||
duration: Timeouts.publish,
|
||||
duration: room.connectOptions.timeouts.publish,
|
||||
onTimeout: () => throw TrackSubscriptionExceptionEvent(
|
||||
participant: this,
|
||||
sid: trackSid,
|
||||
|
||||
Reference in New Issue
Block a user