LiveKit Meet Documentation

repository·main·Indexed 21 days ago

https://github.com/livekit-examples/meet

An open-source video conferencing reference implementation built with Next.js and the @livekit/components-react library. It demonstrates real-time communication tools using LiveKit Cloud, featuring implementations for background effects, Krisp noise cancellation, End-to-End Encryption (E2EE), and CPU performance optimization.

Tokens
4.5K
Snippets
20
Records
23
Agent score
75%

What's inside LiveKit Meet

  1. Overview of LiveKit Meet

    main
    LiveKit Meet is an open-source video conferencing application. It serves as a reference implementation for building meeting software using the LiveKit ecosystem. The application is built using Next.js and leverages the @livekit/components-react library for its UI components, powered by LiveKit Cloud for real-time media transport.
  2. Set up LiveKit Meet for local development

    main

    Follow these steps to get a local development environment running:

    1. Install dependencies: Use pnpm to install the required packages.
    2. Configure environment variables: Copy the .env.example file to .env.local and populate the required values.
    3. Start the server: Run the development script to launch the Next.js application.
    4. Access the app: Open http://localhost:3000 in your browser.
    pnpm install
    cp .env.example .env.local
    # Update .env.local with your credentials
    pnpm dev
  3. Simulate room scenarios for testing

    main

    The DebugMode component includes a mechanism to call room.simulateScenario(value). This is useful for testing how your application handles various connectivity and signaling events.

    Available scenarios are passed via the handleSimulate function in the UI, which maps to the underlying LiveKit simulateScenario method. One example provided in the implementation is signal-reconnect.

  4. Detect staging environment

    main

    The isMeetStaging function returns true if the application is currently running on the meet.staging.livekit.io host. This is useful for toggling staging-specific configurations or debugging tools.

    if (isMeetStaging()) {
      console.log('Running in staging environment');
    }
  5. Detect low power devices

    main

    The isLowPowerDevice function returns a boolean indicating if the current device is likely a low-power device. It determines this by checking if navigator.hardwareConcurrency is less than 6. This can be used to adjust media quality or feature sets to preserve device performance.

    if (isLowPowerDevice()) {
      // Disable heavy visual effects or reduce video resolution
    }
  6. Configure Krisp noise filter options

    main

    When using the useKrispNoiseFilter hook (which powers the noise cancellation in MicrophoneSettings), you can pass a filterOptions object to tune performance and behavior:

    • bufferOverflowMs: Milliseconds before buffer overflow triggers.
    • bufferDropMs: Milliseconds for buffer drop handling.
    • quality: Set to 'low' for low-power devices or 'medium' for standard devices.
    • onBufferDrop: A callback function executed when a buffer drop occurs. Note that in Krisp versions >= 0.3.2, the filter will automatically disable itself if a buffer drop occurs.
    const { isNoiseFilterEnabled, setNoiseFilterEnabled, isNoiseFilterPending } = useKrispNoiseFilter({
      filterOptions: {
        bufferOverflowMs: 100,
        bufferDropMs: 200,
        quality: 'medium',
        onBufferDrop: () => {
          console.warn('krisp buffer dropped');
        },
      },
    });
  7. Generate a unique room ID

    main

    The generateRoomId function creates a unique identifier for a meeting room in the format xxxx-xxxx, where x is a random alphanumeric character. This is suitable for generating quick, shareable room links.

    const roomId = generateRoomId(); // e.g., "a1b2-c3d4"
  8. Encode and decode passphrases

    main

    Use encodePassphrase and decodePassphrase to handle passphrases in a URL-safe format using URI encoding. This is useful for passing passphrases as part of a URL query parameter.

    const encoded = encodePassphrase('my secret passphrase');
    const decoded = decodePassphrase(encoded);
  9. Use the useDebugMode hook for logging and troubleshooting

    main

    The useDebugMode hook configures the LiveKit client logging level and integrates with Datadog for error and log tracking if the necessary environment variables are present. It also attaches the current room instance to window.__lk_room for manual inspection in the browser console.

    To use it, call the hook within a component that has access to the LiveKit RoomContext (e.g., inside a <LiveKitRoom> provider).

    Environment Variables for Datadog Integration:

    • NEXT_PUBLIC_DATADOG_CLIENT_TOKEN
    • NEXT_PUBLIC_DATADOG_SITE
    import { useDebugMode } from './Debug';
    import { LogLevel } from 'livekit-client';
    
    // Inside a component wrapped by LiveKitRoom
    useDebugMode({ logLevel: LogLevel.debug });
  10. Use the SettingsMenu component

    main

    The SettingsMenu component provides a tabbed interface for managing media devices (camera, microphone, speaker) and controlling room recording.

    Features

    • Media Management: Integrates CameraSettings, MicrophoneSettings, and MediaDeviceMenu for audio output selection.
    • Recording Control: Allows starting and stopping room recordings via a recording endpoint. Note that recording is not supported if End-to-End Encryption (E2EE) is enabled.
    • Integration: Uses useRoomContext and useIsRecording from @livekit/components-react to sync with the current room state.

    Configuration via Environment Variables

    To enable the recording tab, you must provide the NEXT_PUBLIC_LK_RECORD_ENDPOINT environment variable. If this variable is missing, the recording tab will not be rendered.

    Requirements

    • Recording Endpoint: Must be a valid URL. The component performs fetch requests to {endpoint}/start?roomName={roomName} or {endpoint}/stop?roomName={roomName}.
    • E2EE: Recording will throw an error if room.isE2EEEnabled is true.
    import { SettingsMenu } from './lib/SettingsMenu';
    
    // Usage within a LiveKit layout
    <SettingsMenu />
  11. Use the useLowCPUOptimizer hook to manage device performance

    main

    The useLowCPUOptimizer hook monitors the local participant's CPU usage. When the ParticipantEvent.LocalTrackCpuConstrained event is triggered, the hook enters a 'low power mode' and applies optimization strategies to reduce CPU load.

    It accepts a room instance and an optional options object to configure how the optimizer behaves when constraints are detected.

    Optimization Strategies:

    • Reduce Publisher Video Quality: If reducePublisherVideoQuality is true, it calls track.prioritizePerformance() on the constrained local track.
    • Disable Video Processing: If disableVideoProcessing is true, it calls track.stopProcessor() on the constrained track.
    • Reduce Subscriber Video Quality: If reduceSubscriberVideoQuality is true, it sets the video quality of all existing remote track publications to VideoQuality.LOW. Additionally, any new tracks subscribed to while in low power mode will automatically be set to VideoQuality.LOW.
    import { useLowCPUOptimizer } from './lib/usePerfomanceOptimiser';
    
    // Inside your component
    const lowPowerMode = useLowCPUOptimizer(room, {
      reducePublisherVideoQuality: true,
      reduceSubscriberVideoQuality: true,
      disableVideoProcessing: false,
    });
    
    if (lowPowerMode) {
      console.log('Device is in low power mode due to CPU constraints');
    }