livekit-client 2.5.10 → 2.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. package/README.md +54 -0
  2. package/dist/livekit-client.e2ee.worker.js.map +1 -1
  3. package/dist/livekit-client.e2ee.worker.mjs.map +1 -1
  4. package/dist/livekit-client.esm.mjs +431 -45
  5. package/dist/livekit-client.esm.mjs.map +1 -1
  6. package/dist/livekit-client.umd.js +1 -1
  7. package/dist/livekit-client.umd.js.map +1 -1
  8. package/dist/src/api/SignalClient.d.ts.map +1 -1
  9. package/dist/src/index.d.ts +1 -0
  10. package/dist/src/index.d.ts.map +1 -1
  11. package/dist/src/room/PCTransport.d.ts +2 -0
  12. package/dist/src/room/PCTransport.d.ts.map +1 -1
  13. package/dist/src/room/PCTransportManager.d.ts.map +1 -1
  14. package/dist/src/room/RTCEngine.d.ts.map +1 -1
  15. package/dist/src/room/RegionUrlProvider.d.ts.map +1 -1
  16. package/dist/src/room/Room.d.ts.map +1 -1
  17. package/dist/src/room/errors.d.ts +2 -2
  18. package/dist/src/room/errors.d.ts.map +1 -1
  19. package/dist/src/room/participant/LocalParticipant.d.ts +56 -0
  20. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  21. package/dist/src/room/rpc.d.ts +96 -0
  22. package/dist/src/room/rpc.d.ts.map +1 -0
  23. package/dist/src/room/track/RemoteAudioTrack.d.ts +1 -1
  24. package/dist/src/room/track/RemoteAudioTrack.d.ts.map +1 -1
  25. package/dist/src/room/track/RemoteVideoTrack.d.ts +2 -1
  26. package/dist/src/room/track/RemoteVideoTrack.d.ts.map +1 -1
  27. package/dist/src/room/track/utils.d.ts +2 -2
  28. package/dist/src/room/track/utils.d.ts.map +1 -1
  29. package/dist/ts4.2/src/index.d.ts +2 -0
  30. package/dist/ts4.2/src/room/PCTransport.d.ts +2 -0
  31. package/dist/ts4.2/src/room/errors.d.ts +2 -2
  32. package/dist/ts4.2/src/room/participant/LocalParticipant.d.ts +56 -0
  33. package/dist/ts4.2/src/room/rpc.d.ts +96 -0
  34. package/dist/ts4.2/src/room/track/RemoteAudioTrack.d.ts +1 -1
  35. package/dist/ts4.2/src/room/track/RemoteVideoTrack.d.ts +2 -1
  36. package/dist/ts4.2/src/room/track/utils.d.ts +2 -2
  37. package/package.json +2 -2
  38. package/src/api/SignalClient.ts +19 -3
  39. package/src/index.ts +2 -0
  40. package/src/room/PCTransport.ts +42 -29
  41. package/src/room/PCTransportManager.ts +6 -1
  42. package/src/room/RTCEngine.ts +13 -3
  43. package/src/room/RegionUrlProvider.ts +3 -1
  44. package/src/room/Room.ts +9 -3
  45. package/src/room/errors.ts +2 -2
  46. package/src/room/participant/LocalParticipant.test.ts +304 -0
  47. package/src/room/participant/LocalParticipant.ts +340 -1
  48. package/src/room/rpc.ts +172 -0
  49. package/src/room/track/RemoteAudioTrack.ts +1 -1
  50. package/src/room/track/RemoteVideoTrack.ts +1 -1
  51. package/src/room/track/utils.ts +1 -6
package/README.md CHANGED
@@ -304,12 +304,66 @@ setLogExtension((level: LogLevel, msg: string, context: object) => {
304
304
  });
305
305
  ```
306
306
 
307
+ ### RPC
308
+
309
+ Perform your own predefined method calls from one participant to another.
310
+
311
+ 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.
312
+
313
+ #### Registering an RPC method
314
+
315
+ The participant who implements the method and will receive its calls must first register support:
316
+
317
+ ```typescript
318
+ room.localParticipant?.registerRpcMethod(
319
+ // method name - can be any string that makes sense for your application
320
+ 'greet',
321
+
322
+ // method handler - will be called when the method is invoked by a RemoteParticipant
323
+ async (data: RpcInvocationData) => {
324
+ console.log(`Received greeting from ${data.callerIdentity}: ${data.payload}`);
325
+ return `Hello, ${data.callerIdentity}!`;
326
+ }
327
+ );
328
+ ```
329
+
330
+ In addition to the payload, your handler will also receive `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.
331
+
332
+ #### Performing an RPC request
333
+
334
+ The caller may then initiate an RPC call like so:
335
+
336
+ ```typescript
337
+ try {
338
+ const response = await room.localParticipant!.performRpc({
339
+ destinationIdentity: 'recipient-identity',
340
+ method: 'greet',
341
+ payload: 'Hello from RPC!',
342
+ });
343
+ console.log('RPC response:', response);
344
+ } catch (error) {
345
+ console.error('RPC call failed:', error);
346
+ }
347
+ ```
348
+
349
+ 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.
350
+
351
+ #### Errors
352
+
353
+ LiveKit is a dynamic realtime environment and calls can fail for various reasons.
354
+
355
+ 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 `RpcError`.
356
+
307
357
  ## Examples
308
358
 
309
359
  ### Demo App
310
360
 
311
361
  [examples/demo](examples/demo/) contains a demo webapp that uses the SDK. Run it with `pnpm install && pnpm examples:demo`
312
362
 
363
+ ### RPC Demo
364
+
365
+ [examples/rpc](examples/rpc/) contains a demo webapp that uses the SDK to showcase the RPC capabilities. Run it with `pnpm install && pnpm dev` from the `examples/rpc` directory.
366
+
313
367
  ## Browser Support
314
368
 
315
369
  | Browser | Desktop OS | Mobile OS |