Skip to content

Commit 732b5ce

Browse files
version 2.14.0
1 parent f211179 commit 732b5ce

File tree

8 files changed

+420
-42
lines changed

8 files changed

+420
-42
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Check out our [API Reference](https://quickblox.github.io/quickblox-javascript-s
1616
## Dependencies for browser
1717

1818
```html
19-
<script src="https://unpkg.com/quickblox@2.13.11/quickblox.min.js"></script>
19+
<script src="https://unpkg.com/quickblox@2.14.0/quickblox.min.js"></script>
2020
```
2121

2222
## Bower and RequireJS

quickblox.js

Lines changed: 209 additions & 20 deletions
Large diffs are not rendered by default.

quickblox.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/modules/chat/qbChat.js

Lines changed: 116 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ function ChatProxy(service) {
9595
this._isLogout = false;
9696

9797
this._checkConnectionTimer = undefined;
98+
// this._checkConnectionPingTimer = undefined; //artan: 13/09/2022 at 16:30
99+
this._checkExpiredSessionTimer = undefined;
100+
this._sessionHasExpired = false;
98101
this._pings = {};
99102
//
100103
this.helpers = new Helpers();
@@ -149,6 +152,7 @@ function ChatProxy(service) {
149152
* - onLastUserActivityListener (userId, seconds)
150153
* - onDisconnectedListener
151154
* - onReconnectListener
155+
* - onSessionExpiredListener
152156
*/
153157

154158
/**
@@ -776,6 +780,7 @@ ChatProxy.prototype = {
776780
}
777781

778782
if(!self.isConnected && typeof self.onReconnectFailedListener === 'function'){
783+
// TODO: investigate problem reconnect field
779784
Utils.safeCallbackCall(self.onReconnectFailedListener, err);
780785
}
781786

@@ -796,7 +801,50 @@ ChatProxy.prototype = {
796801
self.connection.XAddTrackedHandler(self._onIQ, null, 'iq');
797802
self.connection.XAddTrackedHandler(self._onSystemMessageListener, null, 'message', 'headline');
798803
self.connection.XAddTrackedHandler(self._onMessageErrorListener, null, 'message', 'error');
799-
804+
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+
// }
825+
826+
if (typeof self.onSessionExpiredListener === 'function') {
827+
var noExpiredSessionTimerId = typeof self._checkExpiredSessionTimer === 'undefined';
828+
if (noExpiredSessionTimerId) {
829+
Utils.QBLog('[QBChat]', 'Init timer for check session expired at ', ((new Date()).toTimeString().split(' ')[0]));
830+
self._checkExpiredSessionTimer = setInterval(function() {
831+
var timeNow = new Date();
832+
if (typeof config.qbTokenExpirationDate !== 'undefined') {
833+
var timeLag = Math.round((timeNow.getTime() - config.qbTokenExpirationDate.getTime()) / (1000 * 60));
834+
//artan 25-08-2022
835+
// TODO: need to delete in task [CROS-815]
836+
console.log('timeLag: ', timeLag);
837+
if (timeLag >= 0) {
838+
self._sessionHasExpired = true;
839+
Utils.safeCallbackCall(self.onSessionExpiredListener, null);
840+
}
841+
}
842+
// TODO: in task [CROS-815], may by need to change 5 * 1000 to config.liveSessionInterval * 1000
843+
}, 5 * 1000);
844+
845+
}
846+
}
847+
800848
self._postConnectActions(function(roster) {
801849
callback(null, roster);
802850
}, isInitialConnect);
@@ -917,10 +965,13 @@ ChatProxy.prototype = {
917965
_postConnectActions: function(callback, isInitialConnect) {
918966
Utils.QBLog('[QBChat]', 'Status.CONNECTED at ' + chatUtils.getLocalTime());
919967

920-
var self = this,
921-
xmppClient = Utils.getEnv().browser ? self.connection : self.Client,
922-
presence = Utils.getEnv().browser ? $pres() : chatUtils.createStanza(XMPP.Stanza, null, 'presence');
923-
968+
var self = this;
969+
var isBrowser = Utils.getEnv().browser;
970+
var xmppClient = isBrowser ? self.connection : self.Client;
971+
var presence = isBrowser ?
972+
$pres() :
973+
chatUtils.createStanza(XMPP.Stanza, null, 'presence');
974+
924975
if (config.streamManagement.enable && config.chatProtocol.active === 2) {
925976
self.streamManagement.enable(self.connection, null);
926977
self.streamManagement.sentMessageCallback = self._sentMessageCallback;
@@ -930,6 +981,7 @@ ChatProxy.prototype = {
930981

931982
self.isConnected = true;
932983
self._isConnecting = false;
984+
self._sessionHasExpired = false;
933985

934986
self._enableCarbons();
935987

@@ -958,23 +1010,30 @@ ChatProxy.prototype = {
9581010
},
9591011

9601012
_establishConnection: function(params) {
1013+
// TODO: must to call if only qbTokenExpirationDate is not expried
9611014
var self = this;
962-
1015+
Utils.QBLog('[QBChat]', '_establishConnection called');
9631016
if (self._isLogout || self._checkConnectionTimer) {
1017+
Utils.QBLog('[QBChat]', '_establishConnection return');
9641018
return;
9651019
}
9661020

9671021
var _connect = function() {
968-
if (!self.isConnected && !self._isConnecting) {
1022+
Utils.QBLog('[QBChat]', 'call _connect() in _establishConnection ');
1023+
if (!self.isConnected && !self._isConnecting && !self._sessionHasExpired) {
1024+
Utils.QBLog('[QBChat]', 'call connect() again in _establishConnection ');
9691025
self.connect(params);
9701026
} else {
1027+
Utils.QBLog('[QBChat]', 'stop timer in _establishConnection ');
9711028
clearInterval(self._checkConnectionTimer);
9721029
self._checkConnectionTimer = undefined;
9731030
}
9741031
};
9751032

9761033
_connect();
9771034

1035+
1036+
// TODO: investigate problem with interval connection
9781037
self._checkConnectionTimer = setInterval(function() {
9791038
_connect();
9801039
}, config.chatReconnectionTimeInterval * 1000);
@@ -988,6 +1047,7 @@ ChatProxy.prototype = {
9881047
* @returns {String} messageId - The current message id (was generated by SDK)
9891048
* */
9901049
send: function(jid_or_user_id, message) {
1050+
Utils.QBLog('[QBChat]', 'Call send ' + JSON.stringify(message));
9911051
var self = this,
9921052
builder = Utils.getEnv().browser ? $msg : XMPP.Stanza;
9931053

@@ -1050,6 +1110,7 @@ ChatProxy.prototype = {
10501110
* @returns {String} messageId - The current message id (was generated by SDK)
10511111
* */
10521112
sendSystemMessage: function(jid_or_user_id, message) {
1113+
Utils.QBLog('[QBChat]', 'Call sendSystemMessage ' + JSON.stringify(message));
10531114
var self = this,
10541115
builder = Utils.getEnv().browser ? $msg : XMPP.Stanza,
10551116
paramsCreateMsg = {
@@ -1098,6 +1159,7 @@ ChatProxy.prototype = {
10981159
* @param {String | Number} jid_or_user_id - Use opponent id or jid for 1 to 1 chat, and room jid for group chat.
10991160
* */
11001161
sendIsTypingStatus: function(jid_or_user_id) {
1162+
Utils.QBLog('[QBChat]', 'Call sendIsTypingStatus ');
11011163
var self = this,
11021164
stanzaParams = {
11031165
from: self.helpers.getUserCurrentJid(),
@@ -1127,6 +1189,7 @@ ChatProxy.prototype = {
11271189
* @param {String | Number} jid_or_user_id - Use opponent id or jid for 1 to 1 chat, and room jid for group chat.
11281190
* */
11291191
sendIsStopTypingStatus: function(jid_or_user_id) {
1192+
Utils.QBLog('[QBChat]', 'Call sendIsStopTypingStatus ');
11301193
var self = this,
11311194
stanzaParams = {
11321195
from: self.helpers.getUserCurrentJid(),
@@ -1159,6 +1222,7 @@ ChatProxy.prototype = {
11591222
* @param {Number} params.dialogId - The dialog id
11601223
* */
11611224
sendDeliveredStatus: function(params) {
1225+
Utils.QBLog('[QBChat]', 'Call sendDeliveredStatus ');
11621226
var self = this,
11631227
stanzaParams = {
11641228
type: 'chat',
@@ -1195,6 +1259,7 @@ ChatProxy.prototype = {
11951259
* @param {Number} params.dialogId - The dialog id
11961260
* */
11971261
sendReadStatus: function(params) {
1262+
Utils.QBLog('[QBChat]', 'Call sendReadStatus ' + JSON.stringify(params));
11981263
var self = this,
11991264
stanzaParams = {
12001265
type: 'chat',
@@ -1228,6 +1293,7 @@ ChatProxy.prototype = {
12281293
* @param {(Number|String)} jid_or_user_id - The user id or jid, that the last activity we want to know
12291294
* */
12301295
getLastUserActivity: function(jid_or_user_id) {
1296+
Utils.QBLog('[QBChat]', 'Call getLastUserActivity ');
12311297
var iqParams,
12321298
builder,
12331299
iq;
@@ -1254,7 +1320,47 @@ ChatProxy.prototype = {
12541320
}
12551321
},
12561322

1323+
_ping: function(jid_or_user_id, callback){
1324+
var self = this;
1325+
var id = this.helpers.getUniqueId('ping');
1326+
var builder = Utils.getEnv().browser ? $iq : XMPP.Stanza;
1327+
var to;
1328+
var _callback;
1329+
var stanza;
1330+
1331+
//to = config.endpoints.chat;
1332+
to = 'http://localhost';
1333+
_callback = callback;
1334+
1335+
1336+
var iqParams = {
1337+
from: this.helpers.getUserCurrentJid(),
1338+
id: id,
1339+
to: to,
1340+
type: 'get'
1341+
};
1342+
stanza = chatUtils.createStanza(builder, iqParams, 'iq');
1343+
stanza.c('ping', { xmlns: "urn:xmpp:ping" });
1344+
1345+
var noAnswer = function () {
1346+
_callback('No answer');
1347+
self._pings[id] = undefined;
1348+
delete self._pings[id];
1349+
};
1350+
if (Utils.getEnv().browser) {
1351+
this.connection.send(stanza);
1352+
} else {
1353+
this.Client.send(stanza);
1354+
}
1355+
this._pings[id] = {
1356+
callback: _callback,
1357+
interval: setTimeout(noAnswer, config.pingTimeout * 1000)
1358+
};
1359+
return id;
1360+
},
1361+
12571362
ping: function (jid_or_user_id, callback) {
1363+
Utils.QBLog('[QBChat]', 'Call ping ');
12581364
var self = this;
12591365
var id = this.helpers.getUniqueId('ping');
12601366
var builder = Utils.getEnv().browser ? $iq : XMPP.Stanza;
@@ -1306,8 +1412,11 @@ ChatProxy.prototype = {
13061412
* @memberof QB.chat
13071413
* */
13081414
disconnect: function() {
1415+
Utils.QBLog('[QBChat]', 'Call disconnect ');
13091416
clearInterval(this._checkConnectionTimer);
1417+
clearInterval(this._checkExpiredSessionTimer);
13101418
this._checkConnectionTimer = undefined;
1419+
this._checkExpiredSessionTimer = undefined;
13111420
this.muc.joinedRooms = {};
13121421
this._isLogout = true;
13131422
this.helpers.setUserCurrentJid('');

src/qbConfig.js

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
*/
1313

1414
var config = {
15-
version: '2.13.11',
16-
buildNumber: '1105',
15+
version: '2.14.0',
16+
buildNumber: '1135',
1717
creds: {
18-
appId: '',
19-
authKey: '',
20-
authSecret: '',
21-
accountKey: ''
18+
'appId': 0,
19+
'authKey': '',
20+
'authSecret': '',
21+
'accountKey': ''
2222
},
2323
endpoints: {
24-
api: 'api.quickblox.com',
24+
api: 'apistage6.quickblox.com/',
2525
chat: 'chat.quickblox.com',
2626
muc: 'muc.chat.quickblox.com'
2727
},
@@ -35,6 +35,7 @@ var config = {
3535
active: 2
3636
},
3737
pingTimeout: 30,
38+
pingLocalhostTimeInterval: 5,
3839
chatReconnectionTimeInterval: 5,
3940
webrtc: {
4041
answerTimeInterval: 60,
@@ -45,7 +46,7 @@ var config = {
4546
statsReportTimeInterval: false,
4647
iceServers: [
4748
{
48-
urls: 'turn:turn.quickblox.com',
49+
urls: ['turn:turn.quickblox.com', 'stun:turn.quickblox.com'],
4950
username: 'quickblox',
5051
credential: 'baccb97ba2d92d71e26eb9886da5f1e0'
5152
}
@@ -72,10 +73,12 @@ var config = {
7273
},
7374
timeout: null,
7475
debug: {
75-
mode: 0,
76+
mode: 1,
7677
file: null
7778
},
78-
addISOTime: false
79+
addISOTime: false,
80+
qbTokenExpirationDate: null,
81+
liveSessionInterval: 120,
7982
};
8083

8184
config.set = function(options) {
@@ -105,4 +108,23 @@ config.set = function(options) {
105108
});
106109
};
107110

111+
/*
112+
* 17.08.22 artan: waiting for backend fix, look at tasks:
113+
* [CROS-815] - Update sessionExpirationDate on each request
114+
* [SR-1322] - Set param Access-Control-Expose-Headerson server side
115+
*/
116+
config.updateSessionExpirationDate = function (tokenExpirationDate, headerHasToken = false) {
117+
var connectionTimeLag = 1; // minute
118+
var newDate = new Date(tokenExpirationDate);
119+
newDate.setMinutes ( newDate.getMinutes() - connectionTimeLag);
120+
// TODO: need to check in [CROS-815]
121+
if (!headerHasToken) {
122+
console.log('in date: ', newDate);
123+
newDate.setMinutes ( newDate.getMinutes() + config.liveSessionInterval );
124+
console.log('out date: ', newDate);
125+
}
126+
config.qbTokenExpirationDate = newDate;
127+
console.log('updateSessionExpirationDate ... Set value: ', tokenExpirationDate);
128+
};
129+
108130
module.exports = config;

0 commit comments

Comments
 (0)