Skip to content

GetStream/stream-sdk-java

Repository files navigation

Official Java SDK for Stream

Build Maven Central Version Java Version

Check out our:

Features

  • Video call creation and management
  • Chat session creation and management
  • Token generation for user authentication

Installation

dependencies {
    implementation("io.getstream:stream-sdk-java:$streamVersion")
}

✨ Getting started

Configuration

To configure the SDK you need to provide required properties.

Property ENV Default Required
io.getstream.apiKey STREAM_API_KEY - Yes
io.getstream.apiSecret STREAM_API_SECRET - Yes
io.getstream.timeout STREAM_API_TIMEOUT 10000 No

Users and Authentication

import io.getstream.services.frameworks.StreamSDKClient;
import io.getstream.models.UserRequest;

var client = new StreamSDKClient("apiKey", "apiSecret");

// sync two users using the UpdateUsers method, both users will get inserted or updated
List<UserRequest> userRequests =
    List.of(
        UserRequest.builder()
            .id("tommaso-id")
            .name("tommaso")
            .role("admin")
            .custom(Map.of("country", "NL"))
            .build(),
        UserRequest.builder()
            .id("thierry-id")
            .name("thierry")
            .custom(Map.of("country", "US"))
            .build());

UpdateUsersRequest updateUsersRequest =
    UpdateUsersRequest.builder()
        .users(userRequests.stream().collect(Collectors.toMap(UserRequest::getId, x -> x)))
        .build();

client.updateUsers(updateUsersRequest).execute();

// Create a JWT token for the user to connect client-side (e.g. browser/mobile app)
// token expires in 24 hours
client.tokenBuilder().createToken("john", 24 * 60 * 60);

Video API - Calls

To create a video call, use the client.video.call method:

var testCall = client.video().call("default", UUID.randomUUID().toString());

// create call if it doesn't exist or get the existing one
call.getOrCreate(
    GetOrCreateCallRequest.builder()
        .data(
            CallRequest.builder()
                .createdByID("sacha")
                .members(members)
                .custom(Map.of("color", "blue"))
                .build())
        .build());

Development

To run tests, create the local.properties file using the local.properties.example and adjust it to have valid API credentials:

cp local.properties.example local.properties

Then run the tests:

 ./gradlew test

Format the code:

./gradlew spotlessApply

Generate code from spec

To regenerate the Java source from OpenAPI, just run the ./generate.sh script from this repo.

Note

Code generation currently relies on tooling that is not publicly available, only Stream devs can regenerate SDK source code from the OpenAPI spec.

Contributing

Contributions are welcome! Please read the contributing guidelines to get started.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages