quickblox 2.14.1 → 2.15.0

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.
@@ -87,7 +87,7 @@ function ChatProxy(service) {
87
87
  }
88
88
 
89
89
  this.service = service;
90
-
90
+
91
91
  // Check the chat connection (return true/false)
92
92
  this.isConnected = false;
93
93
  // Check the chat connecting state (return true/false)
@@ -95,7 +95,9 @@ function ChatProxy(service) {
95
95
  this._isLogout = false;
96
96
 
97
97
  this._checkConnectionTimer = undefined;
98
- // this._checkConnectionPingTimer = undefined; //artan: 13/09/2022 at 16:30
98
+ this._checkConnectionPingTimer = undefined;
99
+ this._localPingFaildCounter = 0;
100
+ this._onlineStatus = true;
99
101
  this._checkExpiredSessionTimer = undefined;
100
102
  this._sessionHasExpired = false;
101
103
  this._pings = {};
@@ -741,7 +743,10 @@ ChatProxy.prototype = {
741
743
 
742
744
  /** Connect for browser env. */
743
745
  if (Utils.getEnv().browser) {
746
+ Utils.QBLog('[QBChat]', '!!---Browser env - connected--!!');
747
+
744
748
  self.connection.connect(userJid, params.password, function(status) {
749
+ Utils.QBLog('[QBChat]', 'self.connection.connect called with status '+ status);
745
750
  switch (status) {
746
751
  case Strophe.Status.ERROR:
747
752
  self.isConnected = false;
@@ -772,7 +777,7 @@ ChatProxy.prototype = {
772
777
  case Strophe.Status.AUTHFAIL:
773
778
  self.isConnected = false;
774
779
  self._isConnecting = false;
775
-
780
+
776
781
  err = Utils.getError(401, 'Status.AUTHFAIL - The authentication attempt failed', 'QBChat');
777
782
 
778
783
  if (isInitialConnect) {
@@ -780,7 +785,6 @@ ChatProxy.prototype = {
780
785
  }
781
786
 
782
787
  if(!self.isConnected && typeof self.onReconnectFailedListener === 'function'){
783
- // TODO: investigate problem reconnect field
784
788
  Utils.safeCallbackCall(self.onReconnectFailedListener, err);
785
789
  }
786
790
 
@@ -802,26 +806,54 @@ ChatProxy.prototype = {
802
806
  self.connection.XAddTrackedHandler(self._onSystemMessageListener, null, 'message', 'headline');
803
807
  self.connection.XAddTrackedHandler(self._onMessageErrorListener, null, 'message', 'error');
804
808
 
805
- // var noTimerId = typeof self._checkConnectionPingTimer === 'undefined'; //artan: 13/09/2022 at 16:30
806
- // noTimerId = config.pingLocalhostTimeInterval === 0 ? false : noTimerId;
807
- // if (noTimerId) {
808
- // Utils.QBLog('[QBChat]', 'Init ping to localhost at ', Utils.getCurrentTime());
809
- // self._checkConnectionPingTimer = setInterval(function() {
810
- // self._ping(userJid,
811
- // function(error) {
812
- // if (error) {
813
- // Utils.QBLog('[QBChat]',
814
- // 'Local Ping: ',
815
- // 'failed, at ', Utils.getCurrentTime(),
816
- // ' error: ', error);
817
- // } else {
818
- // Utils.QBLog('[QBChat]',
819
- // 'Local Ping: ',
820
- // 'ok, at ', Utils.getCurrentTime());
821
- // }
822
- // });
823
- // }, config.pingLocalhostTimeInterval * 1000);
824
- // }
809
+ var noTimerId = typeof self._checkConnectionPingTimer === 'undefined';
810
+ noTimerId = config.pingLocalhostTimeInterval === 0 ? false : noTimerId;
811
+
812
+ if (noTimerId) {
813
+ Utils.QBLog('[QBChat]', 'Init ping to localhost at ', Utils.getCurrentTime());
814
+ self._checkConnectionPingTimer = setInterval(function() {
815
+ try {
816
+ self.pinglocalhost(function (error) {
817
+ if (error) {
818
+ Utils.QBLog('[QBChat]',
819
+ 'Local Ping: ',
820
+ 'failed, at ', Utils.getCurrentTime(),
821
+ '_localPingFaildCounter: ', self._localPingFaildCounter,
822
+ ' error: ', error);
823
+ self._localPingFaildCounter += 1;
824
+ if (self._localPingFaildCounter > 6) {
825
+ // TODO: check in [CROS-823]
826
+ self.isOnline(function () {
827
+ Utils.QBLog('[QBChat]',
828
+ 'Local Ping: ',
829
+ 'connection failed, at ', Utils.getCurrentTime());
830
+ }, function () {
831
+ console.log("call _establishConnection ....");
832
+
833
+ self.isConnected = false;
834
+ self._isConnecting = false;
835
+ self._localPingFaildCounter = 0;
836
+ self._establishConnection(params);
837
+ });
838
+
839
+ }
840
+ } else {
841
+ Utils.QBLog('[QBChat]',
842
+ 'Local Ping: ',
843
+ 'ok, at ', Utils.getCurrentTime(),
844
+ '_localPingFaildCounter: ', self._localPingFaildCounter);
845
+ self._localPingFaildCounter = 0;
846
+ }
847
+ });
848
+ }
849
+ catch (err) {
850
+ Utils.QBLog('[QBChat]',
851
+ 'Local Ping: ',
852
+ 'Exception, at ', Utils.getCurrentTime(),
853
+ ', detail info: ', err);
854
+ }
855
+ }, config.pingLocalhostTimeInterval * 1000);
856
+ }
825
857
 
826
858
  if (typeof self.onSessionExpiredListener === 'function') {
827
859
  var noExpiredSessionTimerId = typeof self._checkExpiredSessionTimer === 'undefined';
@@ -832,14 +864,14 @@ ChatProxy.prototype = {
832
864
  if (typeof config.qbTokenExpirationDate !== 'undefined') {
833
865
  var timeLag = Math.round((timeNow.getTime() - config.qbTokenExpirationDate.getTime()) / (1000 * 60));
834
866
  //artan 25-08-2022
835
- // TODO: need to delete in task [CROS-815]
867
+ // TODO: need to delete in task [CROS-823]
836
868
  console.log('timeLag: ', timeLag);
837
869
  if (timeLag >= 0) {
838
870
  self._sessionHasExpired = true;
839
871
  Utils.safeCallbackCall(self.onSessionExpiredListener, null);
840
872
  }
841
873
  }
842
- // TODO: in task [CROS-815], may by need to change 5 * 1000 to config.liveSessionInterval * 1000
874
+ // TODO: in task [CROS-823], may by need to change 5 * 1000 to config.liveSessionInterval * 1000
843
875
  }, 5 * 1000);
844
876
 
845
877
  }
@@ -878,6 +910,7 @@ ChatProxy.prototype = {
878
910
 
879
911
  /** connect for node */
880
912
  if(!Utils.getEnv().browser) {
913
+ Utils.QBLog('[QBChat]', '!!--call branch code connect for node--!!');
881
914
  // Remove all connection handlers exist from a previous connection
882
915
  self.Client.removeAllListeners();
883
916
 
@@ -978,7 +1011,7 @@ ChatProxy.prototype = {
978
1011
  }
979
1012
 
980
1013
  self.helpers.setUserCurrentJid(self.helpers.userCurrentJid(xmppClient));
981
-
1014
+
982
1015
  self.isConnected = true;
983
1016
  self._isConnecting = false;
984
1017
  self._sessionHasExpired = false;
@@ -1010,7 +1043,6 @@ ChatProxy.prototype = {
1010
1043
  },
1011
1044
 
1012
1045
  _establishConnection: function(params) {
1013
- // TODO: must to call if only qbTokenExpirationDate is not expried
1014
1046
  var self = this;
1015
1047
  Utils.QBLog('[QBChat]', '_establishConnection called');
1016
1048
  if (self._isLogout || self._checkConnectionTimer) {
@@ -1032,13 +1064,27 @@ ChatProxy.prototype = {
1032
1064
 
1033
1065
  _connect();
1034
1066
 
1035
-
1036
- // TODO: investigate problem with interval connection
1037
1067
  self._checkConnectionTimer = setInterval(function() {
1068
+ Utils.QBLog('[QBChat]', 'self._checkConnectionTimer called with config.chatReconnectionTimeInterval = '+config.chatReconnectionTimeInterval);
1038
1069
  _connect();
1039
1070
  }, config.chatReconnectionTimeInterval * 1000);
1040
1071
  },
1041
1072
 
1073
+ reconnect: function () {
1074
+ Utils.QBLog('[QBChat]', 'Call reconnect ');
1075
+ clearInterval(this._checkConnectionTimer);
1076
+ this._checkConnectionTimer = undefined;
1077
+ this.muc.joinedRooms = {};
1078
+ this.helpers.setUserCurrentJid('');
1079
+
1080
+ if (Utils.getEnv().browser) {
1081
+ this.connection.flush();
1082
+ this.connection.disconnect();
1083
+ } else {
1084
+ this.Client.end();
1085
+ }
1086
+ },
1087
+
1042
1088
  /**
1043
1089
  * Send message to 1 to 1 or group dialog. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Chat_in_dialog More info.}
1044
1090
  * @memberof QB.chat
@@ -1174,12 +1220,10 @@ ChatProxy.prototype = {
1174
1220
  xmlns: chatUtils.MARKERS.STATES
1175
1221
  });
1176
1222
 
1177
- if (self.connection.connected) {
1178
- if(Utils.getEnv().browser){
1179
- self.connection.send(stanza);
1180
- } else {
1181
- self.Client.send(stanza);
1182
- }
1223
+ if(Utils.getEnv().browser){
1224
+ self.connection.send(stanza);
1225
+ } else {
1226
+ self.Client.send(stanza);
1183
1227
  }
1184
1228
  },
1185
1229
 
@@ -1204,12 +1248,10 @@ ChatProxy.prototype = {
1204
1248
  xmlns: chatUtils.MARKERS.STATES
1205
1249
  });
1206
1250
 
1207
- if (self.connection.connected) {
1208
- if(Utils.getEnv().browser){
1209
- self.connection.send(stanza);
1210
- } else {
1211
- self.Client.send(stanza);
1212
- }
1251
+ if(Utils.getEnv().browser){
1252
+ self.connection.send(stanza);
1253
+ } else {
1254
+ self.Client.send(stanza);
1213
1255
  }
1214
1256
  },
1215
1257
 
@@ -1320,7 +1362,8 @@ ChatProxy.prototype = {
1320
1362
  }
1321
1363
  },
1322
1364
 
1323
- _ping: function(jid_or_user_id, callback){
1365
+ pinglocalhost: function(callback){
1366
+ Utils.QBLog('[QBChat]', 'ping localhost');
1324
1367
  var self = this;
1325
1368
  var id = this.helpers.getUniqueId('ping');
1326
1369
  var builder = Utils.getEnv().browser ? $iq : XMPP.Stanza;
@@ -1332,7 +1375,6 @@ ChatProxy.prototype = {
1332
1375
  to = 'http://localhost';
1333
1376
  _callback = callback;
1334
1377
 
1335
-
1336
1378
  var iqParams = {
1337
1379
  from: this.helpers.getUserCurrentJid(),
1338
1380
  id: id,
@@ -1343,7 +1385,7 @@ ChatProxy.prototype = {
1343
1385
  stanza.c('ping', { xmlns: "urn:xmpp:ping" });
1344
1386
 
1345
1387
  var noAnswer = function () {
1346
- _callback('No answer');
1388
+ _callback('Local ping No answer');
1347
1389
  self._pings[id] = undefined;
1348
1390
  delete self._pings[id];
1349
1391
  };
@@ -1359,6 +1401,21 @@ ChatProxy.prototype = {
1359
1401
  return id;
1360
1402
  },
1361
1403
 
1404
+ isOnline: function(no, yes) {
1405
+ const server = 'chat.quickblox.com';
1406
+ try {
1407
+ this.ping(server, (error) => {
1408
+ if (error) {
1409
+ no();
1410
+ } else {
1411
+ yes();
1412
+ }
1413
+ });
1414
+ } catch (err) {
1415
+ no();
1416
+ }
1417
+ },
1418
+
1362
1419
  ping: function (jid_or_user_id, callback) {
1363
1420
  Utils.QBLog('[QBChat]', 'Call ping ');
1364
1421
  var self = this;
@@ -1424,6 +1481,11 @@ ChatProxy.prototype = {
1424
1481
  if (Utils.getEnv().browser) {
1425
1482
  this.connection.flush();
1426
1483
  this.connection.disconnect();
1484
+ if (this._checkConnectionPingTimer !== undefined) {
1485
+ Utils.QBLog('[QBChat]', 'Stop ping to localhost.');
1486
+ clearInterval(this._checkConnectionPingTimer);
1487
+ this._checkConnectionPingTimer = undefined;
1488
+ }
1427
1489
  } else {
1428
1490
  this.Client.end();
1429
1491
  }
@@ -1536,7 +1598,6 @@ RosterProxy.prototype = {
1536
1598
 
1537
1599
  function _callbackWrap(stanza) {
1538
1600
  var items = _getItems(stanza);
1539
- /** TODO */
1540
1601
  for (var i = 0, len = items.length; i < len; i++) {
1541
1602
  var userId = self.helpers.getIdFromNode( chatUtils.getAttr(items[i], 'jid') ),
1542
1603
  ask = chatUtils.getAttr(items[i], 'ask'),