Mesibo Real-time Chat APIs - Initialization
Estimated reading time: 5 minutesYou need to call one or more initialization APIs before using any other mesibo APIs. Following are the various Initialization
APIs.
init
This API is for Android only.
This is the first API function you must call before you use any other mesibo API.
void init();
init
takes the following parameters:
- context, Application Context
Parameter | Description |
---|---|
context | Application Context |
setPath [Optional]
Path where database and all other files will be stored. The default Path will be used if this API is not called or the path is not writable. It is recommended to use the default path or check that the path is writable before calling this API.
void setPath(String path);
setPath
takes the following parameters:
Parameter | Description |
---|---|
path | Valid file system path. Ensure that your app has permission to read/write to this path |
setAccessToken
Set the access token for the user.
int setAccessToken(String token);
setAccessToken
takes the following parameters:
Parameter | Description |
---|---|
token | User Access Token Obtained using Backend API - Add User Operation |
setDatabase
Enable a local database to store all incoming & outgoing messages and other information. If this API is not called, Mesibo will not use any local database to store messages.
It is recommended to call setDatabase
after setting user access token using setAccessToken
API. It ensures a unique local database for each user. If setDatabase
is called before setAccessToken
API function, the same local database will be used for all the users.
boolean setDatabase(String dbname, boolean resetTables);
setDatabase
takes the following parameters:
Parameter | Description |
---|---|
DBName | Name, or the complete path of the database. If path is not specified, the database will be stored in the default path or the path set by setPath API |
resetTables | reset existing tables |
addListener
Mesibo invokes Listeners for various events. For example, when you receive a message, receive an incoming call, etc. You can implement these listeners to get real-time event notifications. Refer to Listeners section for more details on listeners.
You can add a listener using ‘addListener’ API. You can add multiple listeners if required.
void addListener(MesiboListener listener);
addListener
takes the following parameters:
Parameter | Description |
---|---|
listener | listener object (of any type) |
removeListener
Remove a listener previously added using addListener
API.
void removeListener(MesiboListener listener);
removeListener
takes the following parameters:
Parameter | Description |
---|---|
listener | listener object (of any type) |
setSecureConnection
Enable encrypted connection. Encryption is enabled by default. This is an optional API. However, if invoked, should be invoked before the start
API.
void setSecureConnection(boolean enable);
setSecureConnection
takes the following parameters:
Parameter | Description |
---|---|
enable | enable or disable encryption |
start
Start Mesibo. Mesibo will start connection establishment with Mesibo cloud servers OR your on-premise Mesibo server. Note that, Mesibo will not establish a network connection till start
API is called. However, once the start
is called, Mesibo will automatically manage any future reconnections till stop() is called
start
does not take any parameters.
stop
Disconnect any existing connection and also prevent future reconnections.|Void|
void start();
start
does not take any parameters.
stop
Disconnect any existing connection and also prevent future reconnections.|Void|
void start();
stop
does not take any parameters.
Initialization APIs Example
Below is an example of using initialization APIs.
Android Example
Mesibo api = Mesibo.getInstance();
api.init(context);
// set path for storing DB and messaging files
Mesibo.setPath(Environment.getExternalStorageDirectory().getAbsolutePath());
// add listener
Mesibo.addListener(this);
// set access token
if(0 != Mesibo.setAccessToken(accessToken) {
return false;
}
// set database after setting access token so that it's associated with the user
Mesibo.setDatabase("mesibo.db", 0);
// Now start mesibo
if(0 != Mesibo.start()) {
return false;
}
iOS Example
[MesiboInstance setPath:appdir];
[MesiboInstance addListener:self];
[MesiboInstance setAccessToken:accessToken];
[MesiboInstance setDatabase:@"mesibo.db"] ;
[MesiboInstance start];