Initialization

Initialize ChatSDK#

To start using the sdk, there were few data that were required by the SDK for initialization. For which we use the ChatSDK builder class to provide data to SDK. In your Application class onCreate build the ChatSDK Builder and provide the necessary data .An example can be found below.

Configure in app/build.gradle file#

buildTypes {
debug {
buildConfigField 'String', 'SDK_BASE_URL', '"https://api-preprod-sandbox.mirrorfly.com/api/v1/"'
buildConfigField 'String', 'XMPP_PORT', '"5222"'
buildConfigField 'String', 'XMPP_DOMAIN', '"xmpp-preprod-sandbox.mirrorfly.com"'
buildConfigField 'String', 'XMPP_HOST', '"xmpp-preprod-sandbox.mirrorfly.com"'
buildConfigField 'String', 'IV_KEY', '"ddc0f15cc2c90fca"'
buildConfigField 'String', 'LICENSE', '"xxxxxxxxxxxxxxxxxxxxxxxxx"'
buildConfigField 'String', 'SIGNAL_SERVER', '"https://signal-preprod-sandbox.mirrorfly.com"'
buildConfigField 'String', 'WEB_CHAT_LOGIN', '"https://webchat-preprod-sandbox.mirrorfly.com/"'
buildConfigField 'String', 'JANUS_WEB_SOCKET_SERVER', '"wss://janus.mirrorfly.com"'
buildConfigField "String", "SUPPORT_MAIL", '"abc_support@gmail.com"'
}
}

Update your App License key in the app/build.gradle file. You can find the LICENSE key and paste your registered License Key. After replacing your license key do gradle sync operation.

Note : In ChatSDK Builder configuration .setMediaFolderName should be defined your own local path folder name insteadof SELECT_YOUR_PATH_NAME to maintain the Application Media files. If the argument is empty, SDK will be configured with default folder name as MirrorFly.

GroupConfig groupConfiguration = new GroupConfig.Builder()
.enableGroupCreation(true)
.setMaximumMembersInAGroup(250)
.onlyAdminCanAddOrRemoveMembers(true)
.build();
ChatSDK.Builder()
.useProfileName(true)
.setDomainBaseUrl(BuildConfig.SDK_BASE_URL)
.enableMobileNumberLogin(true)
.setLicenseKey(BuildConfig.LICENSE)
.setIsTrialLicenceKey(true)
.setGroupConfiguration(groupConfiguration)
.setMediaFolderName(SELECT_YOUR_PATH_NAME)
.setIVKey(BuildConfig.IV_KEY)
.build();

When Name of a user is available and their country code is available(needed only for mobile login) call the below methods wherever necessary.

ChatManager.setUserCountryISOCode("IN");
ChatManager.setUserProfileName("John Wick");

when user decided to use mobile number for login by setting this flag to true using enableMobileNumberLogin(true) method in ChatSDK, then country code must be provided for the sdk in the form of 2/3 letter code(ISO Alpha-2).

Chat Builder Function Description#

FunctionParameter TypeDescription
useProfileNamebooleanTo show whether contact's profile name or nickname from sdk
setDomainBaseUrlStringurl needed for api calls provided by Chat team
enableMobileNumberLoginbooleantrue if mobile number is used as primary id for the user else false
setLicenseKeyStringlicense key needed for registration api provided by Chat team
setIsTrialLicenceKeybooleantrue if provided licence key is trial licence key else false
setGroupConfigurationGroupConfigconfiguration for the group implementation
setMediaFolderNameStringFolder Name needed to save for the Media Sent/Receive items in device storage
setIVKeyStringThe initial vector used for encryption/decryption
buildn/ainitialize the chat configuration

GroupConfig Builder Function Description#

FunctionArgument TypeDescription
enableGroupCreationbooleanenable/disable group creation
setMaximumMembersInAGroupintset the maximum number of members a group can have(cannot be greater than 300)
onlyAdminCanAddOrRemoveMembersbooleanif true only group admin can add/remove members else members can add/remove other members
buildn/abuild GroupConfig object
caution

Base url must have http/https protocol and should end with / else an exception will be thrown.

In your application class oncreate method add the below lines:

@Override
public void onCreate() {
super.onCreate();
//activity to open when use clicked from notification
//activity to open when a user logout from the app.
ChatManager.setStartActivity(MainActivity.class);
//for chat logging
LogMessage.enableDebugLogging(BuildConfig.DEBUG);

Registration#

To register a new user use the below method. This method will take care sandbox mode registration or live mode registration based on setIsTrialLicenceKey provided.

FlyCore.registerUser(USER_IDENTIFIER, FCM_TOKEN, (isSuccess, throwable, data ) -> {
if(isSuccess) {
JSONObject responseObject = (JSONObject) data.get("data");
// Get Username, password and Auth token from the object
} else {
// Register user failed print throwable to find the exception details.
}
});
ArgumentTypeDescription
USER_IDENTIFIERStringUnique Id to Register the User. We accept only the AlphaNumeric String
FCM_TOKENStringfcm device token
CALLBACKFlyCallbackFlyCallback implemented as lambda expression

Connect to the chat server#

In order to send messages using the chat sdk , at first you need to establish the connection to the server. sdk provides methods for initializing the connection configuration as well as methods for making connection.

At first initialize the connection details using the below method. This method will store the connection details in persistent storage to make connection automatically once you close and reopen the app.

ArgumentTypeDescription
USERNAMEStringuserName for making connection to the server
SECRET_KEYStringpassword used to authenticate to the xmpp server
XMPP_DOMAINStringdomain name which will be used in jid
XMPP_HOSTStringxmpp server url
XMPP_PORTintport of the xmpp server
ChatConnectionManager.initialize(USERNAME, SECRET_KEY, XMPP_DOMAIN, XMPP_HOST, XMPP_PORT);

Once you initialized the connection details, for the first time you need to call the below method to make connection to the chat server immediately after that you don't need to call this method anymore, sdk will handle connection and disconnection on behalf of you.

ChatManager.makeXMPPConnection()