Skip to content

Initialize BandyerSDK

Federico Marin edited this page Sep 1, 2023 · 35 revisions

The BandyerSDK represents the main facade of the SDK.

Before Initialization

To initialize the BandyerSDKClient you will need first to create an user via Bandyer REST-API

https://docs.bandyer.com/Bandyer-RESTAPI/#create-user

Connect BandyerSDK

BandyerSDK can be connected in two ways:

  • via access token
  • via acces link

Connecting with an access token

The connect API must be called after that the configure API has been invoked. A session object must be provided to the connect API holding info about the logging user and the access token provider. An optional session observer can be passed to the session object in order to be informed about the authentication flow.

AccessTokenProvider accessTokenProvider = new AccessTokenProvider() {
            
	@Override
	public void provideAccessToken(@NonNull String userId, @NonNull Completion<String> completion) {
		// retrieve token [...]
		completion.success(accessToken); // or call completion.error(exception) if an error occurred
	}
};

SessionObserver sessionObserver = new SessionObserver() {

	@Override
	public void onSessionAuthenticating(@NonNull Session session) {
		Log.d(TAG, "onSessionAuthenticating for user " + session.getUserId());
	}

	@Override
	public void onSessionAuthenticated(@NonNull Session session) {
		Log.d(TAG, "onSessionAuthenticated for user " + session.getUserId());
	}

	@Override
	public void onSessionRefreshing(@NonNull Session session) {
		Log.d(TAG, "onSessionRefreshing for user " + session.getUserId());
	}

	@Override
	public void onSessionRefreshed(@NonNull Session session) {
		Log.d(TAG, "onSessionRefreshed for user " + session.getUserId());
	}

	@Override
	public void onSessionError(@NonNull Session session, @NonNull Error error) {
		Log.e(TAG, "onSessionError for user " + session.getUserId() + " with error: " + error.getMessage());
	}
};

Session session = new Session("userId", accessTokenProvider, sessionObserver);

BandyerSDK.getInstance().connect(
                             session,
                             errorReason -> Log.e(TAG, "Unable to connect BandyerSDK with error: " + errorReason));

Note that if BandyerSDK is already connected via access link, connecting via access token with the current user or with another user is not allowed. The current access token session must be ended before connecting again.

Connecting with an access link

BandyerSDK can optionally be connected using a call url link. The session that will be created using the call url link as access link will last only for the duration of the joined call.

All the sdk feature will be restricted on the call represented by the call link url.

In addition the only chat accessibile will be the chat related to the current call specified by the call link url.

Remember to configure the BandyerSDK as described here. To connect via a call url please refer to the following code:

Intent intent = new BandyerIntent.Builder()
               		.startFromJoinCallUrl(this, joinUrl)
                    .build();

startActivity(intent);

At the end of the call the BandyerSDK will be automatically disconnected and all persisted data will be cleared as well.

Note that if BandyerSDK is already connected via access token, connecting via access token with the current user or with another user is not allowed. The current access link session must be ended before connecting again.

Disconnect BandyerSDK

To disconnect BandyerSDK invoke the following method:

BandyerSDK.getInstance().disconnect();

Reset BandyerSDK

To reset the configuration and will also disconnect the BandyerSDK invoke the following method:

BandyerSDK.getInstance().reset();

Clear all user data

Call disconnect API with optional boolean parameter set to true to delete all the local data saved for the userAlias used for the BandyerSDKClient initialization.

BandyerSDK.getInstance().disconnect(true);
Clone this wiki locally