Let's integrate SDK for Flutter

warning

MirrorFly Chat SDK V1 for Flutter is no longer supported as a new version is released. Check out our latest Chat SDK V2 here.

Make an easy and efficient way with CONTUS TECH MirrorFly Chat SDK for Flutter - simply integrate the real-time chat features and functionalities into a client's app.

With client-side implementation, our chat SDK lets you initialize and configure the chat easily. With the server-side, Our solution ensures the most reliable infra-management services for the chat within the app. Furthermore, we will let you know how to install the chat SDK in your app for a better in-app chat experience.

note

Just download our sample app and make a start with your app development. Click here to download the sample app.

SDK License Key#

Follow the below steps to get your license key:

Step 1: Sign up into MirrorFly Console page (https://console.mirrorfly.com/register) for free MirrorFly account, If you already have a MirrorFly account, sign into your account

Step 2: Once you’re in! You get access to your MirrorFly account ‘Overview page’ where you can find a license key for further integration process

Step 3: Copy the license key from the ‘Application info’ section

license-key

Create native dependency#

MirrorFly Chat for Flutter enables realtime chat for one-on-one or group chat among the users within your MirrorFly integrated app. MirrorFly SDK can initialize, configure, chat functionality in both Android and iOS project inside the Flutter application.

We have few quick easy instruction that guide you how to integrate the MirrorFly SDK.

Create flutter dependency#

STEP 1: FlySDK package need to be included in your flutter project in order to consume MirrorFly api’s.

STEP 2: Create a packages folder in your root directory.

STEP 3: Aarfiles

STEP 4: Download flysdk zip file and extract and copy the flysdk folder in the packages folder

STEP 5: Add the below dependencies in pubspec.yaml.

flysdk:
path: packages/flysdk

STEP 5: You can use all classes and methods just with the following import statement

import 'package:flysdk/flysdk.dart';

Registration#

The below method to register a user in sandbox Live mode.

Unless you log out the session, make a note that should never call the registration method more than once in an application

Note: While registration, the below registerUser method will accept the FCM_TOKEN as an optional param and pass it across. The connection will be established automatically upon completion of registration and not required for seperate login.

FlyChat.registerUser(userIdentifier, token: token).then((value) {
if (value.contains("data")) {
// you will get the user registration response
var userData = registerModelFromJson(value);
}
}).catchError((error) {
// Register user failed print throwable to find the exception details.
debugPrint(error.message);
});
ArgumentTypeDescription
userIdentifierStringA unique Id to Register the User. We accept only the AlphaNumeric String
tokenStringA registration token that is generated by FCM SDK for the user's app instance to send message for free

Terminology#

Some of the most common terminologies used in Chat SDK with description

keywordExplanation
userID/userBareIDUnique ID assigned for each user Ex: 12345678 (any alphanumeric). The below characters is not allowed in userId: U+0022 (") U+0026 (&) U+0027 (') U+002F (/) U+003A (:) U+003C (<) U+003E (>) U+0040 (@) userID should follow below specification: https://xmpp.org/extensions/xep-0106.html
userJid (or) JIDuserID+@+domain of the chat server Ex. 12345678@xmpp.chatsystem.dev.contus.us
groupID/groupBareIDUnique ID assigned for each group Ex: group123456 (any alphanumeric). GroupJID = groupID +@mix.+domain of the chat server Ex: group123456@mix.xmpp.mirrorfly.dev.contus.us`
SDK will have built-in functions to prepare the JID, Group JID, and more.

Send a One-to-One Message#

Use the below method to send a text message to other user,

Note: To generate a unique user jid by username, you must call the below method

var userJid = await FlyChat.getJid(username);
FlyChat.sendTextMessage(message, jid, replyMessageId).then((value) {
// you will get the message sent success response
var chatMessage = sendMessageModelFromJson(value);
});
ArgumentTypeDescription
jidStringJID of the end user
messageStringIndicates the text message that needs to be sent
replyMessageIdStringSpecifies the Message ID of replied message

Receive a One-to-One Message#

Here the listeners would be called only when a new message is received from other user. To get more details please visit this callback listeners

FlyChat.onMessageReceived.listen(result){
vat chatMessage = sendMessageModelFromJson(result)
}