Creating XMPP Object (Detail)
Following code shows how to call Connect function of xmppClient object with all the callback handling.
xmppClient.connect({
username:<username>,
password:<password>,
resource:<resource>,
host:'<ip-address-of-xmpp-server>',
http_ws_url:'<url-to-websocket-to-websocket>',
debug:1, //0=disabled, 1=enabled
onFailure:function(msg){
/*
* Handle what to do if it fails to connect to XMPP Server
*
* @param {String} msg - This will contain reason of failure.
*/
},
onSuccess:function(){
/*
* Handle what to do after connection establishes
*
* This function will be called after receiving roster (contact list) from server
*/
},
onDisconnect:function(msg){
/*
* Handle what to do if connection is disconnected
*
* @param {String} msg - This will contain some termination message
*/
},
onMessageReceive:function(message){
/*
* This function will be triggered if a message is received from XMPP
*
* @param {Object} message - message is JSON object which will contain following keys.
* {String} id - Unique ID of message received
* {String} from - Full JID of sender
* {String} to - JID of receiver
* {String} text - Message text as string
* {String} type - chat/ offline/ archive/ carbon
* {Object} delay - This JSON Object will be available only in case if type is archive or offline, and it will contain following
* {String} text - Some text
* {String} time - Time when message was received by server.
*/
},
onPresenceReceive:function(presence){
/*
* Handle what to do when presence (online/ offline status) is received
*
* @param {Object} presence - presence is a JSON Object with following keys
* {String} from - Full Jid of another user
* {String} type - available/ unavailable
* {String} status - Any custom message set by another user
*/
},
onSubscriptionRequestReceive:function(request){
/*
* This function will trigger if other user sends use subscription request
*
* @param {Object} request - request is a JSON Object with following keys
* {String} from - Full Jid of another user
* {String} type - subscribe
* {String} status - Any custom message set by another user
*/
},
onSubscriptionRequestAccept:function(request){
/*
* This function will trigger if other user accepts our friend request
*/
},
onSubscriptionRequestRejectOrCancel:function(request){
/*
* This function will trigger if other user denies our subscription request or cancels previously granted permission
*/
},
onUnSubscribe:function(request){
/*
* This function will trigger if other user is un-subscribing from our presence information.
*/
},
onTypingStatusChange:function(from, status){
/*
* This function will notify us about other user's typing status
*
* @param {String} from - Full Jid of other user
* @param {String} status - composing/ paused/ active/ inactive/ gone
*/
},
onRosterReceive:function(roster){
/*
* This function will be triggered when roster (contact list) is received from server
*
* @param {Array} roster - Array of Roster Entry and each Roster Entry will contain following
*
* {String} jid - JID of contact
* {String} name - Name of contact
* {String} subscription - Subscription state none/ both/ to/ from
* {String} group - Group of contact
* {String} ask - whether a request is pending from another end
*/
},
onDelivered:function(from, id){
/*
* This function will notify us about the delivery status of message sent
*
* @param {String} from - Full Jid of message receiver
* @param {String} id - Message id of message we sent.
*
*/
},
onArchiveReceive:function(info){
/*
* Handle what to do if connection is disconnected
*
* @param {Object} info - This JSON Object will contain info of archive, it will contain following keys
* {String} jid - Full Jid of user whose archive is requested.
* {String} first - First message Id
* {String} last - List message Id
* {int} count - Total messages
* {String} complete - true/ false (Whether or not we have received all messages)
*/
},
onRosterPush:function(rosterEntry){
/*
* This function will be triggered, whenever roster (contact list) is updated
*
* @param {Object} rosterEntry - This JSON object will contain following keys.
* {String} name - Name of user
* {String} group - Group of user
* {String} ask - Whether a request is panding from another user's end, the value of ask will be "subscribe"
*/
},
onRosterEntryRemove:function(rosterEntry){
/*
* Handle what to do after a user removed a roster entry.
*
* @param {Object} rosterEntry - This JSON object will contain following keys
* {String} jid - JID of user whose entry is removed
* {String} subscription -
*/
},
onBlockListReceive:function(blockList){
/*
* This function will be triggered, on receiving blocked user list
*
* @param {Array} blockList - Array will contain JIDs of blocked users.
*/
}
});