Skip to content

Commit 9de81dc

Browse files
bumpup and clamp connection timeout, fix the comment (#893)
This PR fixes the comment for PerformRpcParams, bump up the RPC connection time out to 7 seconds, and also clamp the connection response timeout if needed. See similar PR on JS SDK: livekit/client-sdk-js#1694 Co-authored-by: Hiroshi Horie <[email protected]>
1 parent 438d60b commit 9de81dc

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/src/participant/local.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,16 +1043,21 @@ extension RPCMethods on LocalParticipant {
10431043
final requestId = Uuid().v4();
10441044
final completer = Completer<String>();
10451045

1046-
final maxRoundTripLatency = Duration(seconds: 2);
1046+
final maxRoundTripLatency = Duration(seconds: 7);
1047+
final minEffectiveTimeout = const Duration(milliseconds: 1000);
10471048

10481049
try {
1050+
final effectiveTimeout = Duration(
1051+
milliseconds: (params.responseTimeoutMs.inMilliseconds - maxRoundTripLatency.inMilliseconds)
1052+
.clamp(minEffectiveTimeout.inMilliseconds, double.infinity)
1053+
.toInt(),
1054+
);
10491055
await publishRpcRequest(
10501056
destinationIdentity: params.destinationIdentity,
10511057
requestId: requestId,
10521058
method: params.method,
10531059
payload: params.payload,
1054-
responseTimeout:
1055-
Duration(milliseconds: params.responseTimeoutMs.inMilliseconds - maxRoundTripLatency.inMilliseconds),
1060+
responseTimeout: effectiveTimeout,
10561061
version: kRpcVesion,
10571062
);
10581063

lib/src/types/rpc.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ class PerformRpcParams {
1010
/// The payload of the request.
1111
String payload;
1212

13-
/// The maximum time the caller will wait for a response.
13+
/// Timeout for receiving a response after the initial connection (in milliseconds).
14+
/// If a value less than 8000 ms is provided, it will be automatically clamped to 8000 ms
15+
/// to ensure sufficient time for round-trip latency buffering.
16+
/// Default: 15000 ms.
1417
Duration responseTimeoutMs;
1518

1619
PerformRpcParams({
1720
required this.destinationIdentity,
1821
required this.method,
1922
required this.payload,
20-
this.responseTimeoutMs = const Duration(milliseconds: 10000),
23+
this.responseTimeoutMs = const Duration(milliseconds: 15000),
2124
});
2225
}
2326

0 commit comments

Comments
 (0)