Connly SDK
Connly Client JS SDK for chat
Connly SDK is a client-side JavaScript SDK designed to facilitate real-time communication features such as messaging, typing indicators, user presence, and more.
Package Installation
Using NPM
npm install connly
Using YARN
yarn add connly
Monolithic Import
In ESM/Typescript
import Connly from 'connly';
In CommonJS
var Connly = require('connly');
Get Started
Initializing the Connly SDK Object
var serverUrl = 'https://socket.connle.com';
var token = 'your-authentication-token';
var connly = new Connly(serverUrl, token);
Note
To generate a user token, refer to the Login Token V3 documentation.
Connection
To establish a connection, call the connect() method after initializing the Connly instance.
connly.connect();
Connly Methods
Connect
Using this method, user can able to connect to the server.
connly.connect();
Disconnect
Using this method, user can able to disconnect from the server.
connly.disconnect();
Set Status
Using this method, user can able to set their online status.
connly.setStatus('online');
Configuration Parameters
| Parameter | type | Description |
|---|---|---|
| status | string | User status ('online', 'offline', etc.) |
Send Message
Using this method, user can able to send a message.
var messageContent = {
message_id: "345e6789-g09c-34e5-c678-636819384002",
receiver_id: "765e4321-g32b-34e5-c678-636819384789",
service: "text",
type: "msg",
content: "Hello, this is a text message!"
};
connly.sendMessage(messageContent, function (ack) {
// Message sent acknowledgment
});
Send Typing Status
Using this method, user can able to send typing indicator.
var typingDetails = {
to: 'recipientUserId',
isTyping: true,
};
connly.sendTypingStatus(typingDetails);
Send Read Receipt
Using this method, user can able to send read receipt for a message.
var readReceiptDetails = {
messageId: 'messageId123',
readerId: 'yourUserId',
};
connly.sendReadReceipt(readReceiptDetails);
Send Reaction
Using this method, user can able to send a reaction to a message.
var reaction = {
message_id: "123e4567-e89b-12d3-a456-426614174000",
reaction_type: "👍"
};
connly.sendReaction(reaction, function (ack) {
// Reaction sent acknowledgment
});
Connly Event Handlers
onConnect
This event will trigger when user connected successfully.
connly.onConnect(function (data) {
if (data.isConnected) {
// Connected successfully
}
});
onDisconnect
This event will trigger when user disconnected.
connly.onDisconnect(function (data) {
if (!data.isConnected) {
// Disconnected from server
}
});
onStatus
This event will trigger when user status is updated.
connly.onStatus(function (data) {
// User status updated
});
onMessage
This event will trigger when a new message is received.
connly.onMessage(function (data) {
// Received message
});
onTypingStatus
This event will trigger when typing status is received.
connly.onTypingStatus(function (data) {
// Typing status received
});
onReadReceipt
This event will trigger when a read receipt is received.
connly.onReadReceipt(function (data) {
// Read receipt received
});
onDeliveryReceipt
This event will trigger when a delivery receipt is received.
connly.onDeliveryReceipt(function (data) {
// Delivery receipt received
});
onCallAction
This event will trigger when a call action is received.
connly.onCallAction(function (data) {
// Call action received
});
onPresence
This event will trigger when user presence is updated.
connly.onPresence(function (data) {
// User presence updated
});
onReaction
This event will trigger when a reaction is received.
connly.onReaction(function (data) {
// Reaction received
});
onError
This event will trigger when an error occurs.
connly.onError(function (error) {
// An error occurred
});