Thanks to visit codestin.com
Credit goes to github.com

Skip to content

davideberlein/server-sdk-kotlin

Repository files navigation

server-sdk-kotlin

Kotlin SDK for accessing livekit-server APIs. Currently for use in JVM environments.

https://docs.livekit.io/guides/server-api/

Installation

This SDK is available as a Maven package through JitPack.

Maven

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

<dependencies>
    <dependency>
        <groupId>com.github.livekit</groupId>
        <artifactId>server-sdk-kotlin</artifactId>
        <version>97c8779b09</version>
    </dependency>
</dependencies>

Gradle

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

dependencies {
    implementation 'com.github.livekit:server-sdk-kotlin:<commit hash>'
}

Usage

Server API Access

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.

Creating Access Tokens

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 Room("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).

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 100.0%