@@ -45463,7 +45463,7 @@ function ChatProxy(service) {
45463
45463
*/
45464
45464
if (Utils.getEnv().browser) {
45465
45465
// strophe js
45466
- self.connection = Connection();
45466
+ self.connection = Connection(self.onLogListener );
45467
45467
45468
45468
/** Add extension methods to track handlers for removal on reconnect */
45469
45469
self.connection.XHandlerReferences = [];
@@ -45579,6 +45579,7 @@ function ChatProxy(service) {
45579
45579
* - onDisconnectedListener
45580
45580
* - onReconnectListener
45581
45581
* - onSessionExpiredListener
45582
+ * - onLogListener
45582
45583
*/
45583
45584
45584
45585
/**
@@ -45712,6 +45713,12 @@ function ChatProxy(service) {
45712
45713
* @memberOf QB.chat
45713
45714
**/
45714
45715
45716
+ /**
45717
+ * Run after disconnect from chat to log result
45718
+ * @function onLogListener
45719
+ * @memberOf QB.chat
45720
+ **/
45721
+
45715
45722
45716
45723
this._onMessage = function (stanza) {
45717
45724
var from = chatUtils.getAttr(stanza, 'from'),
@@ -46168,7 +46175,7 @@ ChatProxy.prototype = {
46168
46175
/** Connect for browser env. */
46169
46176
if (Utils.getEnv().browser) {
46170
46177
Utils.QBLog('[QBChat]', '!!---Browser env - connected--!!');
46171
-
46178
+ let disconnectCondition = '';
46172
46179
self.connection.connect(userJid, params.password, function (status) {
46173
46180
Utils.QBLog('[QBChat]', 'self.connection.connect called with status ' + status);
46174
46181
switch (status) {
@@ -46297,7 +46304,14 @@ ChatProxy.prototype = {
46297
46304
break;
46298
46305
case Strophe.Status.DISCONNECTED:
46299
46306
Utils.QBLog('[QBChat]', 'Status.DISCONNECTED at ' + chatUtils.getLocalTime());
46300
-
46307
+ //
46308
+ Utils.QBLog('[QBChat]', 'DISCONNECTED CONDITION: ' + disconnectCondition);
46309
+ //
46310
+ if (typeof self.onLogListener === 'function') {
46311
+ Utils.safeCallbackCall(self.onLogListener,
46312
+ '[QBChat]' + ' Status.DISCONNECTED at ' +
46313
+ chatUtils.getLocalTime()+ ' DISCONNECTED CONDITION: ' + disconnectCondition);
46314
+ }
46301
46315
// fire 'onDisconnectedListener' only once
46302
46316
if (self.isConnected && typeof self.onDisconnectedListener === 'function') {
46303
46317
Utils.safeCallbackCall(self.onDisconnectedListener);
@@ -46316,6 +46330,28 @@ ChatProxy.prototype = {
46316
46330
break;
46317
46331
}
46318
46332
});
46333
+ // connection error handler
46334
+ self.connection.xmlInput = function (data) {
46335
+ try {
46336
+ let parser = new DOMParser();
46337
+ let xmlDoc = parser.parseFromString(data, 'text/xml');
46338
+
46339
+ let errorElem = xmlDoc.getElementsByTagName('error');
46340
+ if (errorElem.length > 0) {
46341
+ let conditionElem = errorElem[0].getElementsByTagName('condition');
46342
+ if (conditionElem.length > 0) {
46343
+ disconnectCondition = conditionElem[0].textContent;
46344
+ console.log('Disconnect condition:', disconnectCondition);
46345
+ if (typeof self.onLogListener === 'function') {
46346
+ Utils.safeCallbackCall(self.onLogListener,
46347
+ '[QBChat]' + ' DISCONNECTED CONDITION: ' + disconnectCondition);
46348
+ }
46349
+ }
46350
+ }
46351
+ } catch (e) {
46352
+ console.error('Error parsing XML input:', e);
46353
+ }
46354
+ };
46319
46355
}
46320
46356
46321
46357
/** connect for node */
@@ -46455,27 +46491,56 @@ ChatProxy.prototype = {
46455
46491
_establishConnection: function (params) {
46456
46492
var self = this;
46457
46493
Utils.QBLog('[QBChat]', '_establishConnection called');
46494
+ if (typeof self.onLogListener === 'function') {
46495
+ Utils.safeCallbackCall(self.onLogListener,
46496
+ '[QBChat]' + '_establishConnection called');
46497
+ }
46458
46498
if (self._isLogout || self._checkConnectionTimer) {
46459
46499
Utils.QBLog('[QBChat]', '_establishConnection return');
46500
+ if (typeof self.onLogListener === 'function') {
46501
+ Utils.safeCallbackCall(self.onLogListener,
46502
+ '[QBChat]' + ' _establishConnection return with self._isLogout: '+
46503
+ self._isLogout+' and self._checkConnectionTimer ' +self._checkConnectionTimer?'set up':'undefined');
46504
+ }
46460
46505
return;
46461
46506
}
46462
46507
46463
46508
var _connect = function () {
46464
46509
Utils.QBLog('[QBChat]', 'call _connect() in _establishConnection ');
46510
+ if (typeof self.onLogListener === 'function') {
46511
+ Utils.safeCallbackCall(self.onLogListener,
46512
+ '[QBChat]' + ' call _connect() in _establishConnection ');
46513
+ }
46465
46514
if (!self.isConnected && !self._isConnecting && !self._sessionHasExpired) {
46466
- Utils.QBLog('[QBChat]', 'call connect() again in _establishConnection ');
46515
+ Utils.QBLog('[QBChat]', ' start execute connect() in _establishConnection ');
46516
+ if (typeof self.onLogListener === 'function') {
46517
+ Utils.safeCallbackCall(self.onLogListener,
46518
+ '[QBChat]' + ' with statuses (!self.isConnected && !self._isConnecting && !self._sessionHasExpired): '+' self.isConnected: '+self.isConnected+' self._isConnecting: '+self._isConnecting+' self._sessionHasExpired: '+self._sessionHasExpired);
46519
+ }
46467
46520
self.connect(params);
46521
+ if (typeof self.onLogListener === 'function') {
46522
+ Utils.safeCallbackCall(self.onLogListener,
46523
+ '[QBChat]' + 'call _connect() in _establishConnection is executed');
46524
+ }
46468
46525
} else {
46469
46526
Utils.QBLog('[QBChat]', 'stop timer in _establishConnection ');
46470
46527
clearInterval(self._checkConnectionTimer);
46471
46528
self._checkConnectionTimer = undefined;
46529
+ if (typeof self.onLogListener === 'function') {
46530
+ Utils.safeCallbackCall(self.onLogListener,
46531
+ '[QBChat]' + 'stop timer in _establishConnection ');
46532
+ }
46472
46533
}
46473
46534
};
46474
46535
46475
46536
_connect();
46476
46537
46477
46538
self._checkConnectionTimer = setInterval(function () {
46478
46539
Utils.QBLog('[QBChat]', 'self._checkConnectionTimer called with config.chatReconnectionTimeInterval = ' + config.chatReconnectionTimeInterval);
46540
+ if (typeof self.onLogListener === 'function') {
46541
+ Utils.safeCallbackCall(self.onLogListener,
46542
+ '[QBChat]' + 'self._checkConnectionTimer called with config.chatReconnectionTimeInterval = ' + config.chatReconnectionTimeInterval);
46543
+ }
46479
46544
_connect();
46480
46545
}, config.chatReconnectionTimeInterval * 1000);
46481
46546
},
@@ -53809,8 +53874,8 @@ module.exports = StreamManagement;
53809
53874
*/
53810
53875
53811
53876
var config = {
53812
- version: '2.17.1 ',
53813
- buildNumber: '1161 ',
53877
+ version: '2.18.0 ',
53878
+ buildNumber: '1162 ',
53814
53879
creds: {
53815
53880
'appId': 0,
53816
53881
'authKey': '',
@@ -54252,7 +54317,7 @@ ServiceProxy.prototype = {
54252
54317
handleResponse: function(error, response, next, retry) {
54253
54318
// can add middleware here...
54254
54319
if (error) {
54255
- const errorMsg = JSON.stringify(error.message).toLowerCase();
54320
+ const errorMsg = error.message ? JSON.stringify(error.message).toLowerCase() : '' ;
54256
54321
if (typeof config.on.sessionExpired === 'function' &&
54257
54322
error.code === 401 &&
54258
54323
errorMsg.indexOf('session does not exist') > -1) {
@@ -54522,7 +54587,7 @@ var config = require('./qbConfig');
54522
54587
var chatPRTCL = config.chatProtocol;
54523
54588
var Utils = require('./qbUtils');
54524
54589
54525
- function Connection() {
54590
+ function Connection(onLogListener ) {
54526
54591
var protocol = chatPRTCL.active === 1 ? chatPRTCL.bosh : chatPRTCL.websocket;
54527
54592
var conn = new Strophe.Connection(protocol);
54528
54593
@@ -54544,6 +54609,27 @@ function Connection() {
54544
54609
} else {
54545
54610
conn.xmlInput = function(data) {
54546
54611
Utils.QBLog('[QBChat]', 'RECV:', data);
54612
+ //
54613
+ try {
54614
+ let parser = new DOMParser();
54615
+ let xmlDoc = parser.parseFromString(data, 'text/xml');
54616
+
54617
+ let errorElem = xmlDoc.getElementsByTagName('error');
54618
+ if (errorElem.length > 0) {
54619
+ let conditionElem = errorElem[0].getElementsByTagName('condition');
54620
+ if (conditionElem.length > 0) {
54621
+ let disconnectCondition = conditionElem[0].textContent;
54622
+ console.log('Disconnect condition:', disconnectCondition);
54623
+ if (onLogListener && typeof onLogListener === 'function') {
54624
+ Utils.safeCallbackCall(onLogListener,
54625
+ '[QBChat][QBStrophe]' + 'DISCONNECTED CONDITION: ' + disconnectCondition);
54626
+ }
54627
+ }
54628
+ }
54629
+ } catch (e) {
54630
+ console.error('Error parsing XML input:', e);
54631
+ }
54632
+ //
54547
54633
};
54548
54634
conn.xmlOutput = function(data) {
54549
54635
Utils.QBLog('[QBChat]', 'SENT:', data);
0 commit comments