Skip to main content
Version: Android SDK v1.0.3

Sessions

The VideoKit object is automatically initialized on application start-up, but in order to communicate with our servers, you will need to start a session using your Video.io API token.

Get an API token

All Video.io APIs should be authenticated using the Video.io API token. To retrieve your token, login to dashboard.video.io and navigate to Apps → Your App → API TOKEN.

Start a session

As said, a session should be created before using any other Video.io API that communicates with our servers. What is the right moment to start a session?

  • If your app has no login system, the session can be safely started in Application.onCreate()
  • If users login into your app, the session should be bound to the login lifecycle. In other words, you can start a Video.io session whenever you know the user identifier.

Sessions are started through the session manager (VideoKit.sessions()) and require you to pass the API token and an identifier of the current logged in user. This identifier is extremely important because performing certain operations on videos require a session that uses the same identifier with which the video was created for the first time.

val sessions: SessionManager = VideoKit.sessions()
sessions.start(TOKEN, currentUserIdentifier).onSuccess {
// Authenticated!
}.onError {
// Something went wrong.
}

As you can see, the start() method returns a Call object described here.

Stop a session

To clear the current session, simply call stop():

val sessions: SessionManager = VideoKit.sessions()
sessions.stop()

Check the session state

To access the current session, simply call get(). You can also add and remove session listeners, which are useful in certain cases.

val sessions: SessionManager = VideoKit.sessions()
val session: Session? = sessions.get()
sessions.addListener(object : SessionListener {
override fun onSessionChanged(session: Session?) {
// Session changed!
}
})