To initialise the SDK, there are a few pre-requisites:
- A configured API space.
- An authentication provider that can generate a JWT that matches the auth scheme configured for your API space.
- Implementation of the ChatStore. This implementation should perform db inserts and updates in a single transaction. Set a factory class for ChatStore objects in configuration object.
ChatConfig config = new ChatConfig()
.apiSpaceId("<API_SPACE_ID>")
.authenticator(authenticator)
.store(storeFactory);
authenticator needs to extend ComapiAuthenticator class:
authenticator = new ComapiAuthenticator() {
@Override
public void onAuthenticationChallenge(AuthClient authClient,
ChallengeOptions options) {
// get token using options.getNonce()
authClient.authenticateWithToken(token));
}
}
store factory needs to extend StoreFactory class:
store = new StoreFactory<ChatStore>() {
@Override
protected void build(StoreCallback<ChatStore> callback) {
// create ChatStore implementation that suppeort single tranasaction mechanism
callback.created(store);
}
}
To initialise SDK and obtain client instance as a result:
You are responsible for storing the client instance in the app.
ComapiChat.initialise(application, chatConfig, new Callback<ComapiChatClient>(){/* implement */});
If you want the SDK to store a static instance for you, use the below initialise method instead:
ComapiChat.initialiseShared(application, chatConfig, new Callback<ComapiChatClient>(){/* implement */});
// to get the client instance somwhere else
ComapiChat.getShared();
If you prefer reactive APIs, then you can use one of these:
ComapiChat.initialise(application, chatConfig).subscribe(new Action1<ComapiChatClient>(){/* implement */},
new Action1<Throwable>(){/* implement */});
or
ComapiChat.initialiseShared(application, chatConfig)
.subscribe(new Action1<ComapiChatClient>(){/* implement */},
new Action1<Throwable>(){/* implement */});