Overview

In this guide you learn how to add the Client SDK to your client-side JavaScript app.

Prerequisites

The Client SDK requires Node.js and NPM.

To add the Client SDK to your project

Open your terminal. If you have an existing app, navigate to its root. Otherwise, create a new directory for your project.

Add the Client SDK to your project

Load the Client SDK package

Load the Client SDK from a Content Delivery Network (CDN):

Inside the <head> of your HTML file, add:

Add the Client SDK into your code

Near the top of your application code, add:

Note: This may not be needed in newer browsers. If you get an error about the vonageClientSDK being not found/defined, try this.

Using the Client SDK in your app

Creating Users and JWTs

A JSON Web Token (JWT) is necessary to log in to your Vonage Application. The Client SDK cannot manage users nor generate JWTs, so you must choose a method of handling it on the backend:

  • For onboarding or testing purposes, you can get your client-side app working before setting up a backend by generating a test JWT from the command line and hard-coding it in your client-side JavaScript.

  • For real world usage, you can deliver JWTs from the server using the Node or PHP backend SDKs, and set the jwt variable in your code by fetching that data:

  • Read more on generating JWTs in this article

Instantiate VonageClient and create a session

Instantiating the VonageClient varies on how you load the Vonage Client SDK.

If loaded with a <script> tag:

If loaded via import:

To create a session, pass your JWT as the argument to createSession().

Session Status

If there are any errors with the session after it has been successfully created, you will receive them on the sessionError event listener on the instantiated VonageClient.

Conclusion

You added the Client SDK to your client-side JavaScript app, and created a session. You can now use the VonageClient client in your app, and use the Client SDK functionality.

See also

  • Data Center Configuration - this is an advanced optional configuration you can carry out after adding the SDK to your application.