Skip to content

Commit 84a60c1

Browse files
authored
Add rpc v2 long info case to example (#685)
1 parent c5ce5a6 commit 84a60c1

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

examples/rpc.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ async def main():
3434
except Exception as error:
3535
print("Error:", error)
3636

37+
try:
38+
print("\n\nRunning send long info example...")
39+
await perform_send_very_long_info(callers_room)
40+
except Exception as error:
41+
print("Error:", error)
42+
3743
try:
3844
print("\n\nRunning error handling example...")
3945
await perform_divide(callers_room)
@@ -93,6 +99,17 @@ async def arrival_method(
9399
await asyncio.sleep(2)
94100
return "Welcome and have a wonderful day!"
95101

102+
@greeters_room.local_participant.register_rpc_method("exchanging-long-info")
103+
async def exchanging_long_info_method(
104+
data: RpcInvocationData,
105+
):
106+
print(
107+
f"[Greeter] {data.caller_identity} has arrived and said that its long info is "
108+
f'{len(data.payload)} chars long and starts with: "{data.payload[:20]}..."'
109+
)
110+
await asyncio.sleep(2)
111+
return "Y" * 20_000
112+
96113
@math_genius_room.local_participant.register_rpc_method("square-root")
97114
async def square_root_method(
98115
data: RpcInvocationData,
@@ -146,6 +163,23 @@ async def perform_greeting(room: rtc.Room):
146163
raise
147164

148165

166+
async def perform_send_very_long_info(room: rtc.Room):
167+
print("[Caller] Sending the greeter a very long message")
168+
try:
169+
response = await room.local_participant.perform_rpc(
170+
destination_identity="greeter",
171+
method="exchanging-long-info",
172+
payload="X" * 20_000,
173+
)
174+
print(
175+
f"[Caller] The greeter's long info is {len(response)} chars long and "
176+
f'starts with: "{response[:20]}..."'
177+
)
178+
except Exception as error:
179+
print(f"[Caller] RPC call failed: {error}")
180+
raise
181+
182+
149183
async def perform_square_root(room: rtc.Room):
150184
print("[Caller] What's the square root of 16?")
151185
try:

0 commit comments

Comments
 (0)