-
Notifications
You must be signed in to change notification settings - Fork 4
Initialize BandyerSDKClient
The BandyerSDK represents the main facade of the SDK.
BandyerSDK can be connected in two ways:
- via access token
- via access link
Important
- The accessToken should be generated from your backend by invoking this api get_credentials. Be aware that it expires. The callback will be called multiple times every time a new token is needed to refresh the user session.
- The accessLink should be generated from your backend by invoking this api create_room. Be aware that it can only be used to enter in a room and when that room is closed/deleted it will automatically expire.
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 same user or with another user is not allowed. The current access token session must be ended before connecting again.
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 link with the same user or with another user is not allowed. The current access link session must be ended before connecting again.
To disconnect BandyerSDK invoke the following method:
BandyerSDK.getInstance().disconnect();
To reset the configuration and will also disconnect the BandyerSDK invoke the following method:
BandyerSDK.getInstance().reset();
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);