val client = StreamVideoBuilder(
context = context,
apiKey = apiKey,
geo = GEO.GlobalEdgeNetwork,
user = user,
token = token,
).build()
Client & Authentication
Before joining a call, it is necessary to set up the video client. Here’s a basic example:
- 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()
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:
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:
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 function to call if the token is expired or invalid | null |
loggingLevel | The logging level. Recommend to set it to debug while in development | LoggingLevel.BASIC |
enablePush | If push notifications should be enabled | false |
pushDeviceGenerators | Support Firebase and other push providers | false |
encryptPreferences | If our data store should encrypt the api key, user token etc. | true |
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 |
audioFilters | Run audio through a filter before sending it | - |
videoFilters | Run video through a filter before sending it | - |
sounds | Customize the sounds used by the SDK | Sounds() |