quickblox 2.13.10 → 2.14.0

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
  /**
@@ -768,7 +772,7 @@ ChatProxy.prototype = {
768
772
  case Strophe.Status.AUTHFAIL:
769
773
  self.isConnected = false;
770
774
  self._isConnecting = false;
771
-
775
+
772
776
  err = Utils.getError(401, 'Status.AUTHFAIL - The authentication attempt failed', 'QBChat');
773
777
 
774
778
  if (isInitialConnect) {
@@ -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(),
@@ -1112,10 +1174,12 @@ ChatProxy.prototype = {
1112
1174
  xmlns: chatUtils.MARKERS.STATES
1113
1175
  });
1114
1176
 
1115
- if(Utils.getEnv().browser){
1116
- self.connection.send(stanza);
1117
- } else {
1118
- self.Client.send(stanza);
1177
+ if (self.connection.connected) {
1178
+ if(Utils.getEnv().browser){
1179
+ self.connection.send(stanza);
1180
+ } else {
1181
+ self.Client.send(stanza);
1182
+ }
1119
1183
  }
1120
1184
  },
1121
1185
 
@@ -1125,6 +1189,7 @@ ChatProxy.prototype = {
1125
1189
  * @param {String | Number} jid_or_user_id - Use opponent id or jid for 1 to 1 chat, and room jid for group chat.
1126
1190
  * */
1127
1191
  sendIsStopTypingStatus: function(jid_or_user_id) {
1192
+ Utils.QBLog('[QBChat]', 'Call sendIsStopTypingStatus ');
1128
1193
  var self = this,
1129
1194
  stanzaParams = {
1130
1195
  from: self.helpers.getUserCurrentJid(),
@@ -1139,10 +1204,12 @@ ChatProxy.prototype = {
1139
1204
  xmlns: chatUtils.MARKERS.STATES
1140
1205
  });
1141
1206
 
1142
- if(Utils.getEnv().browser){
1143
- self.connection.send(stanza);
1144
- } else {
1145
- self.Client.send(stanza);
1207
+ if (self.connection.connected) {
1208
+ if(Utils.getEnv().browser){
1209
+ self.connection.send(stanza);
1210
+ } else {
1211
+ self.Client.send(stanza);
1212
+ }
1146
1213
  }
1147
1214
  },
1148
1215
 
@@ -1155,6 +1222,7 @@ ChatProxy.prototype = {
1155
1222
  * @param {Number} params.dialogId - The dialog id
1156
1223
  * */
1157
1224
  sendDeliveredStatus: function(params) {
1225
+ Utils.QBLog('[QBChat]', 'Call sendDeliveredStatus ');
1158
1226
  var self = this,
1159
1227
  stanzaParams = {
1160
1228
  type: 'chat',
@@ -1191,6 +1259,7 @@ ChatProxy.prototype = {
1191
1259
  * @param {Number} params.dialogId - The dialog id
1192
1260
  * */
1193
1261
  sendReadStatus: function(params) {
1262
+ Utils.QBLog('[QBChat]', 'Call sendReadStatus ' + JSON.stringify(params));
1194
1263
  var self = this,
1195
1264
  stanzaParams = {
1196
1265
  type: 'chat',
@@ -1224,6 +1293,7 @@ ChatProxy.prototype = {
1224
1293
  * @param {(Number|String)} jid_or_user_id - The user id or jid, that the last activity we want to know
1225
1294
  * */
1226
1295
  getLastUserActivity: function(jid_or_user_id) {
1296
+ Utils.QBLog('[QBChat]', 'Call getLastUserActivity ');
1227
1297
  var iqParams,
1228
1298
  builder,
1229
1299
  iq;
@@ -1250,7 +1320,47 @@ ChatProxy.prototype = {
1250
1320
  }
1251
1321
  },
1252
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
+
1253
1362
  ping: function (jid_or_user_id, callback) {
1363
+ Utils.QBLog('[QBChat]', 'Call ping ');
1254
1364
  var self = this;
1255
1365
  var id = this.helpers.getUniqueId('ping');
1256
1366
  var builder = Utils.getEnv().browser ? $iq : XMPP.Stanza;
@@ -1302,8 +1412,11 @@ ChatProxy.prototype = {
1302
1412
  * @memberof QB.chat
1303
1413
  * */
1304
1414
  disconnect: function() {
1415
+ Utils.QBLog('[QBChat]', 'Call disconnect ');
1305
1416
  clearInterval(this._checkConnectionTimer);
1417
+ clearInterval(this._checkExpiredSessionTimer);
1306
1418
  this._checkConnectionTimer = undefined;
1419
+ this._checkExpiredSessionTimer = undefined;
1307
1420
  this.muc.joinedRooms = {};
1308
1421
  this._isLogout = true;
1309
1422
  this.helpers.setUserCurrentJid('');
@@ -43,6 +43,8 @@ function StreamManagement(options) {
43
43
  // The client send stanza counter.
44
44
  this._clientSentStanzasCounter = null;
45
45
 
46
+ this._intervalId = null;
47
+
46
48
  this._timeInterval = 2000;
47
49
 
48
50
  this.sentMessageCallback = null;
@@ -127,7 +129,12 @@ StreamManagement.prototype._addEnableHandlers = function () {
127
129
  if(tagName === 'enabled'){
128
130
  self._isStreamManagementEnabled = true;
129
131
 
130
- setInterval(self._timeoutCallback.bind(self), self._timeInterval);
132
+ return true;
133
+ }
134
+
135
+ if (self._isStreamManagementEnabled && tagName === 'message') {
136
+ clearInterval(self._intervalId);
137
+ self._intervalId = setInterval(self._timeoutCallback.bind(self), self._timeInterval);
131
138
 
132
139
  return true;
133
140
  }
@@ -167,17 +174,22 @@ StreamManagement.prototype.send = function (stanza, message) {
167
174
  bodyContent = chatUtils.getElementText(stanzaXML, 'body') || '',
168
175
  attachments = chatUtils.getAllElements(stanzaXML, 'attachment') || '';
169
176
 
170
- self._originalSend.call(self._c, stanza);
171
-
172
- if (tagName === 'message' && (type === 'chat' || type === 'groupchat') && (bodyContent || attachments.length)) {
173
- self._sendStanzasRequest({
174
- message: message,
175
- time: Date.now() + self._timeInterval,
176
- expect: self._clientSentStanzasCounter
177
- });
177
+ try {
178
+ self._originalSend.call(self._c, stanza);
179
+ } catch (e) {
180
+ Utils.QBLog('[QBChat]', e.message);
181
+ } finally {
182
+ if (tagName === 'message' && (type === 'chat' || type === 'groupchat') && (bodyContent || attachments.length)) {
183
+ self._sendStanzasRequest({
184
+ message: message,
185
+ time: Date.now() + self._timeInterval,
186
+ expect: self._clientSentStanzasCounter
187
+ });
188
+ }
189
+
190
+ self._clientSentStanzasCounter++;
178
191
  }
179
192
 
180
- self._clientSentStanzasCounter++;
181
193
  };
182
194
 
183
195
  StreamManagement.prototype._sendStanzasRequest = function (data) {
@@ -186,10 +198,14 @@ StreamManagement.prototype._sendStanzasRequest = function (data) {
186
198
  if(self._isStreamManagementEnabled){
187
199
  self._stanzasQueue.push(data);
188
200
 
189
- var stanza = Utils.getEnv().browser ? $build('r', { xmlns: self._NS}) :
190
- chatUtils.createStanza(self._nodeBuilder, { xmlns: self._NS}, 'r');
201
+ var stanza = Utils.getEnv().browser ? $build('r', { xmlns: self._NS }) :
202
+ chatUtils.createStanza(self._nodeBuilder, { xmlns: self._NS }, 'r');
191
203
 
192
- self._originalSend.call(self._c, stanza);
204
+ if (self._c.connected) {
205
+ self._originalSend.call(self._c, stanza);
206
+ } else {
207
+ self._checkCounterOnIncomeStanza();
208
+ }
193
209
  }
194
210
  };
195
211
 
@@ -198,13 +214,15 @@ StreamManagement.prototype.getClientSentStanzasCounter = function(){
198
214
  };
199
215
 
200
216
  StreamManagement.prototype._checkCounterOnIncomeStanza = function (count){
201
- if (this._stanzasQueue[0].expect !== count){
202
- this.sentMessageCallback(this._stanzasQueue[0].message);
203
- } else {
204
- this.sentMessageCallback(null, this._stanzasQueue[0].message);
217
+ if (this._stanzasQueue.length) {
218
+ if (this._stanzasQueue[0].expect !== count){
219
+ this.sentMessageCallback(this._stanzasQueue[0].message);
220
+ } else {
221
+ this.sentMessageCallback(null, this._stanzasQueue[0].message);
222
+ }
223
+
224
+ this._stanzasQueue.shift();
205
225
  }
206
-
207
- this._stanzasQueue.shift();
208
226
  };
209
227
 
210
228
  StreamManagement.prototype._increaseReceivedStanzasCounter = function(){
package/src/qbConfig.js CHANGED
@@ -12,16 +12,16 @@
12
12
  */
13
13
 
14
14
  var config = {
15
- version: '2.13.10',
16
- buildNumber: '1104',
15
+ version: '2.14.0',
16
+ buildNumber: '1135',
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
- api: 'api.quickblox.com',
24
+ api: 'apistage6.quickblox.com/',
25
25
  chat: 'chat.quickblox.com',
26
26
  muc: 'muc.chat.quickblox.com'
27
27
  },
@@ -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();