quickblox 2.15.2 → 2.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,7 +22,7 @@ if (Utils.getEnv().browser) {
22
22
  Strophe.addNamespace('CHAT_STATES', chatUtils.MARKERS.STATES);
23
23
  } else if (Utils.getEnv().nativescript) {
24
24
  XMPP = require('nativescript-xmpp-client');
25
- } else if (Utils.getEnv().node) {
25
+ } else if (Utils.getEnv().node) {
26
26
  XMPP = require('node-xmpp-client');
27
27
  }
28
28
 
@@ -68,7 +68,7 @@ function ChatProxy(service) {
68
68
  },
69
69
  'autostart': false
70
70
  });
71
- // node-xmpp-client
71
+ // node-xmpp-client
72
72
  } else if (Utils.getEnv().node) {
73
73
  self.Client = new XMPP({
74
74
  'autostart': false
@@ -78,7 +78,7 @@ function ChatProxy(service) {
78
78
  // override 'send' function to add some logs
79
79
  originSendFunction = self.Client.send;
80
80
 
81
- self.Client.send = function(stanza) {
81
+ self.Client.send = function (stanza) {
82
82
  Utils.QBLog('[QBChat]', 'SENT:', stanza.toString());
83
83
  originSendFunction.call(self.Client, stanza);
84
84
  };
@@ -96,7 +96,7 @@ function ChatProxy(service) {
96
96
 
97
97
  this._checkConnectionTimer = undefined;
98
98
  this._checkConnectionPingTimer = undefined;
99
- this._localPingFaildCounter = 0;
99
+ this._chatPingFailedCounter = 0;
100
100
  this._onlineStatus = true;
101
101
  this._checkExpiredSessionTimer = undefined;
102
102
  this._sessionHasExpired = false;
@@ -118,10 +118,10 @@ function ChatProxy(service) {
118
118
  //
119
119
  this.chatUtils = chatUtils;
120
120
 
121
- if (config.streamManagement.enable){
121
+ if (config.streamManagement.enable) {
122
122
  if (config.chatProtocol.active === 2) {
123
123
  this.streamManagement = new StreamManagement(config.streamManagement);
124
- self._sentMessageCallback = function(messageLost, messageSent) {
124
+ self._sentMessageCallback = function (messageLost, messageSent) {
125
125
  if (typeof self.onSentMessageCallback === 'function') {
126
126
  if (messageSent) {
127
127
  self.onSentMessageCallback(null, messageSent);
@@ -158,61 +158,61 @@ function ChatProxy(service) {
158
158
  */
159
159
 
160
160
  /**
161
- * You need to set onMessageListener function, to get messages({@link https://docs.quickblox.com/docs/js-chat-messaging#subscribe-message-events read more}).
161
+ * You need to set onMessageListener function, to get messages. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Create_new_dialog More info.}
162
162
  * @function onMessageListener
163
163
  * @memberOf QB.chat
164
- * @param {Number} userId - Sender id.
165
- * @param {Object} message - The message model object.
164
+ * @param {Number} userId - Sender id
165
+ * @param {Object} message - The message model object
166
166
  **/
167
167
 
168
168
  /**
169
- * Blocked entities receive an error when try to chat with a user in a 1-1 chat and receivie nothing in a group chat.
169
+ * Blocked entities receive an error when try to chat with a user in a 1-1 chat and receivie nothing in a group chat. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Blocked_user_attempts_to_communicate_with_user More info.}
170
170
  * @function onMessageErrorListener
171
171
  * @memberOf QB.chat
172
- * @param {Number} messageId - The message id.
173
- * @param {Object} error - The error object.
172
+ * @param {Number} messageId - The message id
173
+ * @param {Object} error - The error object
174
174
  **/
175
175
 
176
176
  /**
177
- * This feature defines an approach for ensuring is the message delivered to the server. This feature is unabled by default({@link https://docs.quickblox.com/docs/js-chat-messaging#check-if-a-message-is-sent read more}).
177
+ * This feature defines an approach for ensuring is the message delivered to the server. This feature is unabled by default. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Sent_message More info.}
178
178
  * @function onSentMessageCallback
179
179
  * @memberOf QB.chat
180
- * @param {Object} messageLost - The lost message model object (Fail).
181
- * @param {Object} messageSent - The sent message model object (Success).
180
+ * @param {Object} messageLost - The lost message model object (Fail)
181
+ * @param {Object} messageSent - The sent message model object (Success)
182
182
  **/
183
183
 
184
184
  /**
185
- * Show typing status in chat or groupchat({@link https://docs.quickblox.com/docs/js-chat-messaging#send-typing-indicators read more}).
185
+ * Show typing status in chat or groupchat. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Typing_status More info.}
186
186
  * @function onMessageTypingListener
187
187
  * @memberOf QB.chat
188
- * @param {Boolean} isTyping - Typing Status (true - typing, false - stop typing).
189
- * @param {Number} userId - Typing user id.
190
- * @param {String} dialogId - The dialog id.
188
+ * @param {Boolean} isTyping - Typing Status (true - typing, false - stop typing)
189
+ * @param {Number} userId - Typing user id
190
+ * @param {String} dialogId - The dialog id
191
191
  **/
192
192
 
193
193
  /**
194
- * Receive delivery confirmations({@link https://docs.quickblox.com/docs/js-chat-messaging#mark-message-as-delivered read more}).
194
+ * Receive delivery confirmations {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Delivered_status More info.}
195
195
  * @function onDeliveredStatusListener
196
196
  * @memberOf QB.chat
197
- * @param {String} messageId - Delivered message id.
198
- * @param {String} dialogId - The dialog id.
199
- * @param {Number} userId - User id.
197
+ * @param {String} messageId - Delivered message id
198
+ * @param {String} dialogId - The dialog id
199
+ * @param {Number} userId - User id
200
200
  **/
201
201
 
202
202
  /**
203
- * You can manage 'read' notifications in chat({@link https://docs.quickblox.com/docs/js-chat-messaging#mark-message-as-read read more}).
203
+ * You can manage 'read' notifications in chat. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Read_status More info.}
204
204
  * @function onReadStatusListener
205
205
  * @memberOf QB.chat
206
- * @param {String} messageId - Read message id.
207
- * @param {String} dialogId - The dialog id.
208
- * @param {Number} userId - User Id.
206
+ * @param {String} messageId - Read message id
207
+ * @param {String} dialogId - The dialog id
208
+ * @param {Number} userId - User Id
209
209
  **/
210
210
 
211
211
  /**
212
- * These messages work over separated channel and won't be mixed with the regular chat messages({@link https://docs.quickblox.com/docs/js-chat-messaging#send-system-messages read more}).
212
+ * These messages work over separated channel and won't be mixed with the regular chat messages. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#System_notifications More info.}
213
213
  * @function onSystemMessageListener
214
214
  * @memberOf QB.chat
215
- * @param {Object} message - The system message model object. Always have type: 'headline'.
215
+ * @param {Object} message - The system message model object. Always have type: 'headline'
216
216
  **/
217
217
 
218
218
  /**
@@ -240,56 +240,56 @@ function ChatProxy(service) {
240
240
  **/
241
241
 
242
242
  /**
243
- * Receive user status (online / offline)({@link https://docs.quickblox.com/docs/js-chat-contact-list#contact-list-updates read more}).
243
+ * Receive user status (online / offline). {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Roster_callbacks More info.}
244
244
  * @function onContactListListener
245
245
  * @memberOf QB.chat
246
- * @param {Number} userId - The sender ID.
247
- * @param {String} type - If user leave the chat, type will be 'unavailable'.
246
+ * @param {Number} userId - The sender ID
247
+ * @param {String} type - If user leave the chat, type will be 'unavailable'
248
248
  **/
249
249
 
250
250
  /**
251
- * Receive subscription request({@link https://docs.quickblox.com/docs/js-chat-contact-list#add-user-to-your-contact-list read more}).
251
+ * Receive subscription request. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Roster_callbacks More info.}
252
252
  * @function onSubscribeListener
253
253
  * @memberOf QB.chat
254
- * @param {Number} userId - The sender ID.
254
+ * @param {Number} userId - The sender ID
255
255
  **/
256
256
 
257
257
  /**
258
- * Receive confirm request({@link https://docs.quickblox.com/docs/js-chat-contact-list#confirm-the-contact-request read more}).
258
+ * Receive confirm request. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Roster_callbacks More info.}
259
259
  * @function onConfirmSubscribeListener
260
260
  * @memberOf QB.chat
261
261
  * @param {Number} userId - The sender ID
262
262
  **/
263
263
 
264
264
  /**
265
- * Receive reject request({@link https://docs.quickblox.com/docs/js-chat-contact-list#reject-the-contact-request read more}).
265
+ * Receive reject request. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Roster_callbacks More info.}
266
266
  * @function onRejectSubscribeListener
267
267
  * @memberOf QB.chat
268
268
  * @param {Number} userId - The sender ID
269
269
  **/
270
270
 
271
271
  /**
272
- * Receive user's last activity (time ago).
272
+ * Receive user's last activity (time ago). {@link https://xmpp.org/extensions/xep-0012.html More info.}
273
273
  * @function onLastUserActivityListener
274
274
  * @memberOf QB.chat
275
- * @param {Number} userId - The user's ID which last activity time we receive.
276
- * @param {Number} seconds - Time ago (last activity in seconds or 0 if user online or undefined if user never registered in chat).
275
+ * @param {Number} userId - The user's ID which last activity time we receive
276
+ * @param {Number} seconds - Time ago (last activity in seconds or 0 if user online or undefined if user never registered in chat)
277
277
  */
278
278
 
279
279
  /**
280
- * Run after disconnect from chat({@linkhttps://docs.quickblox.com/docs/js-chat-connection#disconnect-from-chat-server read more}).
280
+ * Run after disconnect from chat. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Logout_from_Chat More info.}
281
281
  * @function onDisconnectedListener
282
282
  * @memberOf QB.chat
283
283
  **/
284
284
 
285
285
  /**
286
- * By default Javascript SDK reconnects automatically when connection to server is lost({@link https://docs.quickblox.com/docs/js-chat-connection#reconnection read more}).
286
+ * By default Javascript SDK reconnects automatically when connection to server is lost. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Reconnection More info.}
287
287
  * @function onReconnectListener
288
288
  * @memberOf QB.chat
289
289
  **/
290
290
 
291
291
 
292
- this._onMessage = function(stanza) {
292
+ this._onMessage = function (stanza) {
293
293
  var from = chatUtils.getAttr(stanza, 'from'),
294
294
  to = chatUtils.getAttr(stanza, 'to'),
295
295
  type = chatUtils.getAttr(stanza, 'type'),
@@ -329,16 +329,16 @@ function ChatProxy(service) {
329
329
  // ignore invite messages from MUC
330
330
  if (invite) return true;
331
331
 
332
- if(extraParams) {
332
+ if (extraParams) {
333
333
  extraParamsParsed = chatUtils.parseExtraParams(extraParams);
334
334
 
335
- if(extraParamsParsed.dialogId){
335
+ if (extraParamsParsed.dialogId) {
336
336
  dialogId = extraParamsParsed.dialogId;
337
337
  }
338
338
  }
339
339
 
340
- if(composing || paused){
341
- if (typeof self.onMessageTypingListener === 'function' && (type === 'chat' || type === 'groupchat' || !delay)){
340
+ if (composing || paused) {
341
+ if (typeof self.onMessageTypingListener === 'function' && (type === 'chat' || type === 'groupchat' || !delay)) {
342
342
  Utils.safeCallbackCall(self.onMessageTypingListener, !!composing, userId, dialogId);
343
343
  }
344
344
 
@@ -384,7 +384,7 @@ function ChatProxy(service) {
384
384
  message.markable = 1;
385
385
  }
386
386
 
387
- if (typeof self.onMessageListener === 'function' && (type === 'chat' || type === 'groupchat')){
387
+ if (typeof self.onMessageListener === 'function' && (type === 'chat' || type === 'groupchat')) {
388
388
  Utils.safeCallbackCall(self.onMessageListener, userId, message);
389
389
  }
390
390
 
@@ -393,7 +393,7 @@ function ChatProxy(service) {
393
393
  return true;
394
394
  };
395
395
 
396
- this._onPresence = function(stanza) {
396
+ this._onPresence = function (stanza) {
397
397
  var from = chatUtils.getAttr(stanza, 'from'),
398
398
  to = chatUtils.getAttr(stanza, 'to'),
399
399
  id = chatUtils.getAttr(stanza, 'id'),
@@ -402,22 +402,22 @@ function ChatProxy(service) {
402
402
  x = chatUtils.getElement(stanza, 'x'),
403
403
  xXMLNS, status, statusCode, dialogId, userId;
404
404
 
405
- if(x){
405
+ if (x) {
406
406
  xXMLNS = chatUtils.getAttr(x, 'xmlns');
407
407
  status = chatUtils.getElement(x, 'status');
408
- if(status){
408
+ if (status) {
409
409
  statusCode = chatUtils.getAttr(status, 'code');
410
410
  }
411
411
  }
412
412
 
413
413
  // MUC presences go here
414
- if(xXMLNS && xXMLNS == "http://jabber.org/protocol/muc#user"){
414
+ if (xXMLNS && xXMLNS == "http://jabber.org/protocol/muc#user") {
415
415
  dialogId = self.helpers.getDialogIdFromNode(from);
416
416
  userId = self.helpers.getUserIdFromRoomJid(from);
417
417
 
418
418
  // KICK from dialog event
419
- if(status && statusCode == "301"){
420
- if (typeof self.onKickOccupant === 'function'){
419
+ if (status && statusCode == "301") {
420
+ if (typeof self.onKickOccupant === 'function') {
421
421
  var actorElement = chatUtils.getElement(chatUtils.getElement(x, 'item'), 'actor');
422
422
  var initiatorUserJid = chatUtils.getAttr(actorElement, 'jid');
423
423
  Utils.safeCallbackCall(self.onKickOccupant,
@@ -430,17 +430,17 @@ function ChatProxy(service) {
430
430
  return true;
431
431
 
432
432
  // Occupants JOIN/LEAVE events
433
- }else if(!status){
434
- if(userId != currentUserId){
433
+ } else if (!status) {
434
+ if (userId != currentUserId) {
435
435
  // Leave
436
- if(type && type === 'unavailable'){
437
- if (typeof self.onLeaveOccupant === 'function'){
436
+ if (type && type === 'unavailable') {
437
+ if (typeof self.onLeaveOccupant === 'function') {
438
438
  Utils.safeCallbackCall(self.onLeaveOccupant, dialogId, parseInt(userId));
439
439
  }
440
440
  return true;
441
441
  // Join
442
- }else{
443
- if(typeof self.onJoinOccupant === 'function'){
442
+ } else {
443
+ if (typeof self.onJoinOccupant === 'function') {
444
444
  Utils.safeCallbackCall(self.onJoinOccupant, dialogId, parseInt(userId));
445
445
  }
446
446
  return true;
@@ -450,18 +450,18 @@ function ChatProxy(service) {
450
450
  }
451
451
  }
452
452
 
453
- if(!Utils.getEnv().browser) {
453
+ if (!Utils.getEnv().browser) {
454
454
  /** MUC */
455
- if(xXMLNS){
456
- if(xXMLNS == "http://jabber.org/protocol/muc#user"){
455
+ if (xXMLNS) {
456
+ if (xXMLNS == "http://jabber.org/protocol/muc#user") {
457
457
  /**
458
458
  * if you make 'leave' from dialog
459
459
  * stanza will be contains type="unavailable"
460
460
  */
461
- if(type && type === 'unavailable'){
461
+ if (type && type === 'unavailable') {
462
462
  /** LEAVE from dialog */
463
- if(status && statusCode == "110"){
464
- if(typeof self.nodeStanzasCallbacks['muc:leave'] === 'function') {
463
+ if (status && statusCode == "110") {
464
+ if (typeof self.nodeStanzasCallbacks['muc:leave'] === 'function') {
465
465
  Utils.safeCallbackCall(self.nodeStanzasCallbacks['muc:leave'], null);
466
466
  }
467
467
  }
@@ -470,8 +470,8 @@ function ChatProxy(service) {
470
470
  }
471
471
 
472
472
  /** JOIN to dialog success */
473
- if(id.endsWith(":join") && status && statusCode == "110"){
474
- if(typeof self.nodeStanzasCallbacks[id] === 'function') {
473
+ if (id.endsWith(":join") && status && statusCode == "110") {
474
+ if (typeof self.nodeStanzasCallbacks[id] === 'function') {
475
475
  self.nodeStanzasCallbacks[id](stanza);
476
476
  }
477
477
 
@@ -479,10 +479,10 @@ function ChatProxy(service) {
479
479
  }
480
480
 
481
481
  // an error
482
- } else if(type && type === 'error' && xXMLNS == "http://jabber.org/protocol/muc"){
482
+ } else if (type && type === 'error' && xXMLNS == "http://jabber.org/protocol/muc") {
483
483
  /** JOIN to dialog error */
484
- if(id.endsWith(":join")){
485
- if(typeof self.nodeStanzasCallbacks[id] === 'function') {
484
+ if (id.endsWith(":join")) {
485
+ if (typeof self.nodeStanzasCallbacks[id] === 'function') {
486
486
  self.nodeStanzasCallbacks[id](stanza);
487
487
  }
488
488
  }
@@ -498,7 +498,7 @@ function ChatProxy(service) {
498
498
  userId = self.helpers.getIdFromNode(from);
499
499
 
500
500
  if (!type) {
501
- if (typeof self.onContactListListener === 'function' && self.roster.contacts[userId] && self.roster.contacts[userId].subscription !== 'none'){
501
+ if (typeof self.onContactListListener === 'function' && self.roster.contacts[userId] && self.roster.contacts[userId].subscription !== 'none') {
502
502
  Utils.safeCallbackCall(self.onContactListListener, userId);
503
503
  }
504
504
  } else {
@@ -532,7 +532,7 @@ function ChatProxy(service) {
532
532
  ask: null
533
533
  };
534
534
 
535
- if (typeof self.onConfirmSubscribeListener === 'function'){
535
+ if (typeof self.onConfirmSubscribeListener === 'function') {
536
536
  Utils.safeCallbackCall(self.onConfirmSubscribeListener, userId);
537
537
  }
538
538
  }
@@ -562,10 +562,10 @@ function ChatProxy(service) {
562
562
 
563
563
  // send initial presence if one of client (instance) goes offline
564
564
  if (userId === currentUserId) {
565
- if(Utils.getEnv().browser){
565
+ if (Utils.getEnv().browser) {
566
566
  self.connection.send($pres());
567
567
  } else {
568
- self.Client.send(chatUtils.createStanza(XMPP.Stanza, null,'presence'));
568
+ self.Client.send(chatUtils.createStanza(XMPP.Stanza, null, 'presence'));
569
569
  }
570
570
  }
571
571
 
@@ -578,7 +578,7 @@ function ChatProxy(service) {
578
578
  return true;
579
579
  };
580
580
 
581
- this._onIQ = function(stanza) {
581
+ this._onIQ = function (stanza) {
582
582
  var stanzaId = chatUtils.getAttr(stanza, 'id');
583
583
  var isLastActivity = stanzaId.indexOf('lastActivity') > -1;
584
584
  var isPong = stanzaId.indexOf('ping') > -1;
@@ -607,7 +607,7 @@ function ChatProxy(service) {
607
607
  type: 'result'
608
608
  };
609
609
  var pongStanza = chatUtils.createStanza(builder, pongParams, 'iq');
610
- if(Utils.getEnv().browser) {
610
+ if (Utils.getEnv().browser) {
611
611
  self.connection.send(pongStanza);
612
612
  } else {
613
613
  self.Client.send(pongStanza);
@@ -637,7 +637,7 @@ function ChatProxy(service) {
637
637
  return true;
638
638
  };
639
639
 
640
- this._onSystemMessageListener = function(stanza) {
640
+ this._onSystemMessageListener = function (stanza) {
641
641
  var from = chatUtils.getAttr(stanza, 'from'),
642
642
  to = chatUtils.getAttr(stanza, 'to'),
643
643
  messageId = chatUtils.getAttr(stanza, 'id'),
@@ -658,7 +658,7 @@ function ChatProxy(service) {
658
658
  };
659
659
 
660
660
  Utils.safeCallbackCall(self.onSystemMessageListener, message);
661
- } else if(self.webrtcSignalingProcessor && !delay && moduleIdentifier === 'WebRTCVideoChat'){
661
+ } else if (self.webrtcSignalingProcessor && !delay && moduleIdentifier === 'WebRTCVideoChat') {
662
662
  self.webrtcSignalingProcessor._onMessage(from, extraParams, delay, userId, extraParamsParsed.extension);
663
663
  }
664
664
 
@@ -669,7 +669,7 @@ function ChatProxy(service) {
669
669
  return true;
670
670
  };
671
671
 
672
- this._onMessageErrorListener = function(stanza) {
672
+ this._onMessageErrorListener = function (stanza) {
673
673
  // <error code="503" type="cancel">
674
674
  // <service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
675
675
  // <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" xml:lang="en">Service not available.</text>
@@ -695,20 +695,20 @@ function ChatProxy(service) {
695
695
  ChatProxy.prototype = {
696
696
 
697
697
  /**
698
- * self.connection to the chat({@link https://docs.quickblox.com/docs/js-chat-connection#connect-to-chat-server read more})
698
+ * self.connection to the chat. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Login_to_Chat More info.}
699
699
  * @memberof QB.chat
700
- * @param {Object} params - Connect to the chat parameters.
701
- * @param {Number} params.userId - Connect to the chat by user id (use instead params.email and params.jid).
702
- * @param {String} params.jid - Connect to the chat by user jid (use instead params.userId and params.email).
703
- * @param {String} params.email - Connect to the chat by user's email (use instead params.userId and params.jid).
704
- * @param {String} params.password - The user's password or session token.
705
- * @param {chatConnectCallback} callback - The chatConnectCallback callback.
700
+ * @param {Object} params - Connect to the chat parameters
701
+ * @param {Number} params.userId - Connect to the chat by user id (use instead params.email and params.jid)
702
+ * @param {String} params.jid - Connect to the chat by user jid (use instead params.userId and params.email)
703
+ * @param {String} params.email - Connect to the chat by user's email (use instead params.userId and params.jid)
704
+ * @param {String} params.password - The user's password or session token
705
+ * @param {chatConnectCallback} callback - The chatConnectCallback callback
706
706
  * */
707
- connect: function(params, callback) {
707
+ connect: function (params, callback) {
708
708
  /**
709
709
  * This callback Returns error or contact list.
710
710
  * @callback chatConnectCallback
711
- * @param {Object} error - The error object.
711
+ * @param {Object} error - The error object
712
712
  * @param {(Object|Boolean)} response - Object of subscribed users (roster) or empty body.
713
713
  * */
714
714
  Utils.QBLog('[QBChat]', 'Connect with parameters ' + JSON.stringify(params));
@@ -745,8 +745,8 @@ ChatProxy.prototype = {
745
745
  if (Utils.getEnv().browser) {
746
746
  Utils.QBLog('[QBChat]', '!!---Browser env - connected--!!');
747
747
 
748
- self.connection.connect(userJid, params.password, function(status) {
749
- Utils.QBLog('[QBChat]', 'self.connection.connect called with status '+ status);
748
+ self.connection.connect(userJid, params.password, function (status) {
749
+ Utils.QBLog('[QBChat]', 'self.connection.connect called with status ' + status);
750
750
  switch (status) {
751
751
  case Strophe.Status.ERROR:
752
752
  self.isConnected = false;
@@ -762,13 +762,13 @@ ChatProxy.prototype = {
762
762
  case Strophe.Status.CONNFAIL:
763
763
  self.isConnected = false;
764
764
  self._isConnecting = false;
765
-
765
+
766
766
  err = Utils.getError(422, 'Status.CONNFAIL - The connection attempt failed', 'QBChat');
767
-
767
+
768
768
  if (isInitialConnect) {
769
769
  callback(err, null);
770
770
  }
771
-
771
+
772
772
  break;
773
773
  case Strophe.Status.AUTHENTICATING:
774
774
  Utils.QBLog('[QBChat]', 'Status.AUTHENTICATING');
@@ -777,28 +777,28 @@ ChatProxy.prototype = {
777
777
  case Strophe.Status.AUTHFAIL:
778
778
  self.isConnected = false;
779
779
  self._isConnecting = false;
780
-
780
+
781
781
  err = Utils.getError(401, 'Status.AUTHFAIL - The authentication attempt failed', 'QBChat');
782
-
782
+
783
783
  if (isInitialConnect) {
784
784
  callback(err, null);
785
785
  }
786
-
787
- if(!self.isConnected && typeof self.onReconnectFailedListener === 'function'){
786
+
787
+ if (!self.isConnected && typeof self.onReconnectFailedListener === 'function') {
788
788
  Utils.safeCallbackCall(self.onReconnectFailedListener, err);
789
789
  }
790
-
790
+
791
791
  break;
792
792
  case Strophe.Status.CONNECTING:
793
793
  Utils.QBLog('[QBChat]', 'Status.CONNECTING', '(Chat Protocol - ' + (config.chatProtocol.active === 1 ? 'BOSH' : 'WebSocket' + ')'));
794
-
794
+
795
795
  break;
796
796
  case Strophe.Status.CONNECTED:
797
797
  // Remove any handlers that might exist from a previous connection via
798
798
  // extension method added to the connection on initialization in qbMain.
799
799
  // NOTE: streamManagement also adds handlers, so do this first.
800
800
  self.connection.XDeleteHandlers();
801
-
801
+
802
802
  self.connection.XAddTrackedHandler(self._onMessage, null, 'message', 'chat');
803
803
  self.connection.XAddTrackedHandler(self._onMessage, null, 'message', 'groupchat');
804
804
  self.connection.XAddTrackedHandler(self._onPresence, null, 'presence');
@@ -810,18 +810,18 @@ ChatProxy.prototype = {
810
810
  noTimerId = config.pingLocalhostTimeInterval === 0 ? false : noTimerId;
811
811
 
812
812
  if (noTimerId) {
813
- Utils.QBLog('[QBChat]', 'Init ping to localhost at ', Utils.getCurrentTime());
814
- self._checkConnectionPingTimer = setInterval(function() {
813
+ Utils.QBLog('[QBChat]', 'Init ping to chat at ', Utils.getCurrentTime());
814
+ self._checkConnectionPingTimer = setInterval(function () {
815
815
  try {
816
- self.pinglocalhost(function (error) {
816
+ self.pingchat(function (error) {
817
817
  if (error) {
818
818
  Utils.QBLog('[QBChat]',
819
- 'Local Ping: ',
819
+ 'Chat Ping: ',
820
820
  'failed, at ', Utils.getCurrentTime(),
821
- '_localPingFaildCounter: ', self._localPingFaildCounter,
821
+ '_chatPingFailedCounter: ', self._chatPingFailedCounter,
822
822
  ' error: ', error);
823
823
  self._localPingFaildCounter += 1;
824
- if (self._localPingFaildCounter > 6) {
824
+ if (self._chatPingFailedCounter > 6) {
825
825
  self.isConnected = false;
826
826
  self._isConnecting = false;
827
827
  self._localPingFaildCounter = 0;
@@ -829,16 +829,15 @@ ChatProxy.prototype = {
829
829
  }
830
830
  } else {
831
831
  Utils.QBLog('[QBChat]',
832
- 'Local Ping: ',
832
+ 'Chat Ping: ',
833
833
  'ok, at ', Utils.getCurrentTime(),
834
- '_localPingFaildCounter: ', self._localPingFaildCounter);
834
+ '_chatPingFailedCounter: ', self._chatPingFailedCounter);
835
835
  self._localPingFaildCounter = 0;
836
836
  }
837
837
  });
838
- }
839
- catch (err) {
838
+ } catch (err) {
840
839
  Utils.QBLog('[QBChat]',
841
- 'Local Ping: ',
840
+ 'Chat Ping: ',
842
841
  'Exception, at ', Utils.getCurrentTime(),
843
842
  ', detail info: ', err);
844
843
  }
@@ -849,7 +848,7 @@ ChatProxy.prototype = {
849
848
  var noExpiredSessionTimerId = typeof self._checkExpiredSessionTimer === 'undefined';
850
849
  if (noExpiredSessionTimerId) {
851
850
  Utils.QBLog('[QBChat]', 'Init timer for check session expired at ', ((new Date()).toTimeString().split(' ')[0]));
852
- self._checkExpiredSessionTimer = setInterval(function() {
851
+ self._checkExpiredSessionTimer = setInterval(function () {
853
852
  var timeNow = new Date();
854
853
  if (typeof config.qbTokenExpirationDate !== 'undefined') {
855
854
  var timeLag = Math.round((timeNow.getTime() - config.qbTokenExpirationDate.getTime()) / (1000 * 60));
@@ -864,7 +863,7 @@ ChatProxy.prototype = {
864
863
  }
865
864
  }
866
865
 
867
- self._postConnectActions(function(roster) {
866
+ self._postConnectActions(function (roster) {
868
867
  callback(null, roster);
869
868
  }, isInitialConnect);
870
869
 
@@ -876,7 +875,7 @@ ChatProxy.prototype = {
876
875
  Utils.QBLog('[QBChat]', 'Status.DISCONNECTED at ' + chatUtils.getLocalTime());
877
876
 
878
877
  // fire 'onDisconnectedListener' only once
879
- if (self.isConnected && typeof self.onDisconnectedListener === 'function'){
878
+ if (self.isConnected && typeof self.onDisconnectedListener === 'function') {
880
879
  Utils.safeCallbackCall(self.onDisconnectedListener);
881
880
  }
882
881
 
@@ -896,26 +895,26 @@ ChatProxy.prototype = {
896
895
  }
897
896
 
898
897
  /** connect for node */
899
- if(!Utils.getEnv().browser) {
898
+ if (!Utils.getEnv().browser) {
900
899
  Utils.QBLog('[QBChat]', '!!--call branch code connect for node--!!');
901
900
  // Remove all connection handlers exist from a previous connection
902
901
  self.Client.removeAllListeners();
903
902
 
904
- self.Client.on('connect', function() {
903
+ self.Client.on('connect', function () {
905
904
  Utils.QBLog('[QBChat]', 'Status.CONNECTING', '(Chat Protocol - ' + (config.chatProtocol.active === 1 ? 'BOSH' : 'WebSocket' + ')'));
906
905
  });
907
906
 
908
- self.Client.on('auth', function() {
907
+ self.Client.on('auth', function () {
909
908
  Utils.QBLog('[QBChat]', 'Status.AUTHENTICATING');
910
909
  });
911
-
912
- self.Client.on('online', function() {
913
- self._postConnectActions(function(roster) {
910
+
911
+ self.Client.on('online', function () {
912
+ self._postConnectActions(function (roster) {
914
913
  callback(null, roster);
915
914
  }, isInitialConnect);
916
915
  });
917
-
918
- self.Client.on('stanza', function(stanza) {
916
+
917
+ self.Client.on('stanza', function (stanza) {
919
918
  Utils.QBLog('[QBChat] RECV:', stanza.toString());
920
919
  /**
921
920
  * Detect typeof incoming stanza
@@ -925,35 +924,35 @@ ChatProxy.prototype = {
925
924
  self._onPresence(stanza);
926
925
  } else if (stanza.is('iq')) {
927
926
  self._onIQ(stanza);
928
- } else if(stanza.is('message')) {
927
+ } else if (stanza.is('message')) {
929
928
  if (stanza.attrs.type === 'headline') {
930
929
  self._onSystemMessageListener(stanza);
931
- } else if(stanza.attrs.type === 'error') {
930
+ } else if (stanza.attrs.type === 'error') {
932
931
  self._onMessageErrorListener(stanza);
933
932
  } else {
934
933
  self._onMessage(stanza);
935
934
  }
936
935
  }
937
936
  });
938
-
939
- self.Client.on('disconnect', function() {
937
+
938
+ self.Client.on('disconnect', function () {
940
939
  Utils.QBLog('[QBChat]', 'Status.DISCONNECTED - ' + chatUtils.getLocalTime());
941
940
 
942
941
  if (typeof self.onDisconnectedListener === 'function') {
943
942
  Utils.safeCallbackCall(self.onDisconnectedListener);
944
943
  }
945
-
944
+
946
945
  self.isConnected = false;
947
946
  self._isConnecting = false;
948
947
 
949
948
  // reconnect to chat and enable check connection
950
949
  self._establishConnection(params);
951
950
  });
952
-
953
- self.Client.on('error', function() {
951
+
952
+ self.Client.on('error', function () {
954
953
  Utils.QBLog('[QBChat]', 'Status.ERROR - ' + chatUtils.getLocalTime());
955
954
  err = Utils.getError(422, 'Status.ERROR - An error has occurred', 'QBChat');
956
-
955
+
957
956
  if (isInitialConnect) {
958
957
  callback(err, null);
959
958
  }
@@ -962,8 +961,8 @@ ChatProxy.prototype = {
962
961
  self._isConnecting = false;
963
962
  });
964
963
 
965
- self.Client.on('end', function() {
966
- self.Client.removeAllListeners();
964
+ self.Client.on('end', function () {
965
+ self.Client.removeAllListeners();
967
966
  });
968
967
 
969
968
  self.Client.options.jid = userJid;
@@ -974,7 +973,7 @@ ChatProxy.prototype = {
974
973
 
975
974
  /**
976
975
  * Actions after the connection is established
977
- *
976
+ *
978
977
  * - enable stream management (the configuration setting);
979
978
  * - save user's JID;
980
979
  * - enable carbons;
@@ -982,7 +981,7 @@ ChatProxy.prototype = {
982
981
  * - recover the joined rooms and fire 'onReconnectListener' (if the reconnect);
983
982
  * - send initial presence to the chat server.
984
983
  */
985
- _postConnectActions: function(callback, isInitialConnect) {
984
+ _postConnectActions: function (callback, isInitialConnect) {
986
985
  Utils.QBLog('[QBChat]', 'Status.CONNECTED at ' + chatUtils.getLocalTime());
987
986
 
988
987
  var self = this;
@@ -1006,7 +1005,7 @@ ChatProxy.prototype = {
1006
1005
  self._enableCarbons();
1007
1006
 
1008
1007
  if (isInitialConnect) {
1009
- self.roster.get(function(contacts) {
1008
+ self.roster.get(function (contacts) {
1010
1009
  xmppClient.send(presence);
1011
1010
 
1012
1011
  self.roster.contacts = contacts;
@@ -1014,7 +1013,7 @@ ChatProxy.prototype = {
1014
1013
  });
1015
1014
  } else {
1016
1015
  var rooms = Object.keys(self.muc.joinedRooms);
1017
-
1016
+
1018
1017
  xmppClient.send(presence);
1019
1018
 
1020
1019
  Utils.QBLog('[QBChat]', 'Re-joining ' + rooms.length + " rooms...");
@@ -1029,7 +1028,7 @@ ChatProxy.prototype = {
1029
1028
  }
1030
1029
  },
1031
1030
 
1032
- _establishConnection: function(params) {
1031
+ _establishConnection: function (params) {
1033
1032
  var self = this;
1034
1033
  Utils.QBLog('[QBChat]', '_establishConnection called');
1035
1034
  if (self._isLogout || self._checkConnectionTimer) {
@@ -1037,7 +1036,7 @@ ChatProxy.prototype = {
1037
1036
  return;
1038
1037
  }
1039
1038
 
1040
- var _connect = function() {
1039
+ var _connect = function () {
1041
1040
  Utils.QBLog('[QBChat]', 'call _connect() in _establishConnection ');
1042
1041
  if (!self.isConnected && !self._isConnecting && !self._sessionHasExpired) {
1043
1042
  Utils.QBLog('[QBChat]', 'call connect() again in _establishConnection ');
@@ -1051,8 +1050,8 @@ ChatProxy.prototype = {
1051
1050
 
1052
1051
  _connect();
1053
1052
 
1054
- self._checkConnectionTimer = setInterval(function() {
1055
- Utils.QBLog('[QBChat]', 'self._checkConnectionTimer called with config.chatReconnectionTimeInterval = '+config.chatReconnectionTimeInterval);
1053
+ self._checkConnectionTimer = setInterval(function () {
1054
+ Utils.QBLog('[QBChat]', 'self._checkConnectionTimer called with config.chatReconnectionTimeInterval = ' + config.chatReconnectionTimeInterval);
1056
1055
  _connect();
1057
1056
  }, config.chatReconnectionTimeInterval * 1000);
1058
1057
  },
@@ -1073,13 +1072,13 @@ ChatProxy.prototype = {
1073
1072
  },
1074
1073
 
1075
1074
  /**
1076
- * Send message to 1 to 1 or group dialog({@link https://docs.quickblox.com/docs/js-chat-messaging#send-text-message read more}).
1075
+ * Send message to 1 to 1 or group dialog. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Chat_in_dialog More info.}
1077
1076
  * @memberof QB.chat
1078
- * @param {String | Number} jid_or_user_id - Use opponent id for 1 to 1 chat, and room jid for group chat.
1077
+ * @param {String | Number} jid_or_user_id - Use opponent id or jid for 1 to 1 chat, and room jid for group chat.
1079
1078
  * @param {Object} message - The message object.
1080
- * @returns {String} messageId - The current message id (was generated by SDK).
1079
+ * @returns {String} messageId - The current message id (was generated by SDK)
1081
1080
  * */
1082
- send: function(jid_or_user_id, message) {
1081
+ send: function (jid_or_user_id, message) {
1083
1082
  Utils.QBLog('[QBChat]', 'Call send ' + JSON.stringify(message));
1084
1083
  var self = this,
1085
1084
  builder = Utils.getEnv().browser ? $msg : XMPP.Stanza;
@@ -1113,8 +1112,8 @@ ChatProxy.prototype = {
1113
1112
  stanza = chatUtils.filledExtraParams(stanza, message.extension);
1114
1113
  }
1115
1114
 
1116
- if(Utils.getEnv().browser) {
1117
- if(config.streamManagement.enable){
1115
+ if (Utils.getEnv().browser) {
1116
+ if (config.streamManagement.enable) {
1118
1117
  message.id = paramsCreateMsg.id;
1119
1118
  message.jid_or_user_id = jid_or_user_id;
1120
1119
  self.connection.send(stanza, message);
@@ -1122,7 +1121,7 @@ ChatProxy.prototype = {
1122
1121
  self.connection.send(stanza);
1123
1122
  }
1124
1123
  } else {
1125
- if(config.streamManagement.enable){
1124
+ if (config.streamManagement.enable) {
1126
1125
  message.id = paramsCreateMsg.id;
1127
1126
  message.jid_or_user_id = jid_or_user_id;
1128
1127
  self.Client.send(stanza, message);
@@ -1136,13 +1135,13 @@ ChatProxy.prototype = {
1136
1135
  },
1137
1136
 
1138
1137
  /**
1139
- * Send system message (system notification) to 1 to 1 or group dialog({@link https://docs.quickblox.com/docs/js-chat-messaging#send-system-messages read more}).
1138
+ * Send system message (system notification) to 1 to 1 or group dialog. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#System_notifications More info.}
1140
1139
  * @memberof QB.chat
1141
- * @param {String | Number} jid_or_user_id - Use opponent id for 1 to 1 chat, and room jid for group chat.
1140
+ * @param {String | Number} jid_or_user_id - Use opponent id or jid for 1 to 1 chat, and room jid for group chat.
1142
1141
  * @param {Object} message - The message object.
1143
- * @returns {String} messageId - The current message id (was generated by SDK).
1142
+ * @returns {String} messageId - The current message id (was generated by SDK)
1144
1143
  * */
1145
- sendSystemMessage: function(jid_or_user_id, message) {
1144
+ sendSystemMessage: function (jid_or_user_id, message) {
1146
1145
  Utils.QBLog('[QBChat]', 'Call sendSystemMessage ' + JSON.stringify(message));
1147
1146
  var self = this,
1148
1147
  builder = Utils.getEnv().browser ? $msg : XMPP.Stanza,
@@ -1160,7 +1159,7 @@ ChatProxy.prototype = {
1160
1159
  }).t(message.body).up();
1161
1160
  }
1162
1161
 
1163
- if(Utils.getEnv().browser) {
1162
+ if (Utils.getEnv().browser) {
1164
1163
  // custom parameters
1165
1164
  if (message.extension) {
1166
1165
  stanza.c('extraParams', {
@@ -1173,7 +1172,7 @@ ChatProxy.prototype = {
1173
1172
  self.connection.send(stanza);
1174
1173
  } else {
1175
1174
  if (message.extension) {
1176
- stanza.c('extraParams', {
1175
+ stanza.c('extraParams', {
1177
1176
  xmlns: chatUtils.MARKERS.CLIENT
1178
1177
  }).c('moduleIdentifier').t('SystemNotifications');
1179
1178
 
@@ -1187,11 +1186,11 @@ ChatProxy.prototype = {
1187
1186
  },
1188
1187
 
1189
1188
  /**
1190
- * Send is typing status({@link https://docs.quickblox.com/docs/js-chat-messaging#send-typing-indicators read more}).
1189
+ * Send is typing status. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Typing_status More info.}
1191
1190
  * @memberof QB.chat
1192
- * @param {String | Number} jid_or_user_id - Use opponent id for 1 to 1 chat, and room jid for group chat.
1191
+ * @param {String | Number} jid_or_user_id - Use opponent id or jid for 1 to 1 chat, and room jid for group chat.
1193
1192
  * */
1194
- sendIsTypingStatus: function(jid_or_user_id) {
1193
+ sendIsTypingStatus: function (jid_or_user_id) {
1195
1194
  Utils.QBLog('[QBChat]', 'Call sendIsTypingStatus ');
1196
1195
  var self = this,
1197
1196
  stanzaParams = {
@@ -1207,7 +1206,7 @@ ChatProxy.prototype = {
1207
1206
  xmlns: chatUtils.MARKERS.STATES
1208
1207
  });
1209
1208
 
1210
- if(Utils.getEnv().browser){
1209
+ if (Utils.getEnv().browser) {
1211
1210
  self.connection.send(stanza);
1212
1211
  } else {
1213
1212
  self.Client.send(stanza);
@@ -1215,11 +1214,11 @@ ChatProxy.prototype = {
1215
1214
  },
1216
1215
 
1217
1216
  /**
1218
- * Send is stop typing status({@link https://docs.quickblox.com/docs/js-chat-messaging#send-typing-indicators read more}).
1217
+ * Send is stop typing status. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Typing_status More info.}
1219
1218
  * @memberof QB.chat
1220
- * @param {String | Number} jid_or_user_id - Use opponent id for 1 to 1 chat, and room jid for group chat.
1219
+ * @param {String | Number} jid_or_user_id - Use opponent id or jid for 1 to 1 chat, and room jid for group chat.
1221
1220
  * */
1222
- sendIsStopTypingStatus: function(jid_or_user_id) {
1221
+ sendIsStopTypingStatus: function (jid_or_user_id) {
1223
1222
  Utils.QBLog('[QBChat]', 'Call sendIsStopTypingStatus ');
1224
1223
  var self = this,
1225
1224
  stanzaParams = {
@@ -1235,7 +1234,7 @@ ChatProxy.prototype = {
1235
1234
  xmlns: chatUtils.MARKERS.STATES
1236
1235
  });
1237
1236
 
1238
- if(Utils.getEnv().browser){
1237
+ if (Utils.getEnv().browser) {
1239
1238
  self.connection.send(stanza);
1240
1239
  } else {
1241
1240
  self.Client.send(stanza);
@@ -1243,14 +1242,14 @@ ChatProxy.prototype = {
1243
1242
  },
1244
1243
 
1245
1244
  /**
1246
- * Send is delivered status({@link https://docs.quickblox.com/docs/js-chat-messaging#mark-message-as-delivered read more}).
1245
+ * Send is delivered status. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Delivered_status More info.}
1247
1246
  * @memberof QB.chats
1248
- * @param {Object} params - Object of parameters.
1249
- * @param {Number} params.userId - The receiver id.
1250
- * @param {Number} params.messageId - The delivered message id.
1251
- * @param {Number} params.dialogId - The dialog id.
1247
+ * @param {Object} params - Object of parameters
1248
+ * @param {Number} params.userId - The receiver id
1249
+ * @param {Number} params.messageId - The delivered message id
1250
+ * @param {Number} params.dialogId - The dialog id
1252
1251
  * */
1253
- sendDeliveredStatus: function(params) {
1252
+ sendDeliveredStatus: function (params) {
1254
1253
  Utils.QBLog('[QBChat]', 'Call sendDeliveredStatus ');
1255
1254
  var self = this,
1256
1255
  stanzaParams = {
@@ -1272,7 +1271,7 @@ ChatProxy.prototype = {
1272
1271
  xmlns: chatUtils.MARKERS.CLIENT
1273
1272
  }).c('dialog_id').t(params.dialogId);
1274
1273
 
1275
- if(Utils.getEnv().browser) {
1274
+ if (Utils.getEnv().browser) {
1276
1275
  self.connection.send(stanza);
1277
1276
  } else {
1278
1277
  self.Client.send(stanza);
@@ -1280,14 +1279,14 @@ ChatProxy.prototype = {
1280
1279
  },
1281
1280
 
1282
1281
  /**
1283
- * Send is read status({@link https://docs.quickblox.com/docs/js-chat-messaging#mark-message-as-read read more}).
1282
+ * Send is read status. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Read_status More info.}
1284
1283
  * @memberof QB.chat
1285
- * @param {Object} params - Object of parameters.
1286
- * @param {Number} params.userId - The receiver id.
1287
- * @param {Number} params.messageId - The delivered message id.
1288
- * @param {Number} params.dialogId - The dialog id.
1284
+ * @param {Object} params - Object of parameters
1285
+ * @param {Number} params.userId - The receiver id
1286
+ * @param {Number} params.messageId - The delivered message id
1287
+ * @param {Number} params.dialogId - The dialog id
1289
1288
  * */
1290
- sendReadStatus: function(params) {
1289
+ sendReadStatus: function (params) {
1291
1290
  Utils.QBLog('[QBChat]', 'Call sendReadStatus ' + JSON.stringify(params));
1292
1291
  var self = this,
1293
1292
  stanzaParams = {
@@ -1309,7 +1308,7 @@ ChatProxy.prototype = {
1309
1308
  xmlns: chatUtils.MARKERS.CLIENT
1310
1309
  }).c('dialog_id').t(params.dialogId);
1311
1310
 
1312
- if(Utils.getEnv().browser) {
1311
+ if (Utils.getEnv().browser) {
1313
1312
  self.connection.send(stanza);
1314
1313
  } else {
1315
1314
  self.Client.send(stanza);
@@ -1317,11 +1316,11 @@ ChatProxy.prototype = {
1317
1316
  },
1318
1317
 
1319
1318
  /**
1320
- * Send query to get last user activity by QB.chat.onLastUserActivityListener(userId, seconds)({@link https://xmpp.org/extensions/xep-0012.html read more}).
1319
+ * Send query to get last user activity by QB.chat.onLastUserActivityListener(userId, seconds). {@link https://xmpp.org/extensions/xep-0012.html More info.}
1321
1320
  * @memberof QB.chat
1322
- * @param {(Number|String)} jid_or_user_id - The user id or jid, that the last activity we want to know.
1321
+ * @param {(Number|String)} jid_or_user_id - The user id or jid, that the last activity we want to know
1323
1322
  * */
1324
- getLastUserActivity: function(jid_or_user_id) {
1323
+ getLastUserActivity: function (jid_or_user_id) {
1325
1324
  Utils.QBLog('[QBChat]', 'Call getLastUserActivity ');
1326
1325
  var iqParams,
1327
1326
  builder,
@@ -1349,8 +1348,8 @@ ChatProxy.prototype = {
1349
1348
  }
1350
1349
  },
1351
1350
 
1352
- pinglocalhost: function(callback){
1353
- Utils.QBLog('[QBChat]', 'ping localhost');
1351
+ pingchat: function (callback) {
1352
+ Utils.QBLog('[QBChat]', 'ping chat');
1354
1353
  var self = this;
1355
1354
  var id = this.helpers.getUniqueId('ping');
1356
1355
  var builder = Utils.getEnv().browser ? $iq : XMPP.Stanza;
@@ -1359,7 +1358,8 @@ ChatProxy.prototype = {
1359
1358
  var stanza;
1360
1359
 
1361
1360
  //to = config.endpoints.chat;
1362
- to = 'http://localhost';
1361
+ //to = 'http://localhost';
1362
+ to = config.endpoints.chat? config.endpoints.chat : 'chat.quickblox.com';
1363
1363
  _callback = callback;
1364
1364
 
1365
1365
  var iqParams = {
@@ -1369,10 +1369,10 @@ ChatProxy.prototype = {
1369
1369
  type: 'get'
1370
1370
  };
1371
1371
  stanza = chatUtils.createStanza(builder, iqParams, 'iq');
1372
- stanza.c('ping', { xmlns: "urn:xmpp:ping" });
1372
+ stanza.c('ping', {xmlns: "urn:xmpp:ping"});
1373
1373
 
1374
1374
  var noAnswer = function () {
1375
- _callback('Local ping No answer');
1375
+ _callback('Chat ping No answer');
1376
1376
  self._pings[id] = undefined;
1377
1377
  delete self._pings[id];
1378
1378
  };
@@ -1397,7 +1397,7 @@ ChatProxy.prototype = {
1397
1397
  var _callback;
1398
1398
  var stanza;
1399
1399
  if ((typeof jid_or_user_id === 'string' ||
1400
- typeof jid_or_user_id === 'number') &&
1400
+ typeof jid_or_user_id === 'number') &&
1401
1401
  typeof callback === 'function') {
1402
1402
  to = this.helpers.jidOrUserId(jid_or_user_id);
1403
1403
  _callback = callback;
@@ -1417,7 +1417,7 @@ ChatProxy.prototype = {
1417
1417
  type: 'get'
1418
1418
  };
1419
1419
  stanza = chatUtils.createStanza(builder, iqParams, 'iq');
1420
- stanza.c('ping', { xmlns: "urn:xmpp:ping" });
1420
+ stanza.c('ping', {xmlns: "urn:xmpp:ping"});
1421
1421
 
1422
1422
  var noAnswer = function () {
1423
1423
  _callback('No answer');
@@ -1437,10 +1437,10 @@ ChatProxy.prototype = {
1437
1437
  },
1438
1438
 
1439
1439
  /**
1440
- * Disconnect from the Chat({@link https://docs.quickblox.com/docs/js-chat-connection#disconnect-from-chat-server read more}).
1440
+ * Logout from the Chat. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Logout_from_Chat More info.}
1441
1441
  * @memberof QB.chat
1442
1442
  * */
1443
- disconnect: function() {
1443
+ disconnect: function () {
1444
1444
  Utils.QBLog('[QBChat]', 'Call disconnect ');
1445
1445
  clearInterval(this._checkConnectionTimer);
1446
1446
  clearInterval(this._checkExpiredSessionTimer);
@@ -1463,10 +1463,10 @@ ChatProxy.prototype = {
1463
1463
  }
1464
1464
  },
1465
1465
 
1466
- addListener: function(params, callback) {
1466
+ addListener: function (params, callback) {
1467
1467
  Utils.QBLog('[Deprecated!]', 'Avoid using it, this feature will be removed in future version.');
1468
1468
 
1469
- if(!Utils.getEnv().browser) {
1469
+ if (!Utils.getEnv().browser) {
1470
1470
  throw new Error(unsupportedError);
1471
1471
  }
1472
1472
 
@@ -1479,10 +1479,10 @@ ChatProxy.prototype = {
1479
1479
  }
1480
1480
  },
1481
1481
 
1482
- deleteListener: function(ref) {
1482
+ deleteListener: function (ref) {
1483
1483
  Utils.QBLog('[Deprecated!]', 'Avoid using it, this feature will be removed in future version.');
1484
1484
 
1485
- if(!Utils.getEnv().browser) {
1485
+ if (!Utils.getEnv().browser) {
1486
1486
  throw new Error(unsupportedError);
1487
1487
  }
1488
1488
 
@@ -1492,7 +1492,7 @@ ChatProxy.prototype = {
1492
1492
  /**
1493
1493
  * Carbons XEP [http://xmpp.org/extensions/xep-0280.html]
1494
1494
  */
1495
- _enableCarbons: function(cb) {
1495
+ _enableCarbons: function (cb) {
1496
1496
  var self = this,
1497
1497
  carbonParams = {
1498
1498
  type: 'set',
@@ -1538,11 +1538,11 @@ function RosterProxy(options) {
1538
1538
  RosterProxy.prototype = {
1539
1539
 
1540
1540
  /**
1541
- * Receive contact list({@link https://docs.quickblox.com/docs/js-chat-contact-list#access-contact-list read more}).
1541
+ * Receive contact list. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Contact_List More info.}
1542
1542
  * @memberof QB.chat.roster
1543
1543
  * @param {getRosterCallback} callback - The callback function.
1544
1544
  * */
1545
- get: function(callback) {
1545
+ get: function (callback) {
1546
1546
  /**
1547
1547
  * This callback Return contact list.
1548
1548
  * @callback getRosterCallback
@@ -1561,7 +1561,7 @@ RosterProxy.prototype = {
1561
1561
  var iq = chatUtils.createStanza(builder, iqParams, 'iq');
1562
1562
 
1563
1563
  function _getItems(stanza) {
1564
- if(Utils.getEnv().browser) {
1564
+ if (Utils.getEnv().browser) {
1565
1565
  return stanza.getElementsByTagName('item');
1566
1566
  } else {
1567
1567
  return stanza.getChild('query').children;
@@ -1571,7 +1571,7 @@ RosterProxy.prototype = {
1571
1571
  function _callbackWrap(stanza) {
1572
1572
  var items = _getItems(stanza);
1573
1573
  for (var i = 0, len = items.length; i < len; i++) {
1574
- var userId = self.helpers.getIdFromNode( chatUtils.getAttr(items[i], 'jid') ),
1574
+ var userId = self.helpers.getIdFromNode(chatUtils.getAttr(items[i], 'jid')),
1575
1575
  ask = chatUtils.getAttr(items[i], 'ask'),
1576
1576
  subscription = chatUtils.getAttr(items[i], 'subscription');
1577
1577
 
@@ -1588,7 +1588,7 @@ RosterProxy.prototype = {
1588
1588
  xmlns: chatUtils.MARKERS.ROSTER
1589
1589
  });
1590
1590
 
1591
- if(Utils.getEnv().browser) {
1591
+ if (Utils.getEnv().browser) {
1592
1592
  self.connection.sendIQ(iq, _callbackWrap);
1593
1593
  } else {
1594
1594
  self.nodeStanzasCallbacks[iqParams.id] = _callbackWrap;
@@ -1597,12 +1597,12 @@ RosterProxy.prototype = {
1597
1597
  },
1598
1598
 
1599
1599
  /**
1600
- * Add users to contact list({@link https://docs.quickblox.com/docs/js-chat-contact-list#add-user-to-your-contact-list read more}).
1600
+ * Add users to contact list. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Add_users More info.}
1601
1601
  * @memberof QB.chat.roster
1602
1602
  * @param {String | Number} jidOrUserId - Use opponent id for 1 to 1 chat, and jid for group chat.
1603
1603
  * @param {addRosterCallback} callback - The callback function.
1604
1604
  * */
1605
- add: function(jidOrUserId, callback) {
1605
+ add: function (jidOrUserId, callback) {
1606
1606
 
1607
1607
  /**
1608
1608
  * Callback for QB.chat.roster.add(). Run without parameters.
@@ -1628,12 +1628,12 @@ RosterProxy.prototype = {
1628
1628
  },
1629
1629
 
1630
1630
  /**
1631
- * Confirm subscription with some user({@link https://docs.quickblox.com/docs/js-chat-contact-list#confirm-the-contact-request read more}).
1631
+ * Confirm subscription with some user. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Confirm_subscription_request More info.}
1632
1632
  * @memberof QB.chat.roster
1633
1633
  * @param {String | Number} jidOrUserId - Use opponent id for 1 to 1 chat, and jid for group chat.
1634
1634
  * @param {confirmRosterCallback} callback - The callback function.
1635
1635
  * */
1636
- confirm: function(jidOrUserId, callback) {
1636
+ confirm: function (jidOrUserId, callback) {
1637
1637
 
1638
1638
  /**
1639
1639
  * Callback for QB.chat.roster.confirm(). Run without parameters.
@@ -1665,12 +1665,12 @@ RosterProxy.prototype = {
1665
1665
  },
1666
1666
 
1667
1667
  /**
1668
- * Reject subscription with some user({@link https://docs.quickblox.com/docs/js-chat-contact-list#reject-the-contact-request read more}).
1668
+ * Reject subscription with some user. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Reject_subscription_request More info.}
1669
1669
  * @memberof QB.chat.roster
1670
1670
  * @param {String | Number} jidOrUserId - Use opponent id for 1 to 1 chat, and jid for group chat.
1671
1671
  * @param {rejectRosterCallback} callback - The callback function.
1672
1672
  * */
1673
- reject: function(jidOrUserId, callback) {
1673
+ reject: function (jidOrUserId, callback) {
1674
1674
 
1675
1675
  /**
1676
1676
  * Callback for QB.chat.roster.reject(). Run without parameters.
@@ -1697,12 +1697,12 @@ RosterProxy.prototype = {
1697
1697
 
1698
1698
 
1699
1699
  /**
1700
- * Remove subscription with some user from your contact list({@link https://docs.quickblox.com/docs/js-chat-contact-list#remove-user-from-the-contact-list read more}).
1700
+ * Remove subscription with some user from your contact list. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Remove_users More info.}
1701
1701
  * @memberof QB.chat.roster
1702
1702
  * @param {String | Number} jidOrUserId - Use opponent id for 1 to 1 chat, and jid for group chat.
1703
1703
  * @param {removeRosterCallback} callback - The callback function.
1704
1704
  * */
1705
- remove: function(jidOrUserId, callback) {
1705
+ remove: function (jidOrUserId, callback) {
1706
1706
 
1707
1707
  /**
1708
1708
  * Callback for QB.chat.roster.remove(). Run without parameters.
@@ -1736,7 +1736,7 @@ RosterProxy.prototype = {
1736
1736
  subscription: 'remove'
1737
1737
  });
1738
1738
 
1739
- if(Utils.getEnv().browser) {
1739
+ if (Utils.getEnv().browser) {
1740
1740
  self.connection.sendIQ(iq, _callbackWrap);
1741
1741
  } else {
1742
1742
  self.nodeStanzasCallbacks[iqParams.id] = _callbackWrap;
@@ -1744,7 +1744,7 @@ RosterProxy.prototype = {
1744
1744
  }
1745
1745
  },
1746
1746
 
1747
- _sendSubscriptionPresence: function(params) {
1747
+ _sendSubscriptionPresence: function (params) {
1748
1748
  var builder = Utils.getEnv().browser ? $pres : XMPP.Stanza,
1749
1749
  presParams = {
1750
1750
  to: params.jid,
@@ -1753,7 +1753,7 @@ RosterProxy.prototype = {
1753
1753
 
1754
1754
  var pres = chatUtils.createStanza(builder, presParams, 'presence');
1755
1755
 
1756
- if (Utils.getEnv().browser){
1756
+ if (Utils.getEnv().browser) {
1757
1757
  this.connection.send(pres);
1758
1758
  } else {
1759
1759
  this.Client.send(pres);
@@ -1784,16 +1784,16 @@ function MucProxy(options) {
1784
1784
  MucProxy.prototype = {
1785
1785
 
1786
1786
  /**
1787
- * Join to the group dialog({@link https://docs.quickblox.com/docs/js-chat-dialogs#join-dialog read more}).
1787
+ * Join to the group dialog. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Chat_in_group_dialog More info.}
1788
1788
  * @memberof QB.chat.muc
1789
1789
  * @param {String} dialogIdOrJid - Use dialog jid or dialog id to join to this dialog.
1790
1790
  * @param {joinMacCallback} callback - The callback function.
1791
1791
  * */
1792
- join: function(dialogIdOrJid, callback) {
1792
+ join: function (dialogIdOrJid, callback) {
1793
1793
  /**
1794
1794
  * Callback for QB.chat.muc.join().
1795
- * @param {Object} error - Returns error object or null.
1796
- * @param {Object} responce - Returns responce.
1795
+ * @param {Object} error - Returns error object or null
1796
+ * @param {Object} responce - Returns responce
1797
1797
  * @callback joinMacCallback
1798
1798
  * */
1799
1799
  var self = this,
@@ -1812,7 +1812,7 @@ MucProxy.prototype = {
1812
1812
 
1813
1813
  pres.c('x', {
1814
1814
  xmlns: chatUtils.MARKERS.MUC
1815
- }).c('history', { maxstanzas: 0 });
1815
+ }).c('history', {maxstanzas: 0});
1816
1816
 
1817
1817
  this.joinedRooms[dialogJid] = true;
1818
1818
 
@@ -1820,7 +1820,7 @@ MucProxy.prototype = {
1820
1820
  var id = chatUtils.getAttr(stanza, 'id');
1821
1821
  var from = chatUtils.getAttr(stanza, 'from');
1822
1822
  var dialogId = self.helpers.getDialogIdFromNode(from);
1823
-
1823
+
1824
1824
  var x = chatUtils.getElement(stanza, 'x');
1825
1825
  var xXMLNS = chatUtils.getAttr(x, 'xmlns');
1826
1826
  var status = chatUtils.getElement(x, 'status');
@@ -1831,18 +1831,18 @@ MucProxy.prototype = {
1831
1831
  return true;
1832
1832
  }
1833
1833
 
1834
- if(status && statusCode == '110') {
1834
+ if (status && statusCode == '110') {
1835
1835
  Utils.safeCallbackCall(callback, null, {
1836
1836
  dialogId: dialogId
1837
1837
  });
1838
1838
  } else {
1839
1839
  var type = chatUtils.getAttr(stanza, 'type');
1840
1840
 
1841
- if(type && type === 'error' && xXMLNS == 'http://jabber.org/protocol/muc' && id.endsWith(':join')) {
1841
+ if (type && type === 'error' && xXMLNS == 'http://jabber.org/protocol/muc' && id.endsWith(':join')) {
1842
1842
  var errorEl = chatUtils.getElement(stanza, 'error');
1843
1843
  var code = chatUtils.getAttr(errorEl, 'code');
1844
1844
  var errorMessage = chatUtils.getElementText(errorEl, 'text');
1845
-
1845
+
1846
1846
  Utils.safeCallbackCall(callback, {
1847
1847
  code: code || 500,
1848
1848
  message: errorMessage || 'Unknown issue'
@@ -1869,12 +1869,12 @@ MucProxy.prototype = {
1869
1869
  },
1870
1870
 
1871
1871
  /**
1872
- * Leave group chat dialog({@link https://docs.quickblox.com/docs/js-chat-dialogs#leave-dialog read more}).
1872
+ * Leave group chat dialog. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Chat_in_group_dialog More info.}
1873
1873
  * @memberof QB.chat.muc
1874
- * @param {String} dialogJid - Use dialog jid to leave to this dialog.
1874
+ * @param {String} dialogJid - Use dialog jid to join to this dialog.
1875
1875
  * @param {leaveMacCallback} callback - The callback function.
1876
1876
  * */
1877
- leave: function(jid, callback) {
1877
+ leave: function (jid, callback) {
1878
1878
  /**
1879
1879
  * Callback for QB.chat.muc.leave().
1880
1880
  * run without parameters;
@@ -1903,7 +1903,7 @@ MucProxy.prototype = {
1903
1903
  self.connection.send(pres);
1904
1904
  } else {
1905
1905
  /** The answer don't contain id */
1906
- if(typeof callback === 'function') {
1906
+ if (typeof callback === 'function') {
1907
1907
  self.nodeStanzasCallbacks['muc:leave'] = callback;
1908
1908
  }
1909
1909
 
@@ -1912,15 +1912,15 @@ MucProxy.prototype = {
1912
1912
  },
1913
1913
 
1914
1914
  /**
1915
- * Leave group chat dialog({@link https://docs.quickblox.com/docs/js-chat-dialogs#retrieve-online-users read more}).
1915
+ * Leave group chat dialog. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Chat_in_group_dialog More info.}
1916
1916
  * @memberof QB.chat.muc
1917
- * @param {String} dialogJid - Use dialog jid to get a list of online usersr in this dialog.
1917
+ * @param {String} dialogJid - Use dialog jid to join to this dialog.
1918
1918
  * @param {listOnlineUsersMacCallback} callback - The callback function.
1919
1919
  * */
1920
- listOnlineUsers: function(dialogJID, callback) {
1920
+ listOnlineUsers: function (dialogJID, callback) {
1921
1921
  /**
1922
1922
  * Callback for QB.chat.muc.leave().
1923
- * @param {Object} Users - List of online users.
1923
+ * @param {Object} Users - list of online users
1924
1924
  * @callback listOnlineUsersMacCallback
1925
1925
  * */
1926
1926
 
@@ -1942,12 +1942,12 @@ MucProxy.prototype = {
1942
1942
  function _getUsers(stanza) {
1943
1943
  var stanzaId = stanza.attrs.id;
1944
1944
 
1945
- if(self.nodeStanzasCallbacks[stanzaId]) {
1945
+ if (self.nodeStanzasCallbacks[stanzaId]) {
1946
1946
  var users = [],
1947
1947
  items = stanza.getChild('query').getChildElements('item'),
1948
1948
  userId;
1949
1949
 
1950
- for(var i = 0, len = items.length; i < len; i++) {
1950
+ for (var i = 0, len = items.length; i < len; i++) {
1951
1951
  userId = self.helpers.getUserIdFromRoomJid(items[i].attrs.jid);
1952
1952
  users.push(parseInt(userId));
1953
1953
  }
@@ -1957,7 +1957,7 @@ MucProxy.prototype = {
1957
1957
  }
1958
1958
 
1959
1959
  if (Utils.getEnv().browser) {
1960
- self.connection.sendIQ(iq, function(stanza) {
1960
+ self.connection.sendIQ(iq, function (stanza) {
1961
1961
  var items = stanza.getElementsByTagName('item'),
1962
1962
  userId;
1963
1963
 
@@ -1995,15 +1995,15 @@ function PrivacyListProxy(options) {
1995
1995
  **/
1996
1996
  PrivacyListProxy.prototype = {
1997
1997
  /**
1998
- * Create a privacy list({@link https://docs.quickblox.com/docs/js-chat-privacy-list#create-privacy-list read more}).
1998
+ * Create a privacy list. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Create_a_privacy_list_or_edit_existing_list More info.}
1999
1999
  * @memberof QB.chat.privacylist
2000
- * @param {Object} list - Privacy list object.
2000
+ * @param {Object} list - privacy list object.
2001
2001
  * @param {createPrivacylistCallback} callback - The callback function.
2002
2002
  * */
2003
- create: function(list, callback) {
2003
+ create: function (list, callback) {
2004
2004
  /**
2005
2005
  * Callback for QB.chat.privacylist.create().
2006
- * @param {Object} error - The error object.
2006
+ * @param {Object} error - The error object
2007
2007
  * @callback createPrivacylistCallback
2008
2008
  * */
2009
2009
  var self = this,
@@ -2041,8 +2041,8 @@ PrivacyListProxy.prototype = {
2041
2041
  name: list.name
2042
2042
  });
2043
2043
 
2044
- function createPrivacyItem(iq, params){
2045
- if(Utils.getEnv().browser) {
2044
+ function createPrivacyItem(iq, params) {
2045
+ if (Utils.getEnv().browser) {
2046
2046
  iq.c('item', {
2047
2047
  type: 'jid',
2048
2048
  value: params.jidOrMuc,
@@ -2072,7 +2072,7 @@ PrivacyListProxy.prototype = {
2072
2072
  }
2073
2073
 
2074
2074
  function createPrivacyItemMutal(iq, params) {
2075
- if(Utils.getEnv().browser) {
2075
+ if (Utils.getEnv().browser) {
2076
2076
  iq.c('item', {
2077
2077
  type: 'jid',
2078
2078
  value: params.jidOrMuc,
@@ -2101,39 +2101,39 @@ PrivacyListProxy.prototype = {
2101
2101
  userJid = self.helpers.jidOrUserId(parseInt(userId, 10));
2102
2102
  userMuc = self.helpers.getUserNickWithMucDomain(userId);
2103
2103
 
2104
- if(mutualBlock && userAction === 'deny'){
2104
+ if (mutualBlock && userAction === 'deny') {
2105
2105
  iq = createPrivacyItemMutal(iq, {
2106
- order: j+1,
2106
+ order: j + 1,
2107
2107
  jidOrMuc: userJid,
2108
2108
  userAction: userAction
2109
2109
  });
2110
2110
  iq = createPrivacyItemMutal(iq, {
2111
- order: j+2,
2111
+ order: j + 2,
2112
2112
  jidOrMuc: userMuc,
2113
2113
  userAction: userAction
2114
2114
  }).up().up();
2115
2115
  } else {
2116
2116
  iq = createPrivacyItem(iq, {
2117
- order: j+1,
2117
+ order: j + 1,
2118
2118
  jidOrMuc: userJid,
2119
2119
  userAction: userAction
2120
2120
  });
2121
2121
  iq = createPrivacyItem(iq, {
2122
- order: j+2,
2122
+ order: j + 2,
2123
2123
  jidOrMuc: userMuc,
2124
2124
  userAction: userAction
2125
2125
  });
2126
2126
  }
2127
2127
  }
2128
2128
 
2129
- if(Utils.getEnv().browser) {
2130
- self.connection.sendIQ(iq, function(stanzaResult) {
2129
+ if (Utils.getEnv().browser) {
2130
+ self.connection.sendIQ(iq, function (stanzaResult) {
2131
2131
  callback(null);
2132
- }, function(stanzaError){
2133
- if(stanzaError){
2132
+ }, function (stanzaError) {
2133
+ if (stanzaError) {
2134
2134
  var errorObject = chatUtils.getErrorFromXMLNode(stanzaError);
2135
2135
  callback(errorObject);
2136
- }else{
2136
+ } else {
2137
2137
  callback(Utils.getError(408));
2138
2138
  }
2139
2139
  });
@@ -2141,7 +2141,7 @@ PrivacyListProxy.prototype = {
2141
2141
  self.Client.send(iq);
2142
2142
 
2143
2143
  self.nodeStanzasCallbacks[iqParams.id] = function (stanza) {
2144
- if(!stanza.getChildElements('error').length){
2144
+ if (!stanza.getChildElements('error').length) {
2145
2145
  callback(null);
2146
2146
  } else {
2147
2147
  callback(Utils.getError(408));
@@ -2151,16 +2151,16 @@ PrivacyListProxy.prototype = {
2151
2151
  },
2152
2152
 
2153
2153
  /**
2154
- * Get the privacy list({@link https://docs.quickblox.com/docs/js-chat-privacy-list#retrieve-privacy-list-by-name read more}).
2154
+ * Get the privacy list. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Retrieve_a_privacy_list More info.}
2155
2155
  * @memberof QB.chat.privacylist
2156
2156
  * @param {String} name - The name of the list.
2157
2157
  * @param {getListPrivacylistCallback} callback - The callback function.
2158
2158
  * */
2159
- getList: function(name, callback) {
2159
+ getList: function (name, callback) {
2160
2160
  /**
2161
2161
  * Callback for QB.chat.privacylist.getList().
2162
- * @param {Object} error - The error object.
2163
- * @param {Object} response - The privacy list object.
2162
+ * @param {Object} error - The error object
2163
+ * @param {Object} response - The privacy list object
2164
2164
  * @callback getListPrivacylistCallback
2165
2165
  * */
2166
2166
 
@@ -2183,11 +2183,11 @@ PrivacyListProxy.prototype = {
2183
2183
  name: name
2184
2184
  });
2185
2185
 
2186
- if(Utils.getEnv().browser) {
2187
- self.connection.sendIQ(iq, function(stanzaResult) {
2186
+ if (Utils.getEnv().browser) {
2187
+ self.connection.sendIQ(iq, function (stanzaResult) {
2188
2188
  items = stanzaResult.getElementsByTagName('item');
2189
2189
 
2190
- for (var i = 0, len = items.length; i < len; i=i+2) {
2190
+ for (var i = 0, len = items.length; i < len; i = i + 2) {
2191
2191
  userJid = items[i].getAttribute('value');
2192
2192
  userId = self.helpers.getIdFromNode(userJid);
2193
2193
  usersList.push({
@@ -2200,22 +2200,22 @@ PrivacyListProxy.prototype = {
2200
2200
  items: usersList
2201
2201
  };
2202
2202
  callback(null, list);
2203
- }, function(stanzaError){
2204
- if(stanzaError){
2203
+ }, function (stanzaError) {
2204
+ if (stanzaError) {
2205
2205
  var errorObject = chatUtils.getErrorFromXMLNode(stanzaError);
2206
2206
  callback(errorObject, null);
2207
- }else{
2207
+ } else {
2208
2208
  callback(Utils.getError(408), null);
2209
2209
  }
2210
2210
  });
2211
2211
  } else {
2212
- self.nodeStanzasCallbacks[iqParams.id] = function(stanza){
2212
+ self.nodeStanzasCallbacks[iqParams.id] = function (stanza) {
2213
2213
  var stanzaQuery = stanza.getChild('query'),
2214
2214
  list = stanzaQuery ? stanzaQuery.getChild('list') : null,
2215
2215
  items = list ? list.getChildElements('item') : null,
2216
2216
  userJid, userId, usersList = [];
2217
2217
 
2218
- for (var i = 0, len = items.length; i < len; i=i+2) {
2218
+ for (var i = 0, len = items.length; i < len; i = i + 2) {
2219
2219
  userJid = items[i].attrs.value;
2220
2220
  userId = self.helpers.getIdFromNode(userJid);
2221
2221
  usersList.push({
@@ -2238,22 +2238,22 @@ PrivacyListProxy.prototype = {
2238
2238
  },
2239
2239
 
2240
2240
  /**
2241
- * Update the privacy list({@link https://docs.quickblox.com/docs/js-chat-privacy-list#update-privacy-list read more}).
2241
+ * Update the privacy list.
2242
2242
  * @memberof QB.chat.privacylist
2243
2243
  * @param {String} name - The name of the list.
2244
2244
  * @param {updatePrivacylistCallback} callback - The callback function.
2245
2245
  * */
2246
- update: function(listWithUpdates, callback) {
2246
+ update: function (listWithUpdates, callback) {
2247
2247
  /**
2248
2248
  * Callback for QB.chat.privacylist.update().
2249
- * @param {Object} error - The error object.
2250
- * @param {Object} response - The privacy list object.
2249
+ * @param {Object} error - The error object
2250
+ * @param {Object} response - The privacy list object
2251
2251
  * @callback updatePrivacylistCallback
2252
2252
  * */
2253
2253
 
2254
2254
  var self = this;
2255
2255
 
2256
- self.getList(listWithUpdates.name, function(error, existentList) {
2256
+ self.getList(listWithUpdates.name, function (error, existentList) {
2257
2257
  if (error) {
2258
2258
  callback(error, null);
2259
2259
  } else {
@@ -2261,10 +2261,10 @@ PrivacyListProxy.prototype = {
2261
2261
  updatedList.items = Utils.MergeArrayOfObjects(existentList.items, listWithUpdates.items);
2262
2262
  updatedList.name = listWithUpdates.name;
2263
2263
 
2264
- self.create(updatedList, function(err, result) {
2264
+ self.create(updatedList, function (err, result) {
2265
2265
  if (error) {
2266
2266
  callback(err, null);
2267
- }else{
2267
+ } else {
2268
2268
  callback(null, result);
2269
2269
  }
2270
2270
  });
@@ -2273,16 +2273,16 @@ PrivacyListProxy.prototype = {
2273
2273
  },
2274
2274
 
2275
2275
  /**
2276
- * Get names of privacy lists({@link https://docs.quickblox.com/docs/js-chat-privacy-list#retrieve-privacy-lists read more}).
2276
+ * Get names of privacy lists. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Retrieve_privacy_lists_names More info.}
2277
2277
  * Run without parameters
2278
2278
  * @memberof QB.chat.privacylist
2279
2279
  * @param {getNamesPrivacylistCallback} callback - The callback function.
2280
2280
  * */
2281
- getNames: function(callback) {
2281
+ getNames: function (callback) {
2282
2282
  /**
2283
2283
  * Callback for QB.chat.privacylist.getNames().
2284
- * @param {Object} error - The error object.
2285
- * @param {Object} response - The privacy list object (var names = response.names;).
2284
+ * @param {Object} error - The error object
2285
+ * @param {Object} response - The privacy list object (var names = response.names;)
2286
2286
  * @callback getNamesPrivacylistCallback
2287
2287
  * */
2288
2288
 
@@ -2294,12 +2294,12 @@ PrivacyListProxy.prototype = {
2294
2294
  'id': chatUtils.getUniqueId('getNames')
2295
2295
  };
2296
2296
 
2297
- if(Utils.getEnv().browser){
2297
+ if (Utils.getEnv().browser) {
2298
2298
  iq = $iq(stanzaParams).c('query', {
2299
2299
  xmlns: Strophe.NS.PRIVACY_LIST
2300
2300
  });
2301
2301
 
2302
- self.connection.sendIQ(iq, function(stanzaResult) {
2302
+ self.connection.sendIQ(iq, function (stanzaResult) {
2303
2303
  var allNames = [], namesList = {},
2304
2304
  defaultList = stanzaResult.getElementsByTagName('default'),
2305
2305
  activeList = stanzaResult.getElementsByTagName('active'),
@@ -2319,11 +2319,11 @@ PrivacyListProxy.prototype = {
2319
2319
  };
2320
2320
 
2321
2321
  callback(null, namesList);
2322
- }, function(stanzaError){
2323
- if(stanzaError){
2322
+ }, function (stanzaError) {
2323
+ if (stanzaError) {
2324
2324
  var errorObject = chatUtils.getErrorFromXMLNode(stanzaError);
2325
2325
  callback(errorObject, null);
2326
- }else{
2326
+ } else {
2327
2327
  callback(Utils.getError(408), null);
2328
2328
  }
2329
2329
  });
@@ -2334,8 +2334,8 @@ PrivacyListProxy.prototype = {
2334
2334
  xmlns: chatUtils.MARKERS.PRIVACY
2335
2335
  });
2336
2336
 
2337
- self.nodeStanzasCallbacks[iq.attrs.id] = function(stanza){
2338
- if(stanza.attrs.type !== 'error'){
2337
+ self.nodeStanzasCallbacks[iq.attrs.id] = function (stanza) {
2338
+ if (stanza.attrs.type !== 'error') {
2339
2339
 
2340
2340
  var allNames = [], namesList = {},
2341
2341
  query = stanza.getChild('query'),
@@ -2367,15 +2367,15 @@ PrivacyListProxy.prototype = {
2367
2367
  },
2368
2368
 
2369
2369
  /**
2370
- * Delete privacy list({@link https://docs.quickblox.com/docs/js-chat-privacy-list#remove-privacy-list read more}).
2370
+ * Delete privacy list. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Delete_existing_privacy_list More info.}
2371
2371
  * @param {String} name - The name of privacy list.
2372
2372
  * @memberof QB.chat.privacylist
2373
2373
  * @param {deletePrivacylistCallback} callback - The callback function.
2374
2374
  * */
2375
- delete: function(name, callback) {
2375
+ delete: function (name, callback) {
2376
2376
  /**
2377
2377
  * Callback for QB.chat.privacylist.delete().
2378
- * @param {Object} error - The error object.
2378
+ * @param {Object} error - The error object
2379
2379
  * @callback deletePrivacylistCallback
2380
2380
  * */
2381
2381
 
@@ -2386,20 +2386,20 @@ PrivacyListProxy.prototype = {
2386
2386
  'id': chatUtils.getUniqueId('remove')
2387
2387
  };
2388
2388
 
2389
- if(Utils.getEnv().browser){
2389
+ if (Utils.getEnv().browser) {
2390
2390
  iq = $iq(stanzaParams).c('query', {
2391
2391
  xmlns: Strophe.NS.PRIVACY_LIST
2392
2392
  }).c('list', {
2393
2393
  name: name ? name : ''
2394
2394
  });
2395
2395
 
2396
- this.connection.sendIQ(iq, function(stanzaResult) {
2396
+ this.connection.sendIQ(iq, function (stanzaResult) {
2397
2397
  callback(null);
2398
- }, function(stanzaError){
2399
- if(stanzaError){
2398
+ }, function (stanzaError) {
2399
+ if (stanzaError) {
2400
2400
  var errorObject = chatUtils.getErrorFromXMLNode(stanzaError);
2401
2401
  callback(errorObject);
2402
- }else{
2402
+ } else {
2403
2403
  callback(Utils.getError(408));
2404
2404
  }
2405
2405
  });
@@ -2413,8 +2413,8 @@ PrivacyListProxy.prototype = {
2413
2413
  name: name ? name : ''
2414
2414
  });
2415
2415
 
2416
- this.nodeStanzasCallbacks[stanzaParams.id] = function(stanza){
2417
- if(!stanza.getChildElements('error').length){
2416
+ this.nodeStanzasCallbacks[stanzaParams.id] = function (stanza) {
2417
+ if (!stanza.getChildElements('error').length) {
2418
2418
  callback(null);
2419
2419
  } else {
2420
2420
  callback(Utils.getError(408));
@@ -2427,15 +2427,15 @@ PrivacyListProxy.prototype = {
2427
2427
  },
2428
2428
 
2429
2429
  /**
2430
- * Set as default privacy list({@link https://docs.quickblox.com/docs/js-chat-privacy-list#activate-privacy-list read more}).
2430
+ * Set as default privacy list. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Activate_a_privacy_list More info.}
2431
2431
  * @param {String} name - The name of privacy list.
2432
2432
  * @memberof QB.chat.privacylist
2433
2433
  * @param {setAsDefaultPrivacylistCallback} callback - The callback function.
2434
2434
  * */
2435
- setAsDefault: function(name, callback) {
2435
+ setAsDefault: function (name, callback) {
2436
2436
  /**
2437
2437
  * Callback for QB.chat.privacylist.setAsDefault().
2438
- * @param {Object} error - The error object.
2438
+ * @param {Object} error - The error object
2439
2439
  * @callback setAsDefaultPrivacylistCallback
2440
2440
  * */
2441
2441
 
@@ -2447,18 +2447,18 @@ PrivacyListProxy.prototype = {
2447
2447
  'id': chatUtils.getUniqueId('default')
2448
2448
  };
2449
2449
 
2450
- if(Utils.getEnv().browser){
2450
+ if (Utils.getEnv().browser) {
2451
2451
  iq = $iq(stanzaParams).c('query', {
2452
2452
  xmlns: Strophe.NS.PRIVACY_LIST
2453
2453
  }).c('default', name && name.length > 0 ? {name: name} : {});
2454
2454
 
2455
- this.connection.sendIQ(iq, function(stanzaResult) {
2455
+ this.connection.sendIQ(iq, function (stanzaResult) {
2456
2456
  setAsActive(self); //Activate list after setting it as default.
2457
- }, function(stanzaError){
2458
- if(stanzaError){
2457
+ }, function (stanzaError) {
2458
+ if (stanzaError) {
2459
2459
  var errorObject = chatUtils.getErrorFromXMLNode(stanzaError);
2460
2460
  callback(errorObject);
2461
- }else{
2461
+ } else {
2462
2462
  callback(Utils.getError(408));
2463
2463
  }
2464
2464
  });
@@ -2469,8 +2469,8 @@ PrivacyListProxy.prototype = {
2469
2469
  xmlns: chatUtils.MARKERS.PRIVACY
2470
2470
  }).c('default', name && name.length > 0 ? {name: name} : {});
2471
2471
 
2472
- this.nodeStanzasCallbacks[stanzaParams.id] = function(stanza){
2473
- if(!stanza.getChildElements('error').length){
2472
+ this.nodeStanzasCallbacks[stanzaParams.id] = function (stanza) {
2473
+ if (!stanza.getChildElements('error').length) {
2474
2474
  setAsActive(self); //Activate list after setting it as default.
2475
2475
  } else {
2476
2476
  callback(Utils.getError(408));
@@ -2480,27 +2480,27 @@ PrivacyListProxy.prototype = {
2480
2480
  }
2481
2481
 
2482
2482
  /**
2483
- * Set as active privacy list after setting as default.
2484
- * @param {PrivacyListProxy} self - Privacy list.
2485
- * */
2483
+ * Set as active privacy list after setting as default.
2484
+ * @param {PrivacyListProxy Object} self - The name of privacy list.
2485
+ * */
2486
2486
  function setAsActive(self) {
2487
2487
  var setAsActiveIq,
2488
- setAsActiveStanzaParams = {
2489
- 'from': self.connection ? self.connection.jid : self.Client.jid.user,
2490
- 'type': 'set',
2491
- 'id': chatUtils.getUniqueId('active1')
2492
- };
2493
- if(Utils.getEnv().browser){
2488
+ setAsActiveStanzaParams = {
2489
+ 'from': self.connection ? self.connection.jid : self.Client.jid.user,
2490
+ 'type': 'set',
2491
+ 'id': chatUtils.getUniqueId('active1')
2492
+ };
2493
+ if (Utils.getEnv().browser) {
2494
2494
  setAsActiveIq = $iq(setAsActiveStanzaParams).c('query', {
2495
2495
  xmlns: Strophe.NS.PRIVACY_LIST
2496
2496
  }).c('active', name && name.length > 0 ? {name: name} : {});
2497
- self.connection.sendIQ(setAsActiveIq, function(setAsActiveStanzaResult) {
2497
+ self.connection.sendIQ(setAsActiveIq, function (setAsActiveStanzaResult) {
2498
2498
  callback(null);
2499
- }, function(setAsActiveStanzaError){
2500
- if(setAsActiveStanzaError){
2499
+ }, function (setAsActiveStanzaError) {
2500
+ if (setAsActiveStanzaError) {
2501
2501
  var setAsActiveErrorObject = chatUtils.getErrorFromXMLNode(setAsActiveStanzaError);
2502
2502
  callback(setAsActiveErrorObject);
2503
- }else{
2503
+ } else {
2504
2504
  callback(Utils.getError(408));
2505
2505
  }
2506
2506
  });
@@ -2509,8 +2509,8 @@ PrivacyListProxy.prototype = {
2509
2509
  setAsActiveIq.c('query', {
2510
2510
  xmlns: chatUtils.MARKERS.PRIVACY
2511
2511
  }).c('active', name && name.length > 0 ? {name: name} : {});
2512
- self.nodeStanzasCallbacks[setAsActiveStanzaParams.id] = function(setAsActistanza){
2513
- if(!setAsActistanza.getChildElements('error').length){
2512
+ self.nodeStanzasCallbacks[setAsActiveStanzaParams.id] = function (setAsActistanza) {
2513
+ if (!setAsActistanza.getChildElements('error').length) {
2514
2514
  callback(null);
2515
2515
  } else {
2516
2516
  callback(Utils.getError(408));
@@ -2528,6 +2528,7 @@ PrivacyListProxy.prototype = {
2528
2528
  function Helpers() {
2529
2529
  this._userCurrentJid = '';
2530
2530
  }
2531
+
2531
2532
  /**
2532
2533
  * @namespace QB.chat.helpers
2533
2534
  * */
@@ -2536,7 +2537,7 @@ Helpers.prototype = {
2536
2537
  /**
2537
2538
  * Get unique id.
2538
2539
  * @memberof QB.chat.helpers
2539
- * @param {String | Number} suffix - Not required parameter.
2540
+ * @param {String | Number} suffix - not required parameter.
2540
2541
  * @returns {String} - UniqueId.
2541
2542
  * */
2542
2543
  getUniqueId: chatUtils.getUniqueId,
@@ -2547,7 +2548,7 @@ Helpers.prototype = {
2547
2548
  * @param {String | Number} jid_or_user_id - Jid or user id.
2548
2549
  * @returns {String} - jid.
2549
2550
  * */
2550
- jidOrUserId: function(jid_or_user_id) {
2551
+ jidOrUserId: function (jid_or_user_id) {
2551
2552
  var jid;
2552
2553
  if (typeof jid_or_user_id === 'string') {
2553
2554
  jid = jid_or_user_id;
@@ -2565,7 +2566,7 @@ Helpers.prototype = {
2565
2566
  * @param {String | Number} jid_or_user_id - Jid or user id.
2566
2567
  * @returns {String} - jid.
2567
2568
  * */
2568
- typeChat: function(jid_or_user_id) {
2569
+ typeChat: function (jid_or_user_id) {
2569
2570
  var chatType;
2570
2571
  if (typeof jid_or_user_id === 'string') {
2571
2572
  chatType = jid_or_user_id.indexOf("muc") > -1 ? 'groupchat' : 'chat';
@@ -2582,12 +2583,12 @@ Helpers.prototype = {
2582
2583
  * @memberof QB.chat.helpers
2583
2584
  * @param {Array} occupantsIds - Array of user ids.
2584
2585
  * @param {Number} UserId - Jid or user id.
2585
- * @returns {Number} - Recipient id.
2586
+ * @returns {Number} recipient - recipient id.
2586
2587
  * */
2587
- getRecipientId: function(occupantsIds, UserId) {
2588
+ getRecipientId: function (occupantsIds, UserId) {
2588
2589
  var recipient = null;
2589
- occupantsIds.forEach(function(item) {
2590
- if(item != UserId){
2590
+ occupantsIds.forEach(function (item) {
2591
+ if (item != UserId) {
2591
2592
  recipient = item;
2592
2593
  }
2593
2594
  });
@@ -2601,8 +2602,8 @@ Helpers.prototype = {
2601
2602
  * @param {Number} appId - The application id.
2602
2603
  * @returns {String} jid - The user jid.
2603
2604
  * */
2604
- getUserJid: function(userId, appId) {
2605
- if(!appId){
2605
+ getUserJid: function (userId, appId) {
2606
+ if (!appId) {
2606
2607
  return userId + '-' + config.creds.appId + '@' + config.endpoints.chat;
2607
2608
  }
2608
2609
  return userId + '-' + appId + '@' + config.endpoints.chat;
@@ -2614,7 +2615,7 @@ Helpers.prototype = {
2614
2615
  * @param {Number} UserId - The user id.
2615
2616
  * @returns {String} mucDomainWithNick - The mac domain with he nick.
2616
2617
  * */
2617
- getUserNickWithMucDomain: function(userId) {
2618
+ getUserNickWithMucDomain: function (userId) {
2618
2619
  return config.endpoints.muc + '/' + userId;
2619
2620
  },
2620
2621
 
@@ -2624,7 +2625,7 @@ Helpers.prototype = {
2624
2625
  * @param {String} jid - The user jid.
2625
2626
  * @returns {Number} id - The user id.
2626
2627
  * */
2627
- getIdFromNode: function(jid) {
2628
+ getIdFromNode: function (jid) {
2628
2629
  return (jid.indexOf('@') < 0) ? null : parseInt(jid.split('@')[0].split('-')[0]);
2629
2630
  },
2630
2631
 
@@ -2634,7 +2635,7 @@ Helpers.prototype = {
2634
2635
  * @param {String} jid - The dialog jid.
2635
2636
  * @returns {String} dialogId - The dialog id.
2636
2637
  * */
2637
- getDialogIdFromNode: function(jid) {
2638
+ getDialogIdFromNode: function (jid) {
2638
2639
  if (jid.indexOf('@') < 0) return null;
2639
2640
  return jid.split('@')[0].split('_')[1];
2640
2641
  },
@@ -2645,7 +2646,7 @@ Helpers.prototype = {
2645
2646
  * @param {String} dialogId - The dialog id.
2646
2647
  * @returns {String} jid - The dialog jid.
2647
2648
  * */
2648
- getRoomJidFromDialogId: function(dialogId) {
2649
+ getRoomJidFromDialogId: function (dialogId) {
2649
2650
  return config.creds.appId + '_' + dialogId + '@' + config.endpoints.muc;
2650
2651
  },
2651
2652
 
@@ -2656,7 +2657,7 @@ Helpers.prototype = {
2656
2657
  * @param {String} userJid - user's jid.
2657
2658
  * @returns {String} jid - dialog's full jid.
2658
2659
  * */
2659
- getRoomJid: function(jid) {
2660
+ getRoomJid: function (jid) {
2660
2661
  return jid + '/' + this.getIdFromNode(this._userCurrentJid);
2661
2662
  },
2662
2663
 
@@ -2666,7 +2667,7 @@ Helpers.prototype = {
2666
2667
  * @param {String} jid - dialog's full jid.
2667
2668
  * @returns {String} user_id - User Id.
2668
2669
  * */
2669
- getIdFromResource: function(jid) {
2670
+ getIdFromResource: function (jid) {
2670
2671
  var s = jid.split('/');
2671
2672
  if (s.length < 2) return null;
2672
2673
  s.splice(0, 1);
@@ -2679,7 +2680,7 @@ Helpers.prototype = {
2679
2680
  * @param {String} jid - dialog's full jid.
2680
2681
  * @returns {String} room_jid - dialog's bare jid.
2681
2682
  * */
2682
- getRoomJidFromRoomFullJid: function(jid) {
2683
+ getRoomJidFromRoomFullJid: function (jid) {
2683
2684
  var s = jid.split('/');
2684
2685
  if (s.length < 2) return null;
2685
2686
  return s[0];
@@ -2690,7 +2691,7 @@ Helpers.prototype = {
2690
2691
  * @memberof QB.chat.helpers
2691
2692
  * @returns {String} BsonObjectId - The bson object id.
2692
2693
  **/
2693
- getBsonObjectId: function() {
2694
+ getBsonObjectId: function () {
2694
2695
  return Utils.getBsonObjectId();
2695
2696
  },
2696
2697
 
@@ -2700,17 +2701,17 @@ Helpers.prototype = {
2700
2701
  * @param {String} jid - resourse jid.
2701
2702
  * @returns {String} userId - The user id.
2702
2703
  * */
2703
- getUserIdFromRoomJid: function(jid) {
2704
+ getUserIdFromRoomJid: function (jid) {
2704
2705
  var arrayElements = jid.toString().split('/');
2705
- if(arrayElements.length === 0){
2706
+ if (arrayElements.length === 0) {
2706
2707
  return null;
2707
2708
  }
2708
- return arrayElements[arrayElements.length-1];
2709
+ return arrayElements[arrayElements.length - 1];
2709
2710
  },
2710
2711
 
2711
- userCurrentJid: function(client){
2712
+ userCurrentJid: function (client) {
2712
2713
  try {
2713
- if (client instanceof Strophe.Connection){
2714
+ if (client instanceof Strophe.Connection) {
2714
2715
  return client.jid;
2715
2716
  } else {
2716
2717
  return client.jid.user + '@' + client.jid._domain + '/' + client.jid._resource;
@@ -2720,15 +2721,15 @@ Helpers.prototype = {
2720
2721
  }
2721
2722
  },
2722
2723
 
2723
- getUserCurrentJid: function() {
2724
+ getUserCurrentJid: function () {
2724
2725
  return this._userCurrentJid;
2725
2726
  },
2726
2727
 
2727
- setUserCurrentJid: function(jid) {
2728
+ setUserCurrentJid: function (jid) {
2728
2729
  this._userCurrentJid = jid;
2729
2730
  },
2730
2731
 
2731
- getDialogJid: function(identifier) {
2732
+ getDialogJid: function (identifier) {
2732
2733
  return identifier.indexOf('@') > 0 ? identifier : this.getRoomJidFromDialogId(identifier);
2733
2734
  }
2734
2735
  };