https://docs.livekit.io/guides/server-api/
This SDK is available as a Maven package through Maven Central.
<dependencies>
<dependency>
<groupId>io.livekit</groupId>
<artifactId>livekit-server</artifactId>
<version>0.5.6</version>
</dependency>
</dependencies>
dependencies {
implementation 'io.livekit:livekit-server:0.5.6'
}
Development snapshots are available through Sonatype: https://s01.oss.sonatype.org/content/repositories/snapshots/
The current snapshot VERSION_NAME
can be found in the root
folder's gradle.properties.
Obtain a RoomServiceClient
or EgressServiceClient
through their respective create
methods, and then run calls through the client.
package org.example;
import com.google.protobuf.util.JsonFormat;
import java.io.IOException;
import io.livekit.server.RoomServiceClient;
import livekit.LivekitModels;
import retrofit2.Call;
import retrofit2.Response;
public class Main {
public static void main(String[] args) throws IOException {
RoomServiceClient client = RoomServiceClient.create(
"http://example.com",
"apiKey",
"secret");
Call<LivekitModels.Room> call = client.createRoom("room_name");
Response<LivekitModels.Room> response = call.execute(); // Use call.enqueue for async
LivekitModels.Room room = response.body();
System.out.println(JsonFormat.printer().print(room));
}
}
Call
adapters are also available through Retrofit for other async constructs such as CompletableFuture
and RxJava.
Access tokens can be generated through the io.livekit.server.AccessToken
class.
AccessToken token = new AccessToken("apiKey", "secret");
// Fill in token information.
token.setName("name");
token.setIdentity("identity");
token.setMetadata("metadata");
token.addGrants(new RoomJoin(true), new RoomName("myroom"));
// Sign and create token string.
System.out.println("New access token: " + token.toJwt())
By default, tokens expire 6 hours after generation. You may override this by using token.setTtl(long millis)
.
LiveKit Ecosystem | |
---|---|
Client SDKs | Components · JavaScript · iOS/macOS · Android · Flutter · React Native · Rust · Python · Unity (web) · Unity (beta) |
Server SDKs | Node.js · Golang · Ruby · Java/Kotlin · PHP (community) · Python (community) |
Services | Livekit server · Egress · Ingress |
Resources | Docs · Example apps · Cloud · Self-hosting · CLI |