Skip to content

Commit 27aa6c3

Browse files
committed
feat: add max round trip latency
1 parent 7209a4c commit 27aa6c3

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

livekit-rtc/livekit/rtc/participant.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@
5959
from ._proto import data_track_pb2 as proto_data_track
6060

6161

62+
# Default maximum amount of time it should ever take for an RPC request to reach the
63+
# destination and for the ACK to come back. Set to 7 seconds to account for various
64+
# relay timeouts and retries in LiveKit Cloud that occur in rare cases. Most callers
65+
# should not need to change this.
66+
DEFAULT_MAX_ROUND_TRIP_LATENCY = 7.0
67+
68+
6269
class PublishTrackError(Exception):
6370
def __init__(self, message: str) -> None:
6471
self.message = message
@@ -324,6 +331,7 @@ async def perform_rpc(
324331
method: str,
325332
payload: str,
326333
response_timeout: Optional[float] = None,
334+
max_round_trip_latency: float = DEFAULT_MAX_ROUND_TRIP_LATENCY,
327335
) -> str:
328336
"""
329337
Initiate an RPC call to a remote participant.
@@ -333,6 +341,12 @@ async def perform_rpc(
333341
method (str): The method name to call
334342
payload (str): The method payload
335343
response_timeout (Optional[float]): Timeout for receiving a response after initial connection
344+
max_round_trip_latency (float): The maximum amount of time it should ever take for an RPC
345+
request to reach the destination and for the ACK to come back. Defaults to 7 seconds to
346+
account for various relay timeouts and retries in LiveKit Cloud that occur in rare cases.
347+
Most callers should not need to change this, but it can be increased to tolerate
348+
high-latency networks where RPC requests are backed up behind other messages on the
349+
data channel.
336350
337351
Returns:
338352
str: The response payload
@@ -347,6 +361,7 @@ async def perform_rpc(
347361
req.perform_rpc.payload = payload
348362
if response_timeout is not None:
349363
req.perform_rpc.response_timeout_ms = int(response_timeout * 1000)
364+
req.perform_rpc.max_round_trip_latency_ms = int(max_round_trip_latency * 1000)
350365

351366
queue = FfiClient.instance.queue.subscribe()
352367
try:

0 commit comments

Comments
 (0)