Skip to content

Trirrin/livekit-java-sdk

Repository files navigation

LiveKit Java SDK

English | 简体中文

Java client SDK for LiveKit real-time communication platform.

Features

  • Room Management - Join/leave rooms, handle participants and tracks (signal protocol 17)
  • WebRTC Integration - Audio/video publishing and subscribing via webrtc-java
  • Screen Sharing - Publish screens or application windows
  • Subscription Controls - Subscribe/unsubscribe, video quality, dimensions, and fps per track
  • Participant Updates - Metadata, name, and attributes updates with change events
  • Data Channels - Reliable and lossy data messaging
  • RPC - Call methods on remote participants (performRpc, registerRpcMethod)
  • Data Streams - Chunked text/byte/file streams with topic handlers (sendText, sendFile)
  • Chat & Transcription - Chat messages, transcription segments, and SIP DTMF events
  • E2EE - End-to-end encryption for data channels (AES-GCM with key ratcheting)
  • Auto Reconnection - Automatic reconnection with exponential backoff
  • Network Monitoring - Resume tokens and network change detection
  • Audio Processing - Echo cancellation, noise suppression, auto gain control options
  • Stats & Codecs - WebRTC stats and preferred video codec selection

Requirements

  • Java 21+
  • Gradle 9.x (included via wrapper)

Installation

Gradle (Kotlin DSL)

repositories {
    mavenCentral()
    maven { url = uri("https://jitpack.io") }
}

dependencies {
    // Full SDK with WebRTC support
    implementation("com.github.Trirrin.livekit-java-sdk:rtc:v0.1.4")
    
    // Or signaling only (no audio/video)
    // implementation("com.github.Trirrin.livekit-java-sdk:signaling:v0.1.4")
}

Gradle (Groovy)

repositories {
    mavenCentral()
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'com.github.Trirrin.livekit-java-sdk:rtc:v0.1.4'
}

Maven

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.github.Trirrin.livekit-java-sdk</groupId>
        <artifactId>rtc</artifactId>
        <version>v0.1.4</version>
    </dependency>
</dependencies>

Quick Start

import io.livekit.sdk.Room;
import io.livekit.sdk.RoomOptions;
import io.livekit.sdk.RoomListener;
import io.livekit.sdk.signaling.LiveKitClient;

public class Example {
    public static void main(String[] args) {
        RoomOptions options = new RoomOptions();
        LiveKitClient client = new LiveKitClient(options);
        Room room = client.getRoom();

        room.addListener(new RoomListener() {
            @Override
            public void onConnected(Room r) {
                System.out.println("Connected to room: " + r.getName());
            }

            @Override
            public void onParticipantConnected(Room r, RemoteParticipant participant) {
                System.out.println("Participant joined: " + participant.getIdentity());
            }
            
            // ... other callbacks
        });

        client.connect("wss://your-server.livekit.cloud", "your-access-token");
    }
}

Examples

The examples module includes working examples:

Example Description
BasicRoomExample Join room and handle events
PublishExample Publish audio/video tracks
SubscribeExample Subscribe to remote tracks
DataChannelExample Interactive data messaging

Run examples:

export LIVEKIT_URL=wss://your-server.livekit.cloud
export LIVEKIT_TOKEN=your-access-token
./gradlew :examples:run

Documentation

Project Structure

livekit-java-sdk/
├── protocol/    # Protobuf definitions and generated classes
├── core/        # Room, Participant, Track, E2EE APIs
├── signaling/   # WebSocket signaling client
├── rtc/         # WebRTC integration
├── examples/    # Usage examples
└── docs/        # Documentation

Building

# Build all modules
./gradlew build

# Run tests
./gradlew test

# Format code
./gradlew spotlessApply

# Publish to local repository
./gradlew publishToMavenLocal

E2EE (End-to-End Encryption)

Data channel encryption is supported via E2EEManager:

import io.livekit.sdk.e2ee.E2EEManager;
import io.livekit.sdk.e2ee.BaseKeyProvider;

BaseKeyProvider keyProvider = new BaseKeyProvider();
keyProvider.setSharedKey(secretKeyBytes);

E2EEManager e2ee = new E2EEManager(keyProvider);
byte[] encrypted = e2ee.encryptData(plaintext, participantId);
byte[] decrypted = e2ee.decryptData(encrypted, participantId);

Note: Media track E2EE requires FrameCryptor API which is not yet exposed by webrtc-java.

Known Limitations

  • Screen sharing not yet exposed (webrtc-java supports it)
  • Simulcast/SVC layer selection not implemented
  • Media track E2EE blocked by webrtc-java library limitation

License

Apache License 2.0

Links

About

A LiveKit Client SDK for JAVA

Resources

License

Stars

3 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages