@@ -45463,7 +45463,7 @@ function ChatProxy(service) {
4546345463 */
4546445464 if (Utils.getEnv().browser) {
4546545465 // strophe js
45466- self.connection = Connection();
45466+ self.connection = Connection(self.onLogListener );
4546745467
4546845468 /** Add extension methods to track handlers for removal on reconnect */
4546945469 self.connection.XHandlerReferences = [];
@@ -45579,6 +45579,7 @@ function ChatProxy(service) {
4557945579 * - onDisconnectedListener
4558045580 * - onReconnectListener
4558145581 * - onSessionExpiredListener
45582+ * - onLogListener
4558245583 */
4558345584
4558445585 /**
@@ -45712,6 +45713,12 @@ function ChatProxy(service) {
4571245713 * @memberOf QB.chat
4571345714 **/
4571445715
45716+ /**
45717+ * Run after disconnect from chat to log result
45718+ * @function onLogListener
45719+ * @memberOf QB.chat
45720+ **/
45721+
4571545722
4571645723 this._onMessage = function (stanza) {
4571745724 var from = chatUtils.getAttr(stanza, 'from'),
@@ -46168,7 +46175,7 @@ ChatProxy.prototype = {
4616846175 /** Connect for browser env. */
4616946176 if (Utils.getEnv().browser) {
4617046177 Utils.QBLog('[QBChat]', '!!---Browser env - connected--!!');
46171-
46178+ let disconnectCondition = '';
4617246179 self.connection.connect(userJid, params.password, function (status) {
4617346180 Utils.QBLog('[QBChat]', 'self.connection.connect called with status ' + status);
4617446181 switch (status) {
@@ -46297,7 +46304,14 @@ ChatProxy.prototype = {
4629746304 break;
4629846305 case Strophe.Status.DISCONNECTED:
4629946306 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+ }
4630146315 // fire 'onDisconnectedListener' only once
4630246316 if (self.isConnected && typeof self.onDisconnectedListener === 'function') {
4630346317 Utils.safeCallbackCall(self.onDisconnectedListener);
@@ -46316,6 +46330,28 @@ ChatProxy.prototype = {
4631646330 break;
4631746331 }
4631846332 });
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+ };
4631946355 }
4632046356
4632146357 /** connect for node */
@@ -46455,27 +46491,56 @@ ChatProxy.prototype = {
4645546491 _establishConnection: function (params) {
4645646492 var self = this;
4645746493 Utils.QBLog('[QBChat]', '_establishConnection called');
46494+ if (typeof self.onLogListener === 'function') {
46495+ Utils.safeCallbackCall(self.onLogListener,
46496+ '[QBChat]' + '_establishConnection called');
46497+ }
4645846498 if (self._isLogout || self._checkConnectionTimer) {
4645946499 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+ }
4646046505 return;
4646146506 }
4646246507
4646346508 var _connect = function () {
4646446509 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+ }
4646546514 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+ }
4646746520 self.connect(params);
46521+ if (typeof self.onLogListener === 'function') {
46522+ Utils.safeCallbackCall(self.onLogListener,
46523+ '[QBChat]' + 'call _connect() in _establishConnection is executed');
46524+ }
4646846525 } else {
4646946526 Utils.QBLog('[QBChat]', 'stop timer in _establishConnection ');
4647046527 clearInterval(self._checkConnectionTimer);
4647146528 self._checkConnectionTimer = undefined;
46529+ if (typeof self.onLogListener === 'function') {
46530+ Utils.safeCallbackCall(self.onLogListener,
46531+ '[QBChat]' + 'stop timer in _establishConnection ');
46532+ }
4647246533 }
4647346534 };
4647446535
4647546536 _connect();
4647646537
4647746538 self._checkConnectionTimer = setInterval(function () {
4647846539 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+ }
4647946544 _connect();
4648046545 }, config.chatReconnectionTimeInterval * 1000);
4648146546 },
@@ -53809,8 +53874,8 @@ module.exports = StreamManagement;
5380953874 */
5381053875
5381153876var config = {
53812- version: '2.17.1 ',
53813- buildNumber: '1161 ',
53877+ version: '2.18.0 ',
53878+ buildNumber: '1162 ',
5381453879 creds: {
5381553880 'appId': 0,
5381653881 'authKey': '',
@@ -54252,7 +54317,7 @@ ServiceProxy.prototype = {
5425254317 handleResponse: function(error, response, next, retry) {
5425354318 // can add middleware here...
5425454319 if (error) {
54255- const errorMsg = JSON.stringify(error.message).toLowerCase();
54320+ const errorMsg = error.message ? JSON.stringify(error.message).toLowerCase() : '' ;
5425654321 if (typeof config.on.sessionExpired === 'function' &&
5425754322 error.code === 401 &&
5425854323 errorMsg.indexOf('session does not exist') > -1) {
@@ -54522,7 +54587,7 @@ var config = require('./qbConfig');
5452254587var chatPRTCL = config.chatProtocol;
5452354588var Utils = require('./qbUtils');
5452454589
54525- function Connection() {
54590+ function Connection(onLogListener ) {
5452654591 var protocol = chatPRTCL.active === 1 ? chatPRTCL.bosh : chatPRTCL.websocket;
5452754592 var conn = new Strophe.Connection(protocol);
5452854593
@@ -54544,6 +54609,27 @@ function Connection() {
5454454609 } else {
5454554610 conn.xmlInput = function(data) {
5454654611 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+ //
5454754633 };
5454854634 conn.xmlOutput = function(data) {
5454954635 Utils.QBLog('[QBChat]', 'SENT:', data);
0 commit comments