Skip to main content
Version: JavaScript SDK v1.1.0

Sessions

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

Sessions are started through the SessionManager and you have two options to do that:

Using sessionToken

Session token is a unique token generated for every user of your app. It should be generated by your backend service using this API. This API takes your app token (from the previous step) and identity. Identity is a user unique string, such as user id or nickname. It is important to use the same identity for the same user, so all videos created by this user will be associated with them.

const state = await SessionManager.startSession({
sessionToken: 'YOUR_SESSION_TOKEN'
})

if (state == SessionState.CONNECTED) {
// VideoKit is authenticated
}

Using appToken and identity

Alternatively, if you don't have your own backend or you just want to test VideoKit you can pass appToken and identity directly into SessionManager.

You should remember that exposing your appToken to the public could be dangerous, because appToken gives full controls over your video.io application.

const state = await SessionManager.startSession({
appToken: 'YOUR_APPLICATION_TOKEN',
identity: 'UNIQUE_USER_ID'
})

if (state == SessionState.CONNECTED) {
// VideoKit is authenticated
}

If you include VideoKit using CDN files and script tag, you could also initialize session using query parameters in script url:

<script src="https://cdn.video.io/js/1.1.0/videokit.js?sessionToken=YOUR_SESSION_TOKEN" type="text/javascript"></script>

Or using appToken and identity:

<script src="https://cdn.video.io/js/1.1.0/videokit.js?appToken=YOUR_APPLICATION_TOKEN&identity=UNIQUE_USER_ID" type="text/javascript"></script>

Stop a session

To clear the current session, simply call:

SessionManager.stopSession()

Check the session state

You could also subscribe on session state updates as follows:

SessionManager.subscribe('stateChanged', (event, { state }) => {
if (state == SessionState.CONNECTED) {
// VideoKit is authenticated
}
})