Skip to content

Initialize BandyerSDKClient

Kristiyan Petrov edited this page Nov 9, 2021 · 23 revisions

The BandyerSDKClient is the object accountable for everything regarding the communication.

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

Initialization

BandyerSDKClientOptions options = new BandyerSDKClientOptions.Builder().build();

BandyerSDKClient.getInstance().init(userAlias, options);

BandyerSDKClient.getInstance().startListening(); // Start listening for incoming events
BandyerSDKClient.getInstance().stopListening(); // Stop listening for incoming events

Dispose BandyerSDKClient

Remember to call this method to ensure a clean exit from the activity.

BandyerSDKClient.getInstance().dispose();

Clear all user data

Call this method to delete all the local data saved for the userAlias used for the BandyerSDKClient initialization.

BandyerSDKClient.getInstance().clearUserCache();

BandyerSDKClient Observers

There are two types of observers

  • An Observer for the overall client events
BandyerSDKClient.getInstance().addObserver(new BandyerSDKClientObserver() {
	@Override
	public void onClientStatusChange(BandyerSDKClientState state) {
		Log.d(TAG, "Bandyer SDK client status change: " + state);          
	}

	@Override
	public void onClientError(Throwable throwable) {
   		Log.d(TAG, "Bandyer SDK client error " + throwable.getMessage());
	}

	@Override
	public void onClientReady() {
   		Log.d(TAG, "Bandyer SDK client ready.");
	}

	@Override
	public void onClientStopped() {
   		Log.d(TAG, "Bandyer SDK client stopped.");
	}
});
  • An Observer for the modules(call and/or chat)
BandyerSDKClient.getInstance().addModuleObserver(new BandyerModuleObserver() {
	@Override
	public void onModuleReady(BandyerModule module) {
   		if (module instanceof ChatModule) {
   			Log.d(TAG, "chat module ready! It is now possible to start a call.");
   		} else if (module instanceof CallModule) {
   			Log.d(TAG, "call module ready! It is now possible to start a chat.");
   		}
	} 

	@Override
	public void onModulePaused(BandyerModule module) {
   		Log.d(TAG, "module " + module.getName() + " paused.");
	}

	@Override
	public void onModuleFailed(BandyerModule module, Throwable throwable) {
   		Log.d(TAG, "module " + module.getName() + " failed with error " + throwable.getMessage());
	}

	@Override
	public void onModuleStatusChanged(BandyerModule module, BandyerModuleStatus moduleStatus) {
   		Log.d(TAG, "module " + module.getName() + " status change: " + moduleStatus);

	}
});
Clone this wiki locally