Callback Subscribe API
The API is used to register Callbacks at various different events of AtomChat. These callbacks are processed when particular events of AtomChat are triggered.
You can use the below Syntax for subscribing to any callback
jqcc.cometchat.subscribe(registerCallback);
Params
Json Object of Callback.
registercallback = { 'key' : [function(data){}]}
Register Callback Key Available
Register Callback key | Description |
onMessageReceived | onMessageReceived callback triggers on receiving text chat message from a user |
onMessageSent | onMessageSent triggers when you send a text chat message. |
gotProfileInfo | This callback triggers on receiving the logged-in user's profile information |
gotOnlineList | This callback triggers on receiving contact list |
gotAnnouncement | This callback triggers on receiving an announcement from AtomChat Admin |
gotGroupList | This callback triggers on receiving group list |
onGroupMessageReceived | This callback triggers on receiving text chat message from a user |
onLeaveGroup | This callback triggers when a logged-in user leaves the group |
gotRecentChatsList | This callback triggers on receiving the recent chat contact list |
onAudioVideoCallInit | This callback triggers when Voice & Video Call is initialized |
onAudioVideoCallAccept | This callback triggers when a Voice & Video Call is Accepted |
onAudioVideoCallEnd | This callback triggers when a Voice & Video Call is Ended |
onMessageReceived
onMessageReceived is triggered when you receive a text chat message from another user.
window['onMessageReceived']={'onMessageReceived':[function(data){console.log('data',data)}]};
jqcc.cometchat.subscribe(window['onMessageReceived']);
onMessageSent
onMessageSent is triggered when you send a text chat message to another user.
window['onMessageSent']={'onMessageSent':[function(data){console.log('data',data)}]};
jqcc.cometchat.subscribe(window['onMessageSent']);
gotProfileInfo
gotProfileInfo triggers on receiving the logged-in user's profile information
window['gotProfileInfo']={'gotProfileInfo':[function(data){console.log('data',data)}]};
jqcc.cometchat.subscribe(window['gotProfileInfo']);
gotOnlineList
gotOnlineList triggers on receiving contact list
window['gotOnlineList']={'gotOnlineList':[function(data){console.log('data',data)}]};
jqcc.cometchat.subscribe(window['gotOnlineList']);
gotAnnouncement
gotAnnouncement triggers on receiving an announcement from AtomChat Admin
window['gotAnnouncement']={'gotAnnouncement':[function(data){console.log('data',data)}]};
jqcc.cometchat.subscribe(window['gotAnnouncement']);
gotGroupList
gotGroupList callback triggers on receiving group list
window['gotGroupList']={'gotGroupList':[function(data){console.log('data',data)}]};
jqcc.cometchat.subscribe(window['gotGroupList']);
onGroupMessageReceived
onGroupMessageReceived callback triggers on receiving text chat message from a user
window['onGroupMessageReceived']={'onGroupMessageReceived':[function(data){console.log('data',data)}]};
jqcc.cometchat.subscribe(window['onGroupMessageReceived']);
onLeaveGroup
onLeaveGroup callback triggers when the logged-in user leaves the group
window['onLeaveGroup']={'onLeaveGroup':[function(data){console.log('data',data)}]};
jqcc.cometchat.subscribe(window['onLeaveGroup']);
gotRecentChatsList
gotRecentChatsList callback triggers on receiving recent chat list
window['gotRecentChatsList']={'gotRecentChatsList':[function(data){console.log('data',data)}]};
jqcc.cometchat.subscribe(window['gotRecentChatsList']);
onAudioVideoCallInit
onAudioVideoCallInit callback triggers when Voice & Video Call is initialize
window.onAudioVideoCallInit = function(){ console.log("Audio Video Call Initialise") }
onAudioVideoCallAccept
onAudioVideoCallAccept callback triggers when Voice & Video Call is Accept
window.onAudioVideoCallAccept = function(){ console.log("Audio Video Call Accept") }
onAudioVideoCallEnd
onAudioVideoCallEnd callback triggers when Voice & Video Call is End
window.onAudioVideoCallEnd = function(){ console.log("Audio Video Call End") }
Sample Code for Register Callback
var fucntion1 = function(data){console.log('gotProfileInfo',data)}; registerCallback = { 'gotProfileInfo':[fucntion1,function(data){ console.log('gotProfileInfo1',data); }], 'gotOnlineList':[function(data){ console.log('gotBuddyInfo',data); }], 'onMessageReceived':[function(data){ console.log('onMessageReceived',data); }], 'onGroupMessageReceived':[function(data){ console.log('onGroupMessageReceived',data); }], } var setTime = setInterval(function(){ if(typeof CometChathasBeenRun !== undefined && CometChathasBeenRun == true){ jqcc.cometchat.subscribe(registerCallback); clearInterval(setTime); } },3000);
Javascript APIs
Launch
launch API assists you to dynamically launch a chat box directly from your web pages. The launch API is used to launch a chatbox for One-on-One chat and Groups.
The input parameter is the user’s ID (Check User Section in your AtomChat Admin Panel - UID is user-id) or group id (Check Groups section in your AtomChat Admin Panel - GUID is a unique id of Group) with whom the conversation has to be initiated.
launch (One-on-one Chat)
UID: Unique Id of User.
jqcc.cometchat.launch({uid:UID})
launch (Group Chat)
GUID: Group Unique Id
jqcc.cometchat.launch({guid:"GUID"})
sendMessage
The sendMessage API assists you to send a message on behalf of a logged-in user to another user. The input parameter is the user’s ID to whom the message is to be sent along with the message.
API
toid: The input parameter is the user’s ID to who the message has to be sent along with the message.
message: the message which we want to send to the user.
jqcc.cometchat.sendMessage('toid','message',1);
SAMPLE
<a href="javascript:void(0)" onclick="javascript:jqcc.cometchat.sendMessage('SUPERHERO1','PING!!!',1);">Ping This User</a>
audiovideocall
The audiovideocall API assists you to do one-on-one Audio/Video calls. The input parameter is the user’s ID to whom the Audio Video Call is to be sent.
API
The input parameter is the user’s ID.
jqcc.cometchat.audiovideocall('toid',1);
SAMPLE
<a href="javascript:void(0)" onclick="javascript:jqcc.cometchat.audiovideocall('100',1);">Start Audio/Video Call</a>
audiocall
The audiocall API assists you to do one-on-one Audio Calls. The input parameter is the user’s ID to whom the Audio Call is to be done.
API
The input parameter is the user’s ID.
jqcc.cometchat.audiocall('toid',1);
SAMPLE
<a href="javascript:void(0)" onclick="javascript:jqcc.cometchat.audiocall('100',1);">Start Audio Call</a>
sendGroupMessage
The sendGroupMessage API assists you Launch a chatbox for Groups and Send a Message there. The input parameter is Message & Group Id.
API
The input parameter is guid & message.
jqcc.cometchat.sendGroupMessage('guid', 'message');
<a href="javascript:void(0)" onclick="javascript:jqcc.cometchat.sendGroupMessage('GROUP_554','Hello');">Send Message In This Group</a>
unreadMessageCount
The unreadMessageCount API assists you to get Unread Messages for a particular user or group.
API
The input parameter is uid or guid.
SAMPLE
function callbackfn(data){ console.log(data); } // Get Unread Message Using UID jqcc.cometchat.unreadMessageCount({'uid':5866},callbackfn); // Get Unread Message Count Using GUID jqcc.cometchat.unreadMessageCount({'guid':1},callbackfn);
Is AtomChat Loaded?
The CometChathasBeenRun variable can be used to determine if AtomChat is loaded.
var fucntion1 = function(data){console.log('gotProfileInfo',data)}; registerCallback = { 'gotProfileInfo':[fucntion1,function(data){ console.log('gotProfileInfo1',data) }], 'gotOnlineList':[function(data){ console.log('gotBuddyInfo',data) }], 'onMessageReceived':[function(data){ console.log('onMessageReceived',data) }], 'onGroupMessageReceived':[function(data){ console.log('onGroupMessageReceived',data) }], } var setTime = setInterval(function(){ if(typeof CometChathasBeenRun != undefined){ jqcc.cometchat.subscribe(registerCallback); clearInterval(setTime); } },3000);
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article