Skip to content

Commit 1a52c3a

Browse files
fix(rtc): raise error from Rust SDK in participant methods
1 parent c8ec56d commit 1a52c3a

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

livekit-rtc/livekit/rtc/participant.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ def __init__(self, message: str) -> None:
8080
self.message = message
8181

8282

83+
class ParticipantError(Exception):
84+
def __init__(self, message: str) -> None:
85+
self.message = message
86+
8387
class Participant(ABC):
8488
def __init__(self, owned_info: proto_participant.OwnedParticipant) -> None:
8589
self._info = owned_info.info
@@ -491,9 +495,11 @@ async def set_metadata(self, metadata: str) -> None:
491495
queue = FfiClient.instance.queue.subscribe()
492496
try:
493497
resp = FfiClient.instance.request(req)
494-
await queue.wait_for(
498+
cb: proto_ffi.FfiEvent = await queue.wait_for(
495499
lambda e: e.set_local_metadata.async_id == resp.set_local_metadata.async_id
496500
)
501+
if cb.set_local_metadata.error:
502+
raise ParticipantError(cb.set_local_metadata.error)
497503
finally:
498504
FfiClient.instance.queue.unsubscribe(queue)
499505

@@ -513,9 +519,12 @@ async def set_name(self, name: str) -> None:
513519
queue = FfiClient.instance.queue.subscribe()
514520
try:
515521
resp = FfiClient.instance.request(req)
516-
await queue.wait_for(
522+
cb: proto_ffi.FfiEvent = await queue.wait_for(
517523
lambda e: e.set_local_name.async_id == resp.set_local_name.async_id
518524
)
525+
526+
if cb.set_local_name.error:
527+
raise ParticipantError(cb.set_local_name.error)
519528
finally:
520529
FfiClient.instance.queue.unsubscribe(queue)
521530

@@ -543,9 +552,13 @@ async def set_attributes(self, attributes: dict[str, str]) -> None:
543552
queue = FfiClient.instance.queue.subscribe()
544553
try:
545554
resp = FfiClient.instance.request(req)
546-
await queue.wait_for(
555+
cb: proto_ffi.FfiEvent = await queue.wait_for(
547556
lambda e: e.set_local_attributes.async_id == resp.set_local_attributes.async_id
548557
)
558+
559+
if cb.set_local_attributes.error:
560+
raise ParticipantError(cb.set_local_attributes.error)
561+
549562
finally:
550563
FfiClient.instance.queue.unsubscribe(queue)
551564

0 commit comments

Comments
 (0)