Home
/
Calls
/
Android

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 receive calls when an app is in the background or closed, a user’s device registration token must be registered to the server. A device registration token can be registered by passing it as an argument to a parameter in the authenticate() method when authenticating a user, or by using the SendBirdCall.registerPushToken() method after a user’s authentication has been completed.

Note: Even if your organization already uses Sendbird Chat, a separate user authentication is needed for Sendbird Calls.


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
// Initialize SendBirdCall instance to use APIs in your app.
SendBirdCall.init(getApplicationContext(), APP_ID);

Authenticate to Sendbird server

In order to use the interfaces and methods provided in the 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
// The USER_ID below should be unique to your Sendbird application.
AuthenticateParams params = new AuthenticateParams(USER_ID)
    .setAccessToken(ACCESS_TOKEN)
    .setPushToken(PUSH_TOKEN, isUnique);
    .setAccessToken(ACCESS_TOKEN);

SendBirdCall.authenticate(params, new AuthenticateHandler() {
    @Override
    public void onResult(User user, SendBirdException e) {
        if (e == null) {
            // The user has been authenticated successfully and is connected to Sendbird server.
            ...
        }
    }
});

// Update the currentr user's push token
public class MyFirebaseMessagingService extends FirebaseMessagingService {
    ...

    @Override
    public void onNewToken(@NonNull String token) {
        SendBirdCall.registerPushToken(token, false, e -> {
            if (e == null) {
                // Succeeded to register push token.
            } else {
                // Failed to register push token.
            }
        });
    }
    ...

}

WebSocket

WebSocket connections with Sendbird server are made only when there is an ongoing direct call or group call, therefore authenticating won't create unnecessary WebSocket connections. Also, unless you have integrated push notifications to your application, new incoming calls won't be delivered through WebSocket. The Calls SDK versions prior to 1.6.0 supported making calls with WebSocket connections under certain circumstances, however it is now deprecated.

Note: Sendbird Calls is charged by minutes which starts as soon as the call is connected. It is recommended that you authenticate users for the Calls SDK at your earliest convenience.


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(PUSH_TOKEN, new CompletionHandler() {
    @Override
    public void onResult(SendBirdException e) {
        if (e == null) {
            // The current user has been deauthenticated successfully.
        }
    }
});