JAVASCRIPT SDK
Overview
Ertc javascript SDK is secure, easy to integrate, deploy and manage.
The following principles are followed during development:
- Modularity: Code is segregated into multiple modules
- Ease of Integration: ERTC sdk can be integrated into any web app which is supporting javascript
- Scalability: SDK is highly scalable and can support Enterprise traffic
- Built on Latest Tech Stack
- Data ownership: SDK provides a data layer to effectively manage and control data
- Firebase powered by Google: Highly reliable and scalable
Features
- Individual messages
- Push notifications
- Text, Image, Video, Audio messages
- Typing Indicators
- Delivered and Read receipts
- Chat history
- Chat user list
- Contact details
How to add eRTC SDK to your JS project?
To start with an existing app , use node package manager to install the ertc javascript library, download and install NodeJS. if your system doesn't have it yet.
- Open the terminal and move to your project path.
$ npm install ertc
- Include ertc.js into your default or main page.
<script src="lib/ertc.js"></script>
- Include paho mqtt client library from CDN.
<script
src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.1.0/paho-mqtt.js"
type="text/javascript"></script>
Initializing the Chat SDK
new eRTCSDK().initialise("com.ripbull.ertc");
API documentation
Namespace validation
new TenantModule().validateTenant(namespace, accessCode)
.then(
result => { console.log(result); }
).catch(
error => { console.log(error); });
User Login
new TenantModule().login(username, password)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Change password
new TenantModule().changePassword(oldPassword, newPassword)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Forgot password
new TenantModule().forgetPassword(emailAddress)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Get Chat Users
new UserModule().GetChatUsers(false)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Logout
new UserModule().LogOutUser()
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
User Metadata On – MQTT subscription(To get user updates in real time)
EventManager.subscribe("UserUpdated", function (message) {
console.log(message)
});
Update user profile(with & without profile image)
new UserModule().UpdateUser(this.currentUser.profileStatus, (this.file != null ? this.file : null))
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Set user availability status
val status = AvailabilityStatus.AUTO or AvailabilityStatus.AWAY or AvailabilityStatus.INVISIBLE or AvailabilityStatus.DND
new UserModule().setUserAvailability(value)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Get user availability status
EventManager.subscribe("Availability", function (message) {
console.log(message)
});
Create Group
let groupRecord: GroupRecord = {
name: groupName,
groupDesc: groupDescription,
groupUsers: users,
groupType: groupType
};
new GroupChatModule().createGroup(groupRecord, (this.file != null ? this.file : null))
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Get all groups
new GroupChatModule().getGroups()
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Get group info by groupId
new GroupChatModule().getGroupById(groupId)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Update Group details
new GroupChatModule().updateGroup(groupId, groupName, groupDescription, groupImage, groupType)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Add participants
new GroupChatModule().addParticipants(groupId, users)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Remove participants
new GroupChatModule().removeParticipants(groupId, users)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Add admin
new GroupChatModule().addAdmin(groupId, user)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Remove admin
new GroupChatModule().removeAdmin(groupId, user)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Exit group
new GroupChatModule().exitGroup(groupId)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Remove group pic
new GroupChatModule().removeGroupPic(groupId)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Group Metadata On
EventManager.subscribe("GroupUpdated", function (message) {
console.log(message)
});
Create Thread
new ChatModule().createThread(userChatId)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Follow/UnFollow Thread
Set Follow/Unfollow Thread using update chat method and toggle the value of follow property
let updateMessage: UpdateMessage = {
threadId: threadId,
msgId: chatId,
follow: true/false
}
new ChatModule().updateMessage(updateMessage)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Get Follow Thread
let followThreadRequest: ChatHistoryRequest = {
threadId: "",
threadType: "single",
pagesize: 20,
direction: "past",
currentMsgId: "",
replyChatId: "",
fetchAll: false,
includeCurrent: false,
follow: true
}
new ChatModule().FollowThreads(followThreadRequest)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Send Message
A chat between two users is considered a thread of communication. To initiate a chat between users, you need to create threads and send messages over that threadID.
// Text Message
let message: Message = {
type: MessageType.Text,
message: textMessage
}
// Image
let message: Message = {
type: MessageType.Image,
media: File,
}
// Document
let message: Message = {
type: MessageType.File,
media: File
}
// Contact
let message: Message = {
type: MessageType.Contact,
contact: {
contactName: user.name,
eMailRecords: [email],
phoneNumberRecord: []
}
}
// Giphy
let message: Message = {
type: MessageType.Gify,
gifPath: result
}
new ChatModule().sendMessage(threadId, message)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Get Messages
new ChatModule().getMessages(threadId)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Send Reaction
let message: Reaction = {
emojiCode: emojiCode,
msgId: messageId,
chatReactionType: ChatReactionType.SET,
sendToChannel: 0,
}
new ChatModule().sendReaction(threadId, message)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Message metadata On
EventManager.subscribe('ChatRecieved', , function (message) {
console.log(message)
});
Chat updated
EventManager.subscribe(''ChatUpdated', , function (message) {
console.log(message)
});
Forward chat
//Set forward properties while creating the new chat message
message.isForwarded = true;
message.forwardedMsgId = forwardChatId;
Delete Message
/* there are two option for outgoing message deleteForMe and deleteForEveryOne And one option for incoming message is delete for me
*/
let deleteChat: DeleteMessage = {
deleteType: deleteType //deleteForMe and deleteForEveryOne,
msgIds: [chatId],
threadId: threadId,
}
new ChatModule().deleteChat(deleteChat)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Edit Message
let updateMessage: UpdateMessage = {
threadId: threadId,
msgId: chatId,
message: message
}
new ChatModule().updateMessage(updateMessage)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Report Message
let chatReportRequest: CreateChatReportRequest = {
chatId: chatID,
category: category,
reason: reason
}
new ChatReportModule().CreateChatReport(chatReportRequest)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Undo Report
new ChatReportModule().DeleteChatReport(chatReportId)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Get Reported Message
Chat report list is applicable to admin view
new ChatReportModule().ChatReportList(threadId, category, status, msgType, skip, limit)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Chat Restore
new ChatModule().messageHistory(threadId, threadType, pagesize: number, direction, currentMsgId, replyChatId, includeCurrent, fetchAll)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Search message(local search)
new ChatModule().searchLocalMessageHistory(threadId, searchText)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Search message(global search)
new ChatModule().searchMessageHistory(threadId, searchText, skip, limit)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Mark as Read
new ChatModule().msgReadStatus(chat, MessageStatus.SEEN);
Message Read status – MQTT Listener
EventManager.subscribe('MessageRead', function (message) { console.log(message);});
Block/unblock user
// To block a user: action = “block”
// To unblock a user: action = “unblock”
new ChatModule().blockUnblockUser(action, userChatId)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Mark as favorite
/***********
msgFavList = ArrayList<MessageRecord>
isFavorite = true/false
***********/
new ChatModule().markAsFavorite(msgFavList, isFavorite)
.then(
result => { console.log(result); })
.catch(
error => { console.log(error); });
Typing indicator subscription
EventManager.subscribe('TypingStatus', function (message) {
console.log(message);
});
Typing indicator publish
let typing = {
threadId: threadId,
threadType: "single",
userId: userErtcId,
typingStatus: "on"
}
new TypingModule().typingStatus(typing);
FCM implementation Module
You need FCM registration before Login API. for that you write the below line in your application
new FCMModule().registerFCMToServer(token);