LiveKit Protocol

repository·main·Indexed 40 days ago

https://github.com/livekit/protocol

Protocol definitions and generated protobuf stubs for LiveKit, featuring the participant RPC (RoomRPC) registry for structured communication between participants and the LiveKit server. Includes definitions for agent-related communication, room data structures, real-time communication protocols, and Egress/Ingress services.

Tokens
667
Snippets
2
Records
5
Agent score
50%

What's inside LiveKit

  1. Overview of LiveKit protocol stubs

    main
    This repository contains the generated protobuf stubs for the LiveKit protocol. It provides the core data structures and communication definitions used for participant RPCs (RoomRPC) and other real-time communication protocols within the LiveKit ecosystem.
  2. Understand LiveKit participant RPCs registry (roomrpc)

    main
    The roomrpc registry contains protobuf definitions for well-known LiveKit participant Remote Procedure Calls (RPCs). These definitions specify the request and response messages used when participants interact with the LiveKit server or other participants via RPC.
  3. Follow the naming convention for roomrpc proto files

    main

    To ensure consistency and avoid collisions, all proto files in the roomrpc registry must follow a specific naming convention: roomrpc_<type>_v<vers>.proto.

    Note that the version is a single sequential number, not a semantic version (semver).

    Example: roomrpc_sip_v1.proto

  4. Implement versioned RPC services and messages

    main

    When defining versioned RPCs, follow these rules to maintain compatibility and avoid Go package name collisions:

    1. Directory Structure: Place each participant type or API in its own directory under roomrpc named <type>rpc.
    2. Service Naming: Append V<vers> as a suffix to the service definition.
    3. Message Naming: Append V<vers> as a suffix to all request and response message types.
    4. Method Naming: Do not include the version in the RPC method name itself, as the version is already captured in the service name.

    Example Implementation:

    service MyServiceV1 {
      rpc DoSomething(DoSomethingV1Request) returns (DoSomethingV1Response);
    }
    
    message DoSomethingV1Request {}
    
    message DoSomethingV1Response {}
  5. Import LiveKit Protocol modules

    main

    The @livekit/protocol package provides generated Protobuf stubs for various LiveKit services. You can import specific service namespaces or utility types like protoInt64 and Timestamp from the main entry point.

    Commonly used namespaces include:

    • AgentSession, AgentInference, AgentText, AgentDev: For agent-related communication.
    • livekit_agent_dispatch_pb: Agent dispatching logic.
    • livekit_room_pb: Room-related data structures.
    • livekit_rtc_pb: Real-time communication protocols.
    • livekit_egress_pb / livekit_ingress_pb: Egress and Ingress services.
    • livekit_token_source_pb: Token generation structures.
    import {
      protoInt64,
      Timestamp,
      AgentSession,
      AgentInference,
      // ... other imports
    } from '@livekit/protocol';