LiveKit Components JS

repository·main·Indexed 19 days ago

https://github.com/livekit/components-js

An SDK for adding real-time, multi-modal, and agentic experiences to React applications. It features a multi-layered architecture consisting of @livekit/components-core for shared state handling and framework-specific implementations like @livekit/components-react. The SDK also includes @agents-ui, a set of open-source shadcn/ui components for building voice-first agentic interfaces targeting React 19 and Tailwind CSS 4.

Tokens
37.2K
Snippets
143
Records
180
Agent score
65%

What's inside livekit-components-js

  1. Overview of @livekit/components-js-docs

    main
    The @livekit/components-js-docs package contains purely auto-generated documentation content for all LiveKit Component JavaScript packages. It does not contain any functional code and is used as a data source for documentation websites (such as the livekit-docs-v2 repo) to ensure API documentation stays in sync with the source code.
  2. Explore the LiveKit Ecosystem

    main

    LiveKit provides a wide range of SDKs, UI components, and starter applications across different platforms:

    UI Components

    • React (Primary implementation in this repo)
    • Android Compose
    • SwiftUI
    • Flutter

    SDKs

    • Agents SDKs: Python, Node.js
    • LiveKit Client SDKs: Browser, Swift, Android, Flutter, React Native, Rust, Node.js, Python, Unity, Unity (WebGL), ESP32, C++
    • Server APIs: Node.js, Golang, Ruby, Java/Kotlin, Python, Rust, PHP (community), .NET (community)

    Starter Applications

    • Python Agent, TypeScript Agent, React App, SwiftUI App, Android App, Flutter App, React Native App, Web Embed

    Resources

  3. Navigate the LiveKit Components Monorepo

    main

    The livekit/components-js repository is organized as a monorepo containing framework-specific implementations, core logic, and examples. Use the following structure to find relevant packages:

    • Framework Implementations: The primary React implementation is located in packages/react/.
    • Examples: Reference the Next.js example in examples/nextjs/.
    • Internal Packages:
      • packages/core/: Core logic for components.
      • packages/styles/: Component styling.
      • packages/shadcn/: Shadcn-based components.
  4. Generate API reference manuals with @livekit/api-documenter

    main

    The @livekit/api-documenter tool is used to generate online API reference manuals for TypeScript libraries. It works by consuming *.api.json data files that have been produced by API Extractor.

    Supported output formats include:

    • Markdown
    • DocFX

    To use this tool, you must first configure API Extractor to generate the required .api.json files. For detailed configuration and usage instructions, refer to the API Extractor Generating Docs guide.

  5. What is LiveKit Components Core?

    main

    LiveKit Components Core is a wrapper around the livekit/client-sdk-js package. It transforms the event-based logic of the underlying SDK into observable state and component-level APIs.

    Note: This is an internal package and is not intended to be used directly by end-users. Instead, you should use framework-specific implementations like @livekit/components-react.

  6. How LiveKit Components are architected

    main

    LiveKit Components are designed with a multi-layered architecture to support multiple frameworks:

    1. @livekit/components-core: This package contains the shared state handling logic. It uses observables as the primary data structure. This design allows the core logic to be easily ported to other frameworks like Solid (signals), Svelte (stores), Vue (composables), or Angular (observables).
    2. Framework-specific packages: Packages like @livekit/components-react implement the core logic using framework-specific patterns (e.g., React Hooks and Context) to provide a native developer experience.

    This approach avoids the use of Custom Elements (Web Components) as the primary implementation to ensure developers can work within the constraints and idiomatic patterns of their chosen framework.

  7. Extend and customize @agents-ui components

    main

    Agents UI components are designed to be highly extensible:

    • Prop Passthrough: Most components extend standard HTML attributes. For example, AgentControlBar extends HTMLAttributes<HTMLDivElement>, allowing you to pass any standard div props (like className, id, onClick, etc.) directly to the component.
    • Direct Source Access: Since components are installed directly into your components/agents-ui directory, you can modify the source code to change logic or structure.
    • Styling: For visual changes, it is recommended to pass Tailwind CSS classes to override default styles rather than editing the component internals where possible.
    • Safe Updates: If you rerun the npx shadcn@latest add @agents-ui/{component-name} command, the CLI will prompt you before overwriting any existing files, allowing you to preserve your custom changes.
  8. Understand CSS selector prefixing in LiveKit Components Styles

    main

    To prevent CSS collisions, all selectors used by LiveKit Components (classes, CSS variables, and custom data attributes) are prefixed. This prefixing is handled automatically via PostCSS plugins during the build step.

    When writing or inspecting styles, you should be aware of how the prefix (e.g., lk) is applied to various elements:

    • Classes: .button becomes .lk-button
    • CSS Variables: --border-color becomes --lk-border-color
    • Variable usage: var(--fg) becomes var(--lk-fg)
    • Data Attributes: [data-active='false'] becomes [data-lk-active='false']
    • Pseudo-selectors with attributes: &[data-muted='true'] becomes &[data-lk-muted='true']

    Note: The attr() function is currently not supported for prefixing (e.g., attr(data-participant-name) remains unchanged and does not become attr(data-lk-participant-name)).

  9. Use @extend for CSS inheritance in LiveKit Styles

    main
    When working with the styles package, use SASS @extend instead of @mixin when you want a CSS class to inherit properties from a parent class. This is particularly useful when elements are nearly identical, such as when a .disconnect-button should inherit the base properties of a .button.
  10. Run the LiveKit Components Next.js Example

    main

    To run the Next.js example application, you must first follow the monorepo setup instructions at the root of the repository to ensure all local dependencies are linked.

    1. Create a .env.local file by copying the contents of .env.example and update the values to match your LiveKit server configuration.
    2. From the root of the monorepo, execute the development command.
    3. Access the application at http://localhost:3000/ to view the available examples.
    pnpm dev:next
  11. Configure environment variables for the Next.js Example

    main
    The Next.js example requires environment variables to connect to your LiveKit server. You should create a .env.local file in the project directory and populate it with values from the provided .env.example template. Ensure these values correctly reflect your specific LiveKit server setup.