JavaScript
Calls Authentication

Authentication

In order to use the features of the Calls SDK in your client apps, user authentication with SendBird server must be initiated through the SendBirdCall.authenticate() method. To make or receive calls, the SendBirdCall instance should be connected with SendBird server. Connect socket by using the SendBirdCall.connectWebSocket() method after a user’s authentication has been completed.


Initialize the Calls SDK with APP_ID

As shown below, the SendBirdCall instance must be initialized when a client app is launched. Initialization is done by using the APP_ID of your SendBird application in the dashboard. If the instance is initialized with a different APP_ID, all existing call-related data in a client app will be cleared and the SendBirdCall instance will be initialized again with the new APP_ID.

Light Color Skin
Copy
// Initialization
SendBirdCall.init(APP_ID);

Authenticate to SendBird server

In order to use the interfaces and methods provided in a SendBirdCall instance, a user must be connected to SendBird server by authentication. Without authentication, calling the methods of the Calls SDK will not work in a user’s client app. This means that if a user performs actions such as accepting an incoming call before authentication, the user will receive errors from SendBird server.

Note: Using the Chat API, you can create a user along with their own access token, or issue an access token for an existing user.

Light Color Skin
Copy
// Authentication
SendBirdCall.authenticate({ USER_ID, ACCESS_TOKEN }, (res, error) => {
    if (error) {
        // Authentication failed
    } else {
        // Authentication succeeded
    }
});

// Websocket Connection
SendBirdCall.connectWebSocket()
    .then(/* Succeeded to connec t*/)
    .catch(/* Failed to connect */);
}

Deauthenticate from SendBird server

Deauthenticate a user from SendBird server using the SendBirdCall.deauthenticate() method. It will clear all current direct calls, session keys, and user information from a user’s client app. This can also be considered as logging out from the server.

Light Color Skin
Copy
SendBirdCall.deauthenticate();