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