0 purchases
vdotok connect
vdotok_connect #
Getting Started #
IOS: #
Add the following entry to your Info.plist file, located in < project root >/ios/Runner/Info.plist:
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) Camera Usage!</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) Microphone Usage!</string>
copied to clipboard
Android: #
Ensure the following permission is present in your Android Manifest file
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
copied to clipboard
Create Client Instance: #
First we need to create an instance of emitter client.
Emitter emitter = Emitter.instance;
copied to clipboard
Add listeners: #
Below described main helpful callbacks and listeners:
emitter.onConnect = (bool response)
{
// called when you are connected to emitter
};
emitter.onPresence = (String response)
{
// called when you get the presence of a User
};
emitter.onsubscribe = (String value)
{
// called when the User subscribes to a group
};
emitter.onMessage = (String mesg) async
{
// called whenever any pub/sub occurs
};
emitter.internetConnectivityCallBack = (String mesg)
{
// called whenever your device is connected to internet or disconnected from internet
};
copied to clipboard
Models: #
Below are the Models:
// Use this Model for login/sign up
class User {
final String auth_token;
final String authorization_token;
final String email;
final String full_name;
final String message;
final int process_time;
final String ref_id;
final int status;
final int user_id;
}
// Use this Model for Groups
class GroupModel {
dynamic admin_id;
dynamic auto_created;
dynamic channel_key;
dynamic channel_name;
dynamic group_title;
dynamic id;
dynamic created_datetime;
}
// Use this Model for Getting All Users
class Contact {
int user_id;
dynamic email;
String ref_id;
String full_name;
}
// Use this Model for Chat
class ChatModel {
var id;
var to;
var key;
var from;
var type;
var content;
var date;
int status;
var size;
var isGroupMessage;
var subtype;
}
copied to clipboard
Constants: #
Class used in Receipt Type to inform Status of the Message:
class ReceiptType {
static var sent = 1;
static var delivered = 2;
static var seen = 3;
}
copied to clipboard
Class to Identify the Type of File:
class MediaType {
static int image = 0;
static int audio = 1;
static int video = 2;
static int file = 3;
}
copied to clipboard
Class to Identify Notification Type:
class NotificationType {
static const String newGroup = "new";
static const String deleteGroup = "delete";
static const String modifyGroup = "modify";
}
copied to clipboard
Class to Identify the Type of Message:
class MessageType {
static const String text = "text";
static const String media = "media";
static const String file = "file";
static const String thumbnail = "thumbnail";
static const String path = "path";
static const String typing = "typing";
static const String ftp = "ftp";
static const String acknowledge = "acknowledge";
static const String receipts = "receipts";
}
copied to clipboard
SDK Methods: #
Use this method to connect socket.
emitter.connect(
String clientId, // in login/sign up response
bool reconnectivity, // true
String refId, // in login/sign up response
String authorizationToken, // in login/sign up response
String projectId,
String host, // in login/sign up response
String port // in login/sign up response
);
copied to clipboard
Subscription: #
Use this method to subscribe to a chat or group.
emitter.subscribe(String channelKey,String channelName);
copied to clipboard
SubscribePresence: #
Use this method to acknowledge the availability of the user.
emitter.subscribePresence(String channelKey, String channelName, bool changes, bool status)
copied to clipboard
Publish: #
Use this method to publish message of object type which can be of any type i-e text, audio, video, document, or image type.
Packet for Publishing Messages
var sendMessage = {
"from": // your refId
"content": // text/file/image/video/,mp3
"id": // random Id,
"key": // group channel_key,
"subType": // use this in case of media sharing file,image,video,audio i.e. MediaType.image
"fileExtension": // use this in case of media sharing i.e. .mp3, .doc, .mp4
"type": // MessageType enum value mentioned above i.e. MessageType.text
"to": // channel_name
"isGroupMessage": false,
"date": // current date
"status": // ReceiptType enum value mentioned above i.e. ReceiptType.sent
"size": 0.0
};
emitter.publish(String channelKey, String channelName, Map < String, dynamic > sendMessage, int ttl);
copied to clipboard
Publish Notification: #
Use this method to publish notification of group creation, deletion and modification.
Packet for Publishing Notification
var tempdata =
{
"from": // your own refId,
"data": {
"action": "new", //new, modify, delete
"groupModel": // use GroupModel here mentioned above
},
"to": // group's participants refId list
};
emitter.publishNotification(Map < String, dynamic > tempdata);
copied to clipboard
Listener for Internet Connection/Disconnection #
Use this method to listen changes every time the User’s device is connected to internet or disconnected from internet.
signalingClient.checkConnectivity();
copied to clipboard
Internet Status #
Use this method to check whether or not the User’s device is connected to internet. It will return true or false value.
signalingClient.getInternetStatus();
copied to clipboard
Example: #
Emitter emitter = Emitter.instance;
bool isSocketConnect = false;
@override
void initState()
{
super.initState();
emitter.connect(
clientId: getUser!.user_id.toString(),
reconnectivity: true,
refId: getUser!.ref_id,
authorizationToken: getUser!.authorization_token,
projectId: project_id,
host: authProvider.host,
port: authProvider.port
);
emitter.onConnect = (bool response) {
if (response) {
setState((){
isSocketConnect = true;
});
}
else {
setState((){
isSocketConnect = true;
});
}
};
subscribeChannel(groupModel.channel_key, groupModel.channel_name){
emitter.subscribe(channel_key,channel_name);
}
emitter.onSubscribe = (value) {
if (value == groups!.last!.channel_key + "/" + groups!.last!.channel_name)
{
changeState();
}
};
subscribePresence(groupModel.channel_key, groupModel.channel_name, changes, status){
emitter.subscribePresence(channel_key, channel_name, changes, status);
}
emitter.onPresence = (String response) {
handlePresence(json.decode(response));
};
var tempData = {
"id": generateMd5(groupModel.channel_key),
"to":groupModel.channel_name,
"key": groupModel.channel_key,
"from": getUser!.ref_id,
"type": MessageType.ftp || MediaType.text
"content": textController.text,
"size": 0.0,
"isGroupMessage": false,
"date": ((DateTime.now()).millisecondsSinceEpoch).round(),
"status": ReceiptType.sent,
"subType": MediaType.image,
"fileExtension": .jpg
};
emitter.publish( groupModel.channel_key, groupModel.channel_name, tempData, 0);
emitter.onMessage = (msg) async {
var message = json.decode(msg); // use this variable for future
};
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.