Initialise

To initialise the SDK, you will need a few pre-requisites.

  • A configured API Space

  • 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 will be responsible for storing the client instance in the app)

ComapiChat.initialise(application, chatConfig, new Callback<ComapiChatClient>(){/* implement */});

if you would like the SDK to store a static instance for you use 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 */});