quickblox 2.13.11 → 2.14.1

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.
@@ -95,6 +95,9 @@ function ChatProxy(service) {
95
95
  this._isLogout = false;
96
96
 
97
97
  this._checkConnectionTimer = undefined;
98
+ // this._checkConnectionPingTimer = undefined; //artan: 13/09/2022 at 16:30
99
+ this._checkExpiredSessionTimer = undefined;
100
+ this._sessionHasExpired = false;
98
101
  this._pings = {};
99
102
  //
100
103
  this.helpers = new Helpers();
@@ -149,6 +152,7 @@ function ChatProxy(service) {
149
152
  * - onLastUserActivityListener (userId, seconds)
150
153
  * - onDisconnectedListener
151
154
  * - onReconnectListener
155
+ * - onSessionExpiredListener
152
156
  */
153
157
 
154
158
  /**
@@ -776,6 +780,7 @@ ChatProxy.prototype = {
776
780
  }
777
781
 
778
782
  if(!self.isConnected && typeof self.onReconnectFailedListener === 'function'){
783
+ // TODO: investigate problem reconnect field
779
784
  Utils.safeCallbackCall(self.onReconnectFailedListener, err);
780
785
  }
781
786
 
@@ -796,7 +801,50 @@ ChatProxy.prototype = {
796
801
  self.connection.XAddTrackedHandler(self._onIQ, null, 'iq');
797
802
  self.connection.XAddTrackedHandler(self._onSystemMessageListener, null, 'message', 'headline');
798
803
  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
+
800
848
  self._postConnectActions(function(roster) {
801
849
  callback(null, roster);
802
850
  }, isInitialConnect);
@@ -917,10 +965,13 @@ ChatProxy.prototype = {
917
965
  _postConnectActions: function(callback, isInitialConnect) {
918
966
  Utils.QBLog('[QBChat]', 'Status.CONNECTED at ' + chatUtils.getLocalTime());
919
967
 
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
+
924
975
  if (config.streamManagement.enable && config.chatProtocol.active === 2) {
925
976
  self.streamManagement.enable(self.connection, null);
926
977
  self.streamManagement.sentMessageCallback = self._sentMessageCallback;
@@ -930,6 +981,7 @@ ChatProxy.prototype = {
930
981
 
931
982
  self.isConnected = true;
932
983
  self._isConnecting = false;
984
+ self._sessionHasExpired = false;
933
985
 
934
986
  self._enableCarbons();
935
987
 
@@ -958,16 +1010,21 @@ ChatProxy.prototype = {
958
1010
  },
959
1011
 
960
1012
  _establishConnection: function(params) {
1013
+ // TODO: must to call if only qbTokenExpirationDate is not expried
961
1014
  var self = this;
962
-
1015
+ Utils.QBLog('[QBChat]', '_establishConnection called');
963
1016
  if (self._isLogout || self._checkConnectionTimer) {
1017
+ Utils.QBLog('[QBChat]', '_establishConnection return');
964
1018
  return;
965
1019
  }
966
1020
 
967
1021
  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 ');
969
1025
  self.connect(params);
970
1026
  } else {
1027
+ Utils.QBLog('[QBChat]', 'stop timer in _establishConnection ');
971
1028
  clearInterval(self._checkConnectionTimer);
972
1029
  self._checkConnectionTimer = undefined;
973
1030
  }
@@ -975,6 +1032,8 @@ ChatProxy.prototype = {
975
1032
 
976
1033
  _connect();
977
1034
 
1035
+
1036
+ // TODO: investigate problem with interval connection
978
1037
  self._checkConnectionTimer = setInterval(function() {
979
1038
  _connect();
980
1039
  }, config.chatReconnectionTimeInterval * 1000);
@@ -988,6 +1047,7 @@ ChatProxy.prototype = {
988
1047
  * @returns {String} messageId - The current message id (was generated by SDK)
989
1048
  * */
990
1049
  send: function(jid_or_user_id, message) {
1050
+ Utils.QBLog('[QBChat]', 'Call send ' + JSON.stringify(message));
991
1051
  var self = this,
992
1052
  builder = Utils.getEnv().browser ? $msg : XMPP.Stanza;
993
1053
 
@@ -1050,6 +1110,7 @@ ChatProxy.prototype = {
1050
1110
  * @returns {String} messageId - The current message id (was generated by SDK)
1051
1111
  * */
1052
1112
  sendSystemMessage: function(jid_or_user_id, message) {
1113
+ Utils.QBLog('[QBChat]', 'Call sendSystemMessage ' + JSON.stringify(message));
1053
1114
  var self = this,
1054
1115
  builder = Utils.getEnv().browser ? $msg : XMPP.Stanza,
1055
1116
  paramsCreateMsg = {
@@ -1098,6 +1159,7 @@ ChatProxy.prototype = {
1098
1159
  * @param {String | Number} jid_or_user_id - Use opponent id or jid for 1 to 1 chat, and room jid for group chat.
1099
1160
  * */
1100
1161
  sendIsTypingStatus: function(jid_or_user_id) {
1162
+ Utils.QBLog('[QBChat]', 'Call sendIsTypingStatus ');
1101
1163
  var self = this,
1102
1164
  stanzaParams = {
1103
1165
  from: self.helpers.getUserCurrentJid(),
@@ -1127,6 +1189,7 @@ ChatProxy.prototype = {
1127
1189
  * @param {String | Number} jid_or_user_id - Use opponent id or jid for 1 to 1 chat, and room jid for group chat.
1128
1190
  * */
1129
1191
  sendIsStopTypingStatus: function(jid_or_user_id) {
1192
+ Utils.QBLog('[QBChat]', 'Call sendIsStopTypingStatus ');
1130
1193
  var self = this,
1131
1194
  stanzaParams = {
1132
1195
  from: self.helpers.getUserCurrentJid(),
@@ -1159,6 +1222,7 @@ ChatProxy.prototype = {
1159
1222
  * @param {Number} params.dialogId - The dialog id
1160
1223
  * */
1161
1224
  sendDeliveredStatus: function(params) {
1225
+ Utils.QBLog('[QBChat]', 'Call sendDeliveredStatus ');
1162
1226
  var self = this,
1163
1227
  stanzaParams = {
1164
1228
  type: 'chat',
@@ -1195,6 +1259,7 @@ ChatProxy.prototype = {
1195
1259
  * @param {Number} params.dialogId - The dialog id
1196
1260
  * */
1197
1261
  sendReadStatus: function(params) {
1262
+ Utils.QBLog('[QBChat]', 'Call sendReadStatus ' + JSON.stringify(params));
1198
1263
  var self = this,
1199
1264
  stanzaParams = {
1200
1265
  type: 'chat',
@@ -1228,6 +1293,7 @@ ChatProxy.prototype = {
1228
1293
  * @param {(Number|String)} jid_or_user_id - The user id or jid, that the last activity we want to know
1229
1294
  * */
1230
1295
  getLastUserActivity: function(jid_or_user_id) {
1296
+ Utils.QBLog('[QBChat]', 'Call getLastUserActivity ');
1231
1297
  var iqParams,
1232
1298
  builder,
1233
1299
  iq;
@@ -1254,7 +1320,47 @@ ChatProxy.prototype = {
1254
1320
  }
1255
1321
  },
1256
1322
 
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
+
1257
1362
  ping: function (jid_or_user_id, callback) {
1363
+ Utils.QBLog('[QBChat]', 'Call ping ');
1258
1364
  var self = this;
1259
1365
  var id = this.helpers.getUniqueId('ping');
1260
1366
  var builder = Utils.getEnv().browser ? $iq : XMPP.Stanza;
@@ -1306,8 +1412,11 @@ ChatProxy.prototype = {
1306
1412
  * @memberof QB.chat
1307
1413
  * */
1308
1414
  disconnect: function() {
1415
+ Utils.QBLog('[QBChat]', 'Call disconnect ');
1309
1416
  clearInterval(this._checkConnectionTimer);
1417
+ clearInterval(this._checkExpiredSessionTimer);
1310
1418
  this._checkConnectionTimer = undefined;
1419
+ this._checkExpiredSessionTimer = undefined;
1311
1420
  this.muc.joinedRooms = {};
1312
1421
  this._isLogout = true;
1313
1422
  this.helpers.setUserCurrentJid('');
package/src/qbConfig.js CHANGED
@@ -12,13 +12,13 @@
12
12
  */
13
13
 
14
14
  var config = {
15
- version: '2.13.11',
16
- buildNumber: '1105',
15
+ version: '2.14.1',
16
+ buildNumber: '1136',
17
17
  creds: {
18
- appId: '',
19
- authKey: '',
20
- authSecret: '',
21
- accountKey: ''
18
+ 'appId': 0,
19
+ 'authKey': '',
20
+ 'authSecret': '',
21
+ 'accountKey': ''
22
22
  },
23
23
  endpoints: {
24
24
  api: 'api.quickblox.com',
@@ -35,6 +35,7 @@ var config = {
35
35
  active: 2
36
36
  },
37
37
  pingTimeout: 30,
38
+ pingLocalhostTimeInterval: 5,
38
39
  chatReconnectionTimeInterval: 5,
39
40
  webrtc: {
40
41
  answerTimeInterval: 60,
@@ -45,7 +46,7 @@ var config = {
45
46
  statsReportTimeInterval: false,
46
47
  iceServers: [
47
48
  {
48
- urls: 'turn:turn.quickblox.com',
49
+ urls: ['turn:turn.quickblox.com', 'stun:turn.quickblox.com'],
49
50
  username: 'quickblox',
50
51
  credential: 'baccb97ba2d92d71e26eb9886da5f1e0'
51
52
  }
@@ -72,10 +73,12 @@ var config = {
72
73
  },
73
74
  timeout: null,
74
75
  debug: {
75
- mode: 0,
76
+ mode: 1,
76
77
  file: null
77
78
  },
78
- addISOTime: false
79
+ addISOTime: false,
80
+ qbTokenExpirationDate: null,
81
+ liveSessionInterval: 120,
79
82
  };
80
83
 
81
84
  config.set = function(options) {
@@ -105,4 +108,23 @@ config.set = function(options) {
105
108
  });
106
109
  };
107
110
 
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
+
108
130
  module.exports = config;
package/src/qbMain.js CHANGED
@@ -28,12 +28,24 @@ QuickBlox.prototype = {
28
28
  _getOS: Utils.getOS.bind(Utils),
29
29
 
30
30
  /**
31
+ * Init QuickBlox SDK with User Account data for start session with token.
31
32
  * @memberof QB
32
- * @param {Number | String} appIdOrToken - Application ID (from your admin panel) or Session Token.
33
- * @param {String | Number} authKeyOrAppId - Authorization key or Application ID. You need to set up Application ID if you use session token as appIdOrToken parameter.
34
- * @param {String} authSecret - Authorization secret key (from your admin panel).
33
+ * @param {Number} appId - Application ID (from your admin panel).
34
+ * @param {String | Number} accountKey - Account key (from your admin panel).
35
35
  * @param {Object} configMap - Settings object for QuickBlox SDK.
36
36
  */
37
+ initWithAppId: function(appId, accountKey, configMap) {
38
+ if (typeof appId !== 'number') {
39
+ throw new Error('Type of appId must be a number');
40
+ }
41
+ if (appId === '' || appId === undefined || appId === null ||
42
+ accountKey === '' || accountKey === undefined || accountKey === null) {
43
+ throw new Error('Cannot init QuickBlox without app credentials (app ID, auth key)');
44
+ } else {
45
+ this.init('', appId, null, accountKey, configMap);
46
+ }
47
+ },
48
+
37
49
  init: function(appIdOrToken, authKeyOrAppId, authSecret, accountKey, configMap) {
38
50
  if (typeof accountKey === 'string' && accountKey.length) {
39
51
  if (configMap && typeof configMap === 'object') {
@@ -148,6 +160,37 @@ QuickBlox.prototype = {
148
160
  this.auth.getSession(callback);
149
161
  },
150
162
 
163
+ /**
164
+ * Set up user session token to current session and return it
165
+ * @memberof QB
166
+ * @param {String} token - a User Session Token
167
+ * @param {getSessionCallback} callback - The getSessionCallback function.
168
+ * @callback getSessionCallback
169
+ * @param {Object} error - The error object
170
+ * @param {Object} session - Contains of session object
171
+ * */
172
+ startSessionWithToken: function(token, callback) {
173
+ if (token === undefined) throw new Error('Cannot start session with undefined token');
174
+ else if (token === '') throw new Error('Cannot start session with empty string token');
175
+ else if (token === null) throw new Error('Cannot start session with null value token');
176
+ else if (typeof callback !== 'function') throw new Error('Cannot start session without callback function');
177
+ else {
178
+ try {
179
+ this.service.setSession({token: token});
180
+ } catch (err) {
181
+ callback(err, null);
182
+ }
183
+ if (typeof callback === 'function') {
184
+ try{
185
+ this.auth.getSession(callback);
186
+ }
187
+ catch(er){
188
+ callback(er, null);
189
+ }
190
+ }
191
+ }
192
+ },
193
+
151
194
  /**
152
195
  * Creat new session. {@link https://quickblox.com/developers/Javascript#Authorization More info}
153
196
  * @memberof QB
package/src/qbProxy.js CHANGED
@@ -140,6 +140,15 @@ ServiceProxy.prototype = {
140
140
  .then(function(response) {
141
141
  qbResponse = response;
142
142
 
143
+ if (qbRequest.method === 'GET' || qbRequest.method === 'POST'){
144
+ // TODO: need to check in [CROS-815]
145
+ var qbTokenExpirationDate = qbResponse.headers.get('qb-token-expirationdate');
146
+ var headerHasToken = !(qbTokenExpirationDate === null ||
147
+ typeof qbTokenExpirationDate === 'undefined');
148
+ qbTokenExpirationDate = (headerHasToken) ? qbTokenExpirationDate : new Date();
149
+ self.qbInst.config.updateSessionExpirationDate(qbTokenExpirationDate, headerHasToken);
150
+ }
151
+
143
152
  if (qbDataType === 'text') {
144
153
  return response.text();
145
154
  } else {
@@ -155,6 +164,8 @@ ServiceProxy.prototype = {
155
164
  }).then(function(body) {
156
165
  _requestCallback(null, qbResponse, body);
157
166
  }, function(error) {
167
+ // TODO: review in [CROS-815]
168
+ console.log('Error: ', error);
158
169
  _requestCallback(error);
159
170
  });
160
171
 
package/src/qbUtils.js CHANGED
@@ -147,6 +147,10 @@ var Utils = {
147
147
  '000000'.substr(0, 6 - increment.length) + increment;
148
148
  },
149
149
 
150
+ getCurrentTime: function() {
151
+ return ((new Date()).toTimeString().split(' ')[0]);
152
+ },
153
+
150
154
  injectISOTimes: function(data) {
151
155
  if (data.created_at) {
152
156
  if (typeof data.created_at === 'number') data.iso_created_at = new Date(data.created_at * 1000).toISOString();