Skip to content

Commit d90ee89

Browse files
authored
FFI v0.12.2 & RPC (#62)
* build * build * ffi * ffi * rpc * version * remove * perform * handle * fwd * proto * Changes * rpc * wip * wip * works * working * docstring * remove some files * gi * fmt * clean * docs * docs
1 parent 47692c7 commit d90ee89

File tree

33 files changed

+27856
-8853
lines changed

33 files changed

+27856
-8853
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,11 @@ crashlytics-build.properties
7272
/[Aa]ssets/[Ss]treamingAssets/aa/*
7373

7474
.DS_Store
75+
76+
downloads~
77+
78+
/Runtime/Plugins/ffi-*/LICENSE.md
79+
/Runtime/Plugins/ffi-*/LICENSE.md.meta
80+
/Runtime/Plugins/ffi-*/livekit_ffi.h
81+
/Runtime/Plugins/ffi-*/livekit_ffi.h.meta
82+

BuildScripts~/generate_proto.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ protoc \
1414
$FFI_PROTOCOL/room.proto \
1515
$FFI_PROTOCOL/stats.proto \
1616
$FFI_PROTOCOL/track.proto \
17-
$FFI_PROTOCOL/video_frame.proto
17+
$FFI_PROTOCOL/video_frame.proto \
18+
$FFI_PROTOCOL/rpc.proto

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,5 +187,71 @@ void TrackSubscribed(IRemoteTrack track, RemoteTrackPublication publication, Rem
187187
}
188188
```
189189

190+
### RPC
191+
192+
Perform your own predefined method calls from one participant to another.
193+
194+
This feature is especially powerful when used with [Agents](https://docs.livekit.io/agents), for instance to forward LLM function calls to your client application.
195+
196+
The following is a brief overview but [more detail is available in the documentation](https://docs.livekit.io/home/client/data/rpc).
197+
198+
#### Registering an RPC method
199+
200+
The participant who implements the method and will receive its calls must first register support. Your method handler will be an async callback that receives an `RpcInvocationData` object:
201+
202+
```cs
203+
// Define your method handler
204+
async Task<string> HandleGreeting(RpcInvocationData data)
205+
{
206+
Debug.Log($"Received greeting from {data.CallerIdentity}: {data.Payload}");
207+
return $"Hello, {data.CallerIdentity}!";
208+
}
209+
210+
// Register the method after connection to the room
211+
room.LocalParticipant.RegisterRpcMethod("greet", HandleGreeting);
212+
```
213+
214+
In addition to the payload, `RpcInvocationData` also contains `responseTimeout`, which informs you the maximum time available to return a response. If you are unable to respond in time, the call will result in an error on the caller's side.
215+
216+
#### Performing an RPC request
217+
218+
The caller may initiate an RPC call using coroutines:
219+
220+
```cs
221+
IEnumerator PerformRpcCoroutine()
222+
{
223+
var rpcCall = room.LocalParticipant.PerformRpc(new PerformRpcParams
224+
{
225+
DestinationIdentity = "recipient-identity",
226+
Method = "greet",
227+
Payload = "Hello from RPC!"
228+
});
229+
230+
yield return rpcCall;
231+
232+
if (rpcCall.IsError)
233+
{
234+
Debug.Log($"RPC call failed: {rpcCall.Error}");
235+
}
236+
else
237+
{
238+
Debug.Log($"RPC response: {rpcCall.Payload}");
239+
}
240+
}
241+
242+
// Start the coroutine from another MonoBehaviour method
243+
StartCoroutine(PerformRpcCoroutine());
244+
```
245+
246+
You may find it useful to adjust the `ResponseTimeout` parameter, which indicates the amount of time you will wait for a response. We recommend keeping this value as low as possible while still satisfying the constraints of your application.
247+
248+
#### Errors
249+
250+
LiveKit is a dynamic realtime environment and RPC calls can fail for various reasons.
251+
252+
You may throw errors of the type `RpcError` with a string `message` in an RPC method handler and they will be received on the caller's side with the message intact. Other errors will not be transmitted and will instead arrive to the caller as `1500` ("Application Error"). Other built-in errors are detailed in the [docs](https://docs.livekit.io/home/client/data/rpc/#errors).
253+
254+
255+
190256
<!--BEGIN_REPO_NAV-->
191257
<!--END_REPO_NAV-->
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:e65058144f16acff227cc61a858e4c182fc380c97afff7c0459bd52ead8afb2d
3-
size 358056168
2+
oid sha256:5fd9b298ae66a88c346a03629af3475d2a215e22356277792981cf5b855e74eb
3+
size 359507616
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:751f5a57a7df1fce186932a0df982779eca1f72d353ae8aa14cb95dc3d159f22
3-
size 358436416
2+
oid sha256:4786f6180a75f74f14a2d0454c02ddcc53db93aa2d821c930e39e061d154aef3
3+
size 359886296
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:48148f57ea581441bacca9f626cb05e5b71d2daf35b8e5f6f7175419194d039d
3-
size 22565440
2+
oid sha256:370b4a32e6d7ac686a771a4db04ecbee610bee377897584f7cdbc568c5109775
3+
size 22696912
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:e1675b1f16d5ff5353bc0baa5a7f3bef55e5ffcede19f5677f9d485f00f6d94c
3-
size 28385888
2+
oid sha256:39fb1bfa98b746b623cccb77bf6bd326512d9bb954aa9cba295dd81fc338d9a2
3+
size 28603344
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:10984d692094d6577292b9a02ec6fd79541017ba26620480620fa8fcd53b2471
3-
size 19624056
2+
oid sha256:a91d337cd0b9420d89c236327bc3af7450b99fa43c15c2eea2349c09577c3a1b
3+
size 19756648
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:0cc771595be30fa1685325f50cc9b2b7f74685268815b1ae0308ec123f3ca33b
3-
size 24542288
2+
oid sha256:e3181159a91e648a38bfbcf3b1ad9eff0883dd34b656ab719cf8cd2f9a5d3062
3+
size 24739672
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:fc747f843712625fe0c429361f47b80fab1cc7c1737b5fb5ebc8bb182106d3bc
3-
size 19926016
2+
oid sha256:a42298995303dd1cbed71e2eec5ebe515358d4b332c96573aedf4ff76ee0deaf
3+
size 20203520

0 commit comments

Comments
 (0)