quickblox 2.17.0 → 2.17.1-beta-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.
- package/README.md +1 -1
- package/package.json +1 -1
- package/quickblox.d.ts +27 -21
- package/quickblox.js +93 -7
- package/quickblox.min.js +1 -1
- package/src/modules/chat/qbChat.js +69 -4
- package/src/qbConfig.js +2 -2
- package/src/qbStrophe.js +22 -1
|
@@ -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);
|
|
@@ -892,6 +906,28 @@ ChatProxy.prototype = {
|
|
|
892
906
|
break;
|
|
893
907
|
}
|
|
894
908
|
});
|
|
909
|
+
// connection error handler
|
|
910
|
+
self.connection.xmlInput = function (data) {
|
|
911
|
+
try {
|
|
912
|
+
let parser = new DOMParser();
|
|
913
|
+
let xmlDoc = parser.parseFromString(data, 'text/xml');
|
|
914
|
+
|
|
915
|
+
let errorElem = xmlDoc.getElementsByTagName('error');
|
|
916
|
+
if (errorElem.length > 0) {
|
|
917
|
+
let conditionElem = errorElem[0].getElementsByTagName('condition');
|
|
918
|
+
if (conditionElem.length > 0) {
|
|
919
|
+
disconnectCondition = conditionElem[0].textContent;
|
|
920
|
+
console.log('Disconnect condition:', disconnectCondition);
|
|
921
|
+
if (typeof self.onLogListener === 'function') {
|
|
922
|
+
Utils.safeCallbackCall(self.onLogListener,
|
|
923
|
+
'[QBChat]' + ' DISCONNECTED CONDITION: ' + disconnectCondition);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
} catch (e) {
|
|
928
|
+
console.error('Error parsing XML input:', e);
|
|
929
|
+
}
|
|
930
|
+
};
|
|
895
931
|
}
|
|
896
932
|
|
|
897
933
|
/** connect for node */
|
|
@@ -1031,20 +1067,45 @@ ChatProxy.prototype = {
|
|
|
1031
1067
|
_establishConnection: function (params) {
|
|
1032
1068
|
var self = this;
|
|
1033
1069
|
Utils.QBLog('[QBChat]', '_establishConnection called');
|
|
1070
|
+
if (typeof self.onLogListener === 'function') {
|
|
1071
|
+
Utils.safeCallbackCall(self.onLogListener,
|
|
1072
|
+
'[QBChat]' + '_establishConnection called');
|
|
1073
|
+
}
|
|
1034
1074
|
if (self._isLogout || self._checkConnectionTimer) {
|
|
1035
1075
|
Utils.QBLog('[QBChat]', '_establishConnection return');
|
|
1076
|
+
if (typeof self.onLogListener === 'function') {
|
|
1077
|
+
Utils.safeCallbackCall(self.onLogListener,
|
|
1078
|
+
'[QBChat]' + ' _establishConnection return with self._isLogout: '+
|
|
1079
|
+
self._isLogout+' and self._checkConnectionTimer ' +self._checkConnectionTimer?'set up':'undefined');
|
|
1080
|
+
}
|
|
1036
1081
|
return;
|
|
1037
1082
|
}
|
|
1038
1083
|
|
|
1039
1084
|
var _connect = function () {
|
|
1040
1085
|
Utils.QBLog('[QBChat]', 'call _connect() in _establishConnection ');
|
|
1086
|
+
if (typeof self.onLogListener === 'function') {
|
|
1087
|
+
Utils.safeCallbackCall(self.onLogListener,
|
|
1088
|
+
'[QBChat]' + ' call _connect() in _establishConnection ');
|
|
1089
|
+
}
|
|
1041
1090
|
if (!self.isConnected && !self._isConnecting && !self._sessionHasExpired) {
|
|
1042
|
-
Utils.QBLog('[QBChat]', '
|
|
1091
|
+
Utils.QBLog('[QBChat]', ' start execute connect() in _establishConnection ');
|
|
1092
|
+
if (typeof self.onLogListener === 'function') {
|
|
1093
|
+
Utils.safeCallbackCall(self.onLogListener,
|
|
1094
|
+
'[QBChat]' + ' with statuses (!self.isConnected && !self._isConnecting && !self._sessionHasExpired): '+' self.isConnected: '+self.isConnected+' self._isConnecting: '+self._isConnecting+' self._sessionHasExpired: '+self._sessionHasExpired);
|
|
1095
|
+
}
|
|
1043
1096
|
self.connect(params);
|
|
1097
|
+
if (typeof self.onLogListener === 'function') {
|
|
1098
|
+
Utils.safeCallbackCall(self.onLogListener,
|
|
1099
|
+
'[QBChat]' + 'call _connect() in _establishConnection is executed');
|
|
1100
|
+
}
|
|
1044
1101
|
} else {
|
|
1045
1102
|
Utils.QBLog('[QBChat]', 'stop timer in _establishConnection ');
|
|
1046
1103
|
clearInterval(self._checkConnectionTimer);
|
|
1047
1104
|
self._checkConnectionTimer = undefined;
|
|
1105
|
+
if (typeof self.onLogListener === 'function') {
|
|
1106
|
+
Utils.safeCallbackCall(self.onLogListener,
|
|
1107
|
+
'[QBChat]' + 'stop timer in _establishConnection ');
|
|
1108
|
+
}
|
|
1048
1109
|
}
|
|
1049
1110
|
};
|
|
1050
1111
|
|
|
@@ -1052,6 +1113,10 @@ ChatProxy.prototype = {
|
|
|
1052
1113
|
|
|
1053
1114
|
self._checkConnectionTimer = setInterval(function () {
|
|
1054
1115
|
Utils.QBLog('[QBChat]', 'self._checkConnectionTimer called with config.chatReconnectionTimeInterval = ' + config.chatReconnectionTimeInterval);
|
|
1116
|
+
if (typeof self.onLogListener === 'function') {
|
|
1117
|
+
Utils.safeCallbackCall(self.onLogListener,
|
|
1118
|
+
'[QBChat]' + 'self._checkConnectionTimer called with config.chatReconnectionTimeInterval = ' + config.chatReconnectionTimeInterval);
|
|
1119
|
+
}
|
|
1055
1120
|
_connect();
|
|
1056
1121
|
}, config.chatReconnectionTimeInterval * 1000);
|
|
1057
1122
|
},
|
package/src/qbConfig.js
CHANGED
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,27 @@ function Connection() {
|
|
|
35
35
|
} else {
|
|
36
36
|
conn.xmlInput = function(data) {
|
|
37
37
|
Utils.QBLog('[QBChat]', 'RECV:', data);
|
|
38
|
+
//
|
|
39
|
+
try {
|
|
40
|
+
let parser = new DOMParser();
|
|
41
|
+
let xmlDoc = parser.parseFromString(data, 'text/xml');
|
|
42
|
+
|
|
43
|
+
let errorElem = xmlDoc.getElementsByTagName('error');
|
|
44
|
+
if (errorElem.length > 0) {
|
|
45
|
+
let conditionElem = errorElem[0].getElementsByTagName('condition');
|
|
46
|
+
if (conditionElem.length > 0) {
|
|
47
|
+
let disconnectCondition = conditionElem[0].textContent;
|
|
48
|
+
console.log('Disconnect condition:', disconnectCondition);
|
|
49
|
+
if (onLogListener && typeof onLogListener === 'function') {
|
|
50
|
+
Utils.safeCallbackCall(onLogListener,
|
|
51
|
+
'[QBChat][QBStrophe]' + 'DISCONNECTED CONDITION: ' + disconnectCondition);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
} catch (e) {
|
|
56
|
+
console.error('Error parsing XML input:', e);
|
|
57
|
+
}
|
|
58
|
+
//
|
|
38
59
|
};
|
|
39
60
|
conn.xmlOutput = function(data) {
|
|
40
61
|
Utils.QBLog('[QBChat]', 'SENT:', data);
|