One-on-One

To add One-on-One Chat support in your application,

Include CustomUI.js in your index.html file to access the Custom UI functionality in your Cordova app

All the method calls will invoke their respective callback blocks as defined below.

1. Subscribe to CometChat

Start receiving messages, user’s list and logged-in user’s profile data. mode signifies receiving messages with emoji support.



function callbackmeth(result){

  alert(result);

}

CustomUI.subscribe(ture,callbackmeth);

(i)
Invocation: When server sends an update related to logged-in user’s profile
Response: Callback containing the current user’s profile.
Eg:

"myinfo" = {
    "id"="5";
    "n"="MyName";
    "l"="MyLastName";
    "a"="avatar.png";
    "s"="available";
    "m"="I'm available";
}

(ii)
Invocation: When the server sends an updated user’s list
Response: Callback containing the user’s list.
Eg:

"getonlineusers"={
    "_1" = {
        "id"="1";
        "n"="User1";
        "a"="avatar.png";
        "d"="1";
        "s"="available";
        "m"="I'm available";
    };
	
    "_2" = {
        "id"="2";
        "n"="User2";
        "a"="avatar.png";
        "d"="1";
        "s"="available";
        "m"="I'm available";
    };
}

(iii)
Invocation: When a message is received
Response: Callback containing messages and its details

Field ‘message_type’ indicates the type of received message.
Types of messages received in this callback:

message_type = 10: For normal text messages
message_type = 11: For join chatroom invite message
message_type = 12: For image messages
message_type = 13: For handwritten messages
message_type = 14: For video messages
message_type = 17: For audio messages
message_type = 18: For file messages

Eg:
Text message

"messagereceived"={
    "id"= "64";
    "message"= "Hello";
    "self"= 0;
    "old"= "1";
    "sent"= 1411035449792;
    "from"= "73";
    "message_type" = 10;
}

Join Chatroom message

"messagereceived"={
    "id"= "64";
    "message"= {
        "chatroom_id" = 23;
        "chatroom_name" = "test-ccc";
        "chatroom_password" = da39a3ee5e6b4b0d3255bfef95601890afd80709;
    };
    "self"= 0;
    "old"= "1";
    "sent"= 1411035449792;
    "from"= "73";
    "message_type" = 11;
}

Image message

"messagereceived"={
    "id"= "64";
    "message"= "http://yoursite.com/cometchat/plugins/filetransfer/download.php
                file=a1d28da22369e330fab64e0250226d0b.png&unencryptedfilename=Image.png";
    "self"= 0;
    "old"= "1";
    "sent"= 1411035449792;
    "from"= "73";
    "message_type" = 12;
}

Handwritten message

"messagereceived"={
    "id"= "64";
    "message"= "http://yoursite.com/cometchat/plugins/handwrite/uploads/9384627441b49aad5ef6bace29cdcd36.png";
    "self"= 0;
    "old"= "1";
    "sent"= 1411035449792;
    "from"= "73";
    "message_type" = 13;
}

Video message

"messagereceived"={
    "id"= "64";
    "message"= "http://yoursite.com/cometchat/plugins/filetransfer/download.php?      
                file=a1d28da22369e330fab64e0250226d0b.png&unencryptedfilename=Video.mp4";
    "self"= 0;
    "old"= "1";
    "sent"= "1035449792;
    "from"= "73";
    "message_type" = 14;
}

Audio message

"messagereceived"={
    "id"= "64";
    "message"= "http://yoursite.com/cometchat/plugins/filetransfer/download.php?      
                file=a1d28da22369e330fab64e0250226d0b.png&unencryptedfilename=sample.mp3";
    "self"= 0;
    "old"= "1";
    "sent"= "1035449792;
    "from"= "73";
    "message_type" = 17;
}

File message

"messagereceived"={
    "id"= "64";
    "message"= "http://yoursite.com/cometchat/plugins/filetransfer/download.php?      
                file=a1d28da22369e330fab64e0250226d0b.png&unencryptedfilename=sample.txt";
    "self"= 0;
    "old"= "1";
    "sent"= "1035449792;
    "from"= "73";
    "message_type" = 18;
}

(iv)
Invocation: When the admin sends a site-wide announcement
Response: Callback containing the announcement message details.
Eg:

"announcementreceived"={
    "id"= "55";
    "m"="hello";
}

(v)
Invocation: When an audio video chat message is received
Response: Callback containing audio video chat messages and its details
Eg:

"avchatmessagereceived"={
    "to"= 105;
    "id"= "64";
    "message"="AVCHAT_CALL_ACCEPTED";
    "self"= 0;
    "old"= "1";
    "sent"= 1411035449792;
    "from"= "73";
    "message_type" = 31;
}

Field ‘message_type’ indicates the type of received message.
Types of messages received in this callback:

AVCHAT_CALL_ACCEPTED
message_type = 31: Audio video call request has been accepted

AVCHAT_INCOMING_CALL
message_type = 32: Incoming audio video call request

AVCHAT_INCOMING_CALL_USER_BUSY
message_type = 33: Incoming audio video call request while user is busy

AVCHAT_END_CALL
message_type = 34: Audio video call has been ended

AVCHAT_REJECT_CALL
message_type = 35: Audio video call request has been rejected

AVCHAT_CANCEL_CALL
message_type = 36: Audio video call has been cancelled

AVCHAT_NO_ANSWER
message_type = 37: No answer received for audio video call request sent

AVCHAT_BUSY_CALL
message_type = 38: Busy call received for audio video call request sent

(vi)
Invocation: When server sends is typing status.
Response: Callback containing the current user’s is typing status.
Eg:

"actionmessagereceived"={
    "action":"typing_start",
    "from":"12",
    "sent":"1450849776899"
}

OR

"actionmessagereceived"={
    "action":"typing_stop",
    "from":"12",
    "sent":"1450849780098"
}

2. Send message

Send text/emoji message to another user by specifying userID. (Ensure that userID and message must not be nil or an empty string)



function callbackmeth(result){

  alert(result);

}

CustomUI.sendMessage("Hi! How are you?","2",callbackmeth);

(i)
Invocation: When message is sent successfully
Response: Callback containing the message details
Eg:

"success"={
    "id"="71";
    "m"="Hi! How are you?";
}

3. Send Image

a) Send image message in the form of imageData to another user by specifying userID. (Ensure that imageData and userID should not be nil)


function callbackmeth(result){

  alert(result);

}

CustomUI.sendImageWithData(imageData,"2",callbackmeth);

Return type: void
Callback Blocks:
(i)
Invocation: When an image is sent successfully.
Response: Callback containing the message id of image message and original image data.
Eg:

"success"={
    "id"="71";
    "m"="<ffd8ffe0 00104a46 49460001 01010048 00480000 ffdb0043 00030202 02020203 02020203 03030304 06040404 04040806 
            06050609 080a0a09 0809090a 0c0f0c0a 0b0e0b09 090d110d 0e0f1010 11100a0c 12131210 130f1010 10ffdb00 430103
            03 03040304 08040408 100b090b>";
}

b) Send image at given imagePath to another user by specifying userID. The image file should exist at the given path location. (Ensure that nil or empty imagePath and userID should not be sent)



function callbackmeth(result){

  alert(result);

}

CustomUI.sendImageWithPath("/var/mobile/Containers/Data/Application/F9778125-2506-4DED-9CDE-
                                89146DF4D1EB/Documents/IMG1049.JPG","2",callbackmeth);

(i)
Invocation: When an image at specified path is sent successfully.
Response: Callback containing the message id of sent image message and the original image path
Eg:

"success"={
    "id"="71";
    "m"="/var/mobile/Containers/Data/Application/F9778125-2506-4DED-9CDE-89146DF4D1EB/Documents/IMG1049.JPG";
}

4. Audio File

Send file at given audioPath to another user by specifying userID. The audio file should exist at the given path location. (Ensure that nil or empty audioPath and userID should not be sent)



function callbackmeth(result){

  alert(result);

}

Custom.UI.sendAudioWithPath("/var/mobile/Containers/Data/Application/F9778125-2506-4DED-9CDE-
                                89146DF4D1EB/Documents/sample.mp3","2",callbackmeth);

Invocation: When an audio file at specified path is sent successfully.
Response: Callback containing the message id of sent file message and the original file path
Eg:

"success"={
    "id"="71";
    "m"="/var/mobile/Containers/Data/Application/F9778125-2506-4DED-9CDE-89146DF4D1EB/Documents/sample.mp3";
}

5. Send File

Send file at given filePath to another user by specifying userID. The file should exist at the given path location. (Ensure that nil or empty filePath and userID should not be sent)



function callbackmeth(result){

  alert(result);

}

CustomUI.sendFileWithPath("/var/mobile/Containers/Data/Application/F9778125-2506-4DED-9CDE-
                                89146DF4D1EB/Documents/sample.txt","2",callbackmeth);

Invocation: When an file at specified path is sent successfully.
Response: Callback containing the message id of sent file message and the original file path
Eg:

"success"={
    "id"="71";
    "m"="/var/mobile/Containers/Data/Application/F9778125-2506-4DED-9CDE-89146DF4D1EB/Documents/sample.txt";
}

6. Send Video

a) Send video at given videoPath to the userID specified. The video file should exist at the given path location and must be in mp4 format. (Ensure that videoPath and userID should not be nil or empty)


function callbackmeth(result){

  alert(result);

}

CustomUI.sendVideoWithPath("/var/mobile/Containers/Data/Application/F9778125-2506-4DED-9CDE-89146DF4D1EB
                                 /Documents/IMG0180.mp4","2",callbackmeth);

(i) (void(^)(NSDictionary *response))response
Invocation: When a video at given path is sent successfully.
Response: Callback containing the message id of video message and original video path
Eg:

"success"={ 					
    "id"="74";
    "m"="/var/mobile/Containers/Data/Application/F9778125-2506-4DED-9CDE-89146DF4D1EB/Documents/IMG0180.mp4";
}

b) Send video using NSURL to the userID specified. NSURL can be obtained either by accessing UIImagePickerControllerMediaURL property of a video when it is selected using UIImagePickerController or by converting path of given video to NSURL. (Ensure that videoURL and userID should not be nil or empty)


function callbackmeth(result){

  alert(result);

}

CustomUI.sendVideoWithURL(videoURL,"2",callbackmeth);

(i)
Invocation: When video message is sent successfully using given videoURL
Response: Callback containing the message id of sent video message and original videoURL
Eg:

"success"={
    "id"="71";				 
    "m"="Users/MyPC/Desktop/72fd88e9abc28c04ef4b98d3bd62b483.3gp -- file:///”
}

7. Get user’s profile details

Get the profile details corresponding to the userID. This function can also be used to get logged-in user’s details. (Ensure that userID should not be nil or empty)



function callbackmeth(result){

  alert(result);

}

CustomUI.getUserInfo("5",callbackmeth);

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: When the profile details corresponding to the userID is requested .
Response: NSDictionary containing the user’s profile.
Eg:

{
    "id"="5";
    "n"="a";
    "l"="";
    "a"="img.png";
    "s"="available";
    "m"="I'm available";
}

8. Change online status

Change logged-in user’s status to ‘Available’, ‘Busy’, ‘Invisible’, ‘Offline’ by selecting the proper status value from enum STATUS_OPTIONS.



function callbackmeth(result){

  alert(result);

}

CustomUI.changeStatus(0,callbackmeth);

(i)
Invocation: When status is updated successfully.
Response: Callback containing the success message.
Eg:

"success"={
    "Message"="Change status successful";	
}

9. Change status message

To change logged-in user’s status message. (Ensure that statusMessage should not be nil or empty)



function callbackmeth(result){

  alert(result);

}

CustomUI.changeStatusMessage("Exam Time!!",callbackmeth);

(i)
Invocation: When status message is updated successfully.
Response: Callback containing the success message.
Eg:

"success"={
    "Message"="Change status message successful"
}

10. Get the list of currently active users



function callbackmeth(result){

  alert(result);

}

CustomUI.getOnlineUsersWithResponse(callbackmeth);

(i)
Invocation: When online user’s list is requested.
Response: Callback containing the user’s list.
Eg:

"success"={
    "_1" = {
        "id"="1";
        "n"="User1";
        "a"="avatar.png";
        "d"="1";
        "s"="available";
        "m"="I'm available";
    };	
    "_2" = {
        "id"="2";
        "n"="User2";
        "a"="avatar.png";
        "d"="1";
        "s"="available";
        "m"="I'm available";
    };
}

11. Block User

To block the user corresponding to given userID. Once the user is blocked successfully, you will not be able to send/receive messages to/from the respective user.



function callbackmeth(result){

  alert(result);

}

CustomUI.blockUser("102",callbackmeth);

Invocation: Triggered when block user response is received.
Response: Callback containing id of blocked user.
Eg:

"success"={
    "id"="102";
}

12. Unblock User

To unblock user corresponding to given userID. Once the user is unblocked successfully, you will be able to send/receive messages to/from the respective user.



function callbackmeth(result){

  alert(result);

}

CustomUI.unblockUser("102",callbackmeth);

Invocation: Triggers when the user is successfully unblocked.
Response: Callback containing id of unblocked user.
Eg:

"success"={  
    "id"="102";
}

13. Get list of blocked users



function callbackmeth(result){

  alert(result);

}

CustomUI.getBlockedUsersWithResponse(callbackmeth);

(i) (void(^)(NSDictionary *response))response
Invocation: When blocked user’s list is requested.
Response: Callback containing the blocked user’s list.
Eg:

"success"={
    "73"=
    {
        "id"="73";
        "name"="user73”;
    };
    "700"=
    {
        "id"="70";
        "name"="user70”;
    };
}

14. Fetch all announcements



function callbackmeth(result){

  alert(result);

}

CustomUI.getAllAnnouncements(callbackmeth);

(i)
Invocation: When announcements list is requested.
Response: Callback containing the list of announcements.
Eg:

"success"={
    "_2"=
    {
        "id"="2";
        "m"="Test 2";
        "t"="1416576762";
    };
    "_1"=
    {
        "id"="1";
        "m":"Announcements test";
        "t":"1416576743";
    }
}

15. Get chat history

To get chat history of particular user. Specify the friendID and messageID of the oldest message present in the application. The server will return messages exchanged prior to this given messageID. (Ensure that userID and messageID should not be nil or empty)



function callbackmeth(result){

  alert(result);

}

CustomUI.getChatHistoryOfUser("14","-1",callbackmeth);

Parameters:
(i) friendID: The id of the user with whom you want to fetch the conversation with.

(ii) messageID: The messages fetched will be before this particular ID. If you do not have any ‘messageID’ OR you want the entire messages history, pass @”-1” to get the messages. The number of messages is set from CometChat Administration panel.

(i)
Invocation: When chat history of user is received from server.
Response: Callback containing the history messages.
Eg:

"success"={
    history = (
    {
        from = 14;
        id = 4843;
        message = rty;
        "message_type" = 10;
        old = 1;
        self = 1;
        sent = 1429771974000;
    };
    {
        from = 14;
        id = 4844;
        message = reyrey;
        "message_type" = 10;
        old = 1;
        self = 1;
        sent = 1429771987000;
    };
    {
        from = 14;
        id = 4845;
        message = 57457;
        "message_type" = 10;
        old = 1;
        self = 1;
        sent = 1429772014000;
    };
    {
        from = 14;
        id = 4846;
        message = 457547457457;
        "message_type" = 10;
        old = 1;
        self = 0;
        sent = 1429772019000;
    }
    );
}

16. Translate Conversation

To translate ‘OneOnOne’ and ‘Chatroom’ conversations in the selected language. Refer to LANGUAGE enum for language values.



function callbackmeth(result){

  alert(result);

}

CustomUI.setTranslationLanguage(0,callbackmeth);

17. To check whether CometChat is installed at specified URL location. Returns the URL of CometChat installation directory. (Ensure that siteURL nil or empty)



function callbackmeth(result){

  alert(result);

}

CustomUI.isCometChatInstalled("http://www.yoursite.com/",callbackmeth);

(i)
Invocation: When CometChat installation directory is found at specified URL.
Response: Callback containing the exact location of CometChat installation directory.
Eg:

"success"={
    "cometchat_url"="http://www.yoursite.com/cometchat”;
}

18. To check whether plugins are enabled or disabled.


function callbackmeth(result){

  alert(result);

}

CustomUI.getPluginInfo(callbackmeth);

(i)
Invocation: When plugin information is fetched successfully.
Response: Callback containing plugins with enable/disable flag.
Eg:

"success"={
    avchat_enabled="1";
    createchatroom_enabled="1";
    blockuser_enabled="0";
    mediasharing_enabled="1";
    chatroom_mediasharing_enabled="1";
    realtime_translate_enabled="0";
}

19. isTyping…
Now you can make your chat more alive by sending typing.. information to another user, so the other user will know you are typing some text to him.
Note that this feature will only work from CometChat v5.7 onwards and by using CometService.
To send a message that you are typing you need to use isTyping method. The syntax of this function is as follows:



function callbackmeth(result){

  alert(result);

}

CustomUI.isTyping(flag,channel,callback);

Parameters:
(i) flag: This is BOOL value, pass YES when you start typing, pass NO when you stop typing.
(ii) channel: This is the channel id to whom you are chatting with. You will get the channel from the user list as “ch” channel when you enable the CometService.

20. Unsubscribe

To stop receiving OneOnOne messages, user’s list and logged-in user’s profile data.


CustomUI.unsubscribe();

Please refer ‎error codes for failure responses.

Not finding what you need?

The CometChat team is here to help!