Platform docs
Auth, users, webhooks & more

Client & Authentication

Before joining a call, it is necessary to set up the video client. Here's a basic example:

import io.getstream.video.android.core.GEO
import io.getstream.video.android.core.StreamVideoBuilder
import io.getstream.video.android.model.User

val client = StreamVideoBuilder(
     context = context,
     apiKey = apiKey,
     geo = GEO.GlobalEdgeNetwork,
     user = user,
     token = token,
).build()
  • The API Key can be found in your Stream dashboard.
  • The User can be either authenticated, anonymous or guest.
  • Note: You can store custom data on the user object, if required.

Typically, you'll want to initialize the client in your app's Application class or dedicated dependency injection module.

Generating a token

  • Tokens need to be generated server side. You can use our server side SDKs to quickly add support for this. Typically you integrate this into the part of your codebase where you login or register users. The tokens provide a way to authenticate a user or give access to a specific set of calls.

  • Here's a valid user and token to help you get started on the client side, before integrating with your backend API.

Different types of users

  • Authenticated users are users that have an account on your app.
  • Guest users are temporary user accounts. You can use it to temporarily give someone a name and image when joining a call.
  • Anonymous users are users that are not authenticated. It's common to use this for watching a livestream or similar where you aren't authenticated.

This example shows the client setup for a guest user:

import io.getstream.video.android.model.User
import io.getstream.video.android.model.UserType

val streamVideo = StreamVideoBuilder(
    context = context,
    apiKey = apiKey,
    geo = GEO.GlobalEdgeNetwork,
    user = User(id = "guest", type = UserType.Guest)
).build()

And here's an example for an anonymous user

val streamVideo = StreamVideoBuilder(
    context = context,
    apiKey = apiKey,
    geo = GEO.GlobalEdgeNetwork,
    user = User(id = "anonymous", type = UserType.Anonymous)
).build()

Anonymous users don't establish an active web socket connection, therefore they won't receive any events. They are just able to watch a livestream or join a call.

The token for an anonymous user should contain the call_cids field, which is an array of the call cid's that the user is allowed to join.

Here's an example JWT token payload for an anonymous user:

{
  "iss": "@stream-io/dashboard",
  "iat": 1726406693,
  "exp": 1726493093,
  "user_id": "!anon",
  "role": "viewer",
  "call_cids": [
    "livestream:123"
  ]
}

Client options

Here's a more complete example of the client options:

import io.getstream.log.Priority
import io.getstream.video.android.core.GEO
import io.getstream.video.android.core.StreamVideoBuilder
import io.getstream.video.android.core.logging.LoggingLevel
import io.getstream.video.android.core.socket.common.token.TokenProvider

val streamVideo = StreamVideoBuilder(
    context = context,
    apiKey = apiKey,
    geo = GEO.GlobalEdgeNetwork,
    user = user,
    token = token,
    tokenProvider = object : TokenProvider {
        override suspend fun loadToken(): String {
            // make an API call here to get a new token from your backend
            return yourTokenService.fetchToken(user.id)
        }
    },
    loggingLevel = LoggingLevel(priority = Priority.DEBUG), // set the logging level
).build()

Once you invoke the build() method of StreamVideoBuilder, you can get the same instance of the StreamVideo with the instance() methods below:

val streamVideo = StreamVideo.instance()

If you don't need the user information, you can clear it by calling the logout() method like so:

val streamVideo = StreamVideo.instance()
streamVideo.logOut()

Lastly, if you don't need to use the StreamVideo instance anymore, you can uninstall it by calling removeClient() method:

StreamVideo.removeClient()

Logging Stream SDK

Stream SDK allows you to trace log messages and debug what's going on and what problems you're facing. By setting the logging level on StreamVideoBuilder, you can filter the log messages depending on the priority:

val streamVideo = StreamVideoBuilder(
  loggingLevel = LoggingLevel(priority = Priority.DEBUG),
  ..
)

We provide the following 6 different logging levels: Verbose, Debug, Info, Warn, Error, and Assert. The default logging level is Error.

Call Configurations

Stream SDK allows you to configure specific behavior for different types of calls (e.g., default call, livestream call, audio call) by using CallServiceConfigRegistry

Key Call Configurations:

  • Foreground Notifications: Control the visibility of foreground notifications during calls.
  • Audio Usage: Set the type of audio usage for the call
    • AudioAttributes.USAGE_VOICE_COMMUNICATION
    • AudioAttributes.USAGE_MEDIA
  • Foreground Service Class: Customize the behavior of the foreground service for specific call types.

For full details and advanced configuration options, please refer to our Call Configurations guide

Builder parameters

The following table lists the main StreamVideoBuilder constructor parameters.

Option Description Default
apiKey The API key to use. Found in the dashboard -
geo The GEO routing policy. Defaults to the global edge network. Configure this if you need specific geofencing rules GEO.GlobalEdgeNetwork
user The user object. You can store custom data on the user -
token The JWT token to use for authentication -
tokenProvider A TokenProvider called to load a new token when the current one is expired or invalid -
loggingLevel The logging level. Recommend to set it to debug while in development LoggingLevel()
notificationConfig Push notification configuration, including the pushDeviceGenerators for Firebase and other push providers NotificationConfig()
ensureSingleInstance Verify that only 1 version of the video client exists, prevents integration mistakes. true
ringNotification A function to create your own notification when there's an incoming "ringing" call null
connectionTimeoutInMs Connection timeout in milliseconds 5000
sounds Customize the sounds used by the SDK Default ringing sounds
callServiceConfigRegistry A registry for managing call configurations related to different call types like default, livestream, audio, etc. CallServiceConfigRegistry()
appName Optional name of your app, used for logging and debugging null
leaveAfterDisconnectSeconds Seconds to wait before leaving the call after the connection is lost 30
connectOnInit Whether the socket connects as soon as a user is set true
rejectCallWhenBusy Automatically reject incoming calls while the user is already in another call false
telecomConfig Enables the Telecom integration. See Telecom integration null