Skip to main content

Client & Authentication

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

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:

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()

Client options

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

val streamVideo = StreamVideoBuilder(
context = context,
apiKey = apiKey,
geo = GEO.GlobalEdgeNetwork,
user = user,
token = token,
tokenProvider = { error ->
// make an API call here to get a new token from your backend
},
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.

The full list of supported options is:

OptionDescriptionDefault
apiKeyThe API key to use. Found in the dashboard-
geoThe GEO routing policy. Defaults to the global edge network. Configure this if you need specific geofencing rulesGEO.GlobalEdgeNetwork
userThe user object. You can store custom data on the user-
tokenThe JWT token to use for authentication-
tokenProviderA function to call if the token is expired or invalidnull
loggingLevelThe logging level. Recommend to set it to debug while in developmentLoggingLevel.BASIC
enablePushIf push notifications should be enabledfalse
pushDeviceGeneratorsSupport Firebase and other push providersfalse
encryptPreferencesIf our data store should encrypt the api key, user token etc.true
ensureSingleInstanceVerify that only 1 version of the video client exists, prevents integration mistakes.true
ringNotificationA function to create your own notification when there's an incoming "ringing" callnull
audioFiltersRun audio through a filter before sending it-
videoFiltersRun video through a filter before sending it-
soundsCustomize the sounds used by the SDKSounds()

Did you find this page helpful?