quickblox 2.17.1 → 2.17.2-beta.2-logger

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.
@@ -39,7 +39,7 @@ function ChatProxy(service) {
39
39
  */
40
40
  if (Utils.getEnv().browser) {
41
41
  // strophe js
42
- self.connection = Connection();
42
+ self.connection = Connection(self.onLogListener);
43
43
 
44
44
  /** Add extension methods to track handlers for removal on reconnect */
45
45
  self.connection.XHandlerReferences = [];
@@ -155,6 +155,7 @@ function ChatProxy(service) {
155
155
  * - onDisconnectedListener
156
156
  * - onReconnectListener
157
157
  * - onSessionExpiredListener
158
+ * - onLogListener
158
159
  */
159
160
 
160
161
  /**
@@ -288,6 +289,12 @@ function ChatProxy(service) {
288
289
  * @memberOf QB.chat
289
290
  **/
290
291
 
292
+ /**
293
+ * Run after disconnect from chat to log result
294
+ * @function onLogListener
295
+ * @memberOf QB.chat
296
+ **/
297
+
291
298
 
292
299
  this._onMessage = function (stanza) {
293
300
  var from = chatUtils.getAttr(stanza, 'from'),
@@ -744,7 +751,7 @@ ChatProxy.prototype = {
744
751
  /** Connect for browser env. */
745
752
  if (Utils.getEnv().browser) {
746
753
  Utils.QBLog('[QBChat]', '!!---Browser env - connected--!!');
747
-
754
+ let disconnectCondition = '';
748
755
  self.connection.connect(userJid, params.password, function (status) {
749
756
  Utils.QBLog('[QBChat]', 'self.connection.connect called with status ' + status);
750
757
  switch (status) {
@@ -873,7 +880,14 @@ ChatProxy.prototype = {
873
880
  break;
874
881
  case Strophe.Status.DISCONNECTED:
875
882
  Utils.QBLog('[QBChat]', 'Status.DISCONNECTED at ' + chatUtils.getLocalTime());
876
-
883
+ //
884
+ Utils.QBLog('[QBChat]', 'DISCONNECTED CONDITION: ' + disconnectCondition);
885
+ //
886
+ if (typeof self.onLogListener === 'function') {
887
+ Utils.safeCallbackCall(self.onLogListener,
888
+ '[QBChat]' + ' Status.DISCONNECTED at ' +
889
+ chatUtils.getLocalTime()+ ' DISCONNECTED CONDITION: ' + disconnectCondition);
890
+ }
877
891
  // fire 'onDisconnectedListener' only once
878
892
  if (self.isConnected && typeof self.onDisconnectedListener === 'function') {
879
893
  Utils.safeCallbackCall(self.onDisconnectedListener);
@@ -1031,20 +1045,45 @@ ChatProxy.prototype = {
1031
1045
  _establishConnection: function (params) {
1032
1046
  var self = this;
1033
1047
  Utils.QBLog('[QBChat]', '_establishConnection called');
1048
+ if (typeof self.onLogListener === 'function') {
1049
+ Utils.safeCallbackCall(self.onLogListener,
1050
+ '[QBChat]' + '_establishConnection called');
1051
+ }
1034
1052
  if (self._isLogout || self._checkConnectionTimer) {
1035
1053
  Utils.QBLog('[QBChat]', '_establishConnection return');
1054
+ if (typeof self.onLogListener === 'function') {
1055
+ Utils.safeCallbackCall(self.onLogListener,
1056
+ '[QBChat]' + ' _establishConnection return with self._isLogout: '+
1057
+ self._isLogout+' and self._checkConnectionTimer ' +self._checkConnectionTimer?'set up':'undefined');
1058
+ }
1036
1059
  return;
1037
1060
  }
1038
1061
 
1039
1062
  var _connect = function () {
1040
1063
  Utils.QBLog('[QBChat]', 'call _connect() in _establishConnection ');
1064
+ if (typeof self.onLogListener === 'function') {
1065
+ Utils.safeCallbackCall(self.onLogListener,
1066
+ '[QBChat]' + ' call _connect() in _establishConnection ');
1067
+ }
1041
1068
  if (!self.isConnected && !self._isConnecting && !self._sessionHasExpired) {
1042
- Utils.QBLog('[QBChat]', 'call connect() again in _establishConnection ');
1069
+ Utils.QBLog('[QBChat]', ' start execute connect() in _establishConnection ');
1070
+ if (typeof self.onLogListener === 'function') {
1071
+ Utils.safeCallbackCall(self.onLogListener,
1072
+ '[QBChat]' + ' with statuses (!self.isConnected && !self._isConnecting && !self._sessionHasExpired): '+' self.isConnected: '+self.isConnected+' self._isConnecting: '+self._isConnecting+' self._sessionHasExpired: '+self._sessionHasExpired);
1073
+ }
1043
1074
  self.connect(params);
1075
+ if (typeof self.onLogListener === 'function') {
1076
+ Utils.safeCallbackCall(self.onLogListener,
1077
+ '[QBChat]' + 'call _connect() in _establishConnection is executed');
1078
+ }
1044
1079
  } else {
1045
1080
  Utils.QBLog('[QBChat]', 'stop timer in _establishConnection ');
1046
1081
  clearInterval(self._checkConnectionTimer);
1047
1082
  self._checkConnectionTimer = undefined;
1083
+ if (typeof self.onLogListener === 'function') {
1084
+ Utils.safeCallbackCall(self.onLogListener,
1085
+ '[QBChat]' + 'stop timer in _establishConnection ');
1086
+ }
1048
1087
  }
1049
1088
  };
1050
1089
 
@@ -1052,6 +1091,10 @@ ChatProxy.prototype = {
1052
1091
 
1053
1092
  self._checkConnectionTimer = setInterval(function () {
1054
1093
  Utils.QBLog('[QBChat]', 'self._checkConnectionTimer called with config.chatReconnectionTimeInterval = ' + config.chatReconnectionTimeInterval);
1094
+ if (typeof self.onLogListener === 'function') {
1095
+ Utils.safeCallbackCall(self.onLogListener,
1096
+ '[QBChat]' + 'self._checkConnectionTimer called with config.chatReconnectionTimeInterval = ' + config.chatReconnectionTimeInterval);
1097
+ }
1055
1098
  _connect();
1056
1099
  }, config.chatReconnectionTimeInterval * 1000);
1057
1100
  },
package/src/qbConfig.js CHANGED
@@ -12,8 +12,8 @@
12
12
  */
13
13
 
14
14
  var config = {
15
- version: '2.17.1',
16
- buildNumber: '1161',
15
+ version: '2.17.2-beta.2-logger',
16
+ buildNumber: '1162',
17
17
  creds: {
18
18
  'appId': 0,
19
19
  'authKey': '',
package/src/qbStrophe.js CHANGED
@@ -13,7 +13,7 @@ var config = require('./qbConfig');
13
13
  var chatPRTCL = config.chatProtocol;
14
14
  var Utils = require('./qbUtils');
15
15
 
16
- function Connection() {
16
+ function Connection(onLogListener) {
17
17
  var protocol = chatPRTCL.active === 1 ? chatPRTCL.bosh : chatPRTCL.websocket;
18
18
  var conn = new Strophe.Connection(protocol);
19
19
 
@@ -35,6 +35,32 @@ function Connection() {
35
35
  } else {
36
36
  conn.xmlInput = function(data) {
37
37
  Utils.QBLog('[QBChat]', 'RECV:', data);
38
+ //
39
+ if (onLogListener && typeof onLogListener === 'function') {
40
+ Utils.safeCallbackCall(onLogListener,
41
+ '[QBChat][QBStrophe]' + 'RECV: ' + data);
42
+ }
43
+ //
44
+ try {
45
+ let parser = new DOMParser();
46
+ let xmlDoc = parser.parseFromString(data, 'text/xml');
47
+
48
+ let errorElem = xmlDoc.getElementsByTagName('error');
49
+ if (errorElem.length > 0) {
50
+ let conditionElem = errorElem[0].getElementsByTagName('condition');
51
+ if (conditionElem.length > 0) {
52
+ let disconnectCondition = conditionElem[0].textContent;
53
+ console.log('Disconnect condition:', disconnectCondition);
54
+ if (onLogListener && typeof onLogListener === 'function') {
55
+ Utils.safeCallbackCall(onLogListener,
56
+ '[QBChat][QBStrophe]' + 'DISCONNECTED CONDITION: ' + disconnectCondition);
57
+ }
58
+ }
59
+ }
60
+ } catch (e) {
61
+ console.error('Error parsing XML input:', e);
62
+ }
63
+ //
38
64
  };
39
65
  conn.xmlOutput = function(data) {
40
66
  Utils.QBLog('[QBChat]', 'SENT:', data);