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.
package/README.md CHANGED
@@ -16,7 +16,7 @@ Check out our [API Reference](https://quickblox.github.io/quickblox-javascript-s
16
16
  ## Dependencies for browser
17
17
 
18
18
  ```html
19
- <script src="https://unpkg.com/quickblox@2.13.9/quickblox.min.js"></script>
19
+ <script src="https://unpkg.com/quickblox@2.14.0/quickblox.min.js"></script>
20
20
  ```
21
21
 
22
22
  ## Bower and RequireJS
@@ -40,10 +40,10 @@ npm install quickblox --save
40
40
  And you're ready to go:
41
41
 
42
42
  ```javascript
43
- var QB = require('quickblox');
43
+ var QB = require("quickblox");
44
44
 
45
45
  // OR to create many QB instances
46
- var QuickBlox = require('quickblox').QuickBlox;
46
+ var QuickBlox = require("quickblox").QuickBlox;
47
47
  var QB1 = new QuickBlox();
48
48
  var QB2 = new QuickBlox();
49
49
  ```
@@ -54,9 +54,9 @@ var QB2 = new QuickBlox();
54
54
 
55
55
  # Browsers support
56
56
 
57
- | Edge | Firefox | Chrome | Safari | Opera | Node.js |
58
- |:----:|:-------:|:------:|:------:|:-----:|:-------:|
59
- | 14+ | 52+ | 50+ | 11.1+ | 36+ | 6+ |
57
+ | Edge | Firefox | Chrome | Safari | Opera | Node.js |
58
+ | :--: | :-----: | :----: | :----: | :---: | :-----: |
59
+ | 14+ | 52+ | 50+ | 11.1+ | 36+ | 6+ |
60
60
 
61
61
  # Documentation
62
62
 
@@ -69,7 +69,9 @@ Please raise questions, requests for help etc. via https://stackoverflow.com/que
69
69
  Feedback and suggestions for improvement always welcome :)
70
70
 
71
71
  # How to contribute
72
+
72
73
  See more information at [contributing.md](https://github.com/QuickBlox/quickblox-javascript-sdk/blob/gh-pages/.github/CONTRIBUTING.md)
73
74
 
74
75
  # License
76
+
75
77
  Apache 2.0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "quickblox",
3
3
  "description": "QuickBlox JavaScript SDK",
4
- "version": "2.13.10",
4
+ "version": "2.14.0",
5
5
  "homepage": "https://quickblox.com/developers/Javascript",
6
6
  "main": "src/qbMain.js",
7
7
  "license": "(Apache-2.0)",
@@ -76,6 +76,7 @@
76
76
  }
77
77
  },
78
78
  "scripts": {
79
+ "dev": "NODE_ENV=develop gulp watch",
79
80
  "setDependencies": "npm i && npm i -g gulp-cli && npm install rimraf -g && npm install -g jasmine",
80
81
  "lint": "jshint src --reporter=node_modules/jshint-stylish",
81
82
  "build": "cross-env NODE_ENV=production npm run lint && gulp build && gulp minify",
package/quickblox.js CHANGED
@@ -46183,6 +46183,9 @@ function ChatProxy(service) {
46183
46183
  this._isLogout = false;
46184
46184
 
46185
46185
  this._checkConnectionTimer = undefined;
46186
+ // this._checkConnectionPingTimer = undefined; //artan: 13/09/2022 at 16:30
46187
+ this._checkExpiredSessionTimer = undefined;
46188
+ this._sessionHasExpired = false;
46186
46189
  this._pings = {};
46187
46190
  //
46188
46191
  this.helpers = new Helpers();
@@ -46237,6 +46240,7 @@ function ChatProxy(service) {
46237
46240
  * - onLastUserActivityListener (userId, seconds)
46238
46241
  * - onDisconnectedListener
46239
46242
  * - onReconnectListener
46243
+ * - onSessionExpiredListener
46240
46244
  */
46241
46245
 
46242
46246
  /**
@@ -46856,7 +46860,7 @@ ChatProxy.prototype = {
46856
46860
  case Strophe.Status.AUTHFAIL:
46857
46861
  self.isConnected = false;
46858
46862
  self._isConnecting = false;
46859
-
46863
+
46860
46864
  err = Utils.getError(401, 'Status.AUTHFAIL - The authentication attempt failed', 'QBChat');
46861
46865
 
46862
46866
  if (isInitialConnect) {
@@ -46864,6 +46868,7 @@ ChatProxy.prototype = {
46864
46868
  }
46865
46869
 
46866
46870
  if(!self.isConnected && typeof self.onReconnectFailedListener === 'function'){
46871
+ // TODO: investigate problem reconnect field
46867
46872
  Utils.safeCallbackCall(self.onReconnectFailedListener, err);
46868
46873
  }
46869
46874
 
@@ -46884,7 +46889,50 @@ ChatProxy.prototype = {
46884
46889
  self.connection.XAddTrackedHandler(self._onIQ, null, 'iq');
46885
46890
  self.connection.XAddTrackedHandler(self._onSystemMessageListener, null, 'message', 'headline');
46886
46891
  self.connection.XAddTrackedHandler(self._onMessageErrorListener, null, 'message', 'error');
46887
-
46892
+
46893
+ // var noTimerId = typeof self._checkConnectionPingTimer === 'undefined'; //artan: 13/09/2022 at 16:30
46894
+ // noTimerId = config.pingLocalhostTimeInterval === 0 ? false : noTimerId;
46895
+ // if (noTimerId) {
46896
+ // Utils.QBLog('[QBChat]', 'Init ping to localhost at ', Utils.getCurrentTime());
46897
+ // self._checkConnectionPingTimer = setInterval(function() {
46898
+ // self._ping(userJid,
46899
+ // function(error) {
46900
+ // if (error) {
46901
+ // Utils.QBLog('[QBChat]',
46902
+ // 'Local Ping: ',
46903
+ // 'failed, at ', Utils.getCurrentTime(),
46904
+ // ' error: ', error);
46905
+ // } else {
46906
+ // Utils.QBLog('[QBChat]',
46907
+ // 'Local Ping: ',
46908
+ // 'ok, at ', Utils.getCurrentTime());
46909
+ // }
46910
+ // });
46911
+ // }, config.pingLocalhostTimeInterval * 1000);
46912
+ // }
46913
+
46914
+ if (typeof self.onSessionExpiredListener === 'function') {
46915
+ var noExpiredSessionTimerId = typeof self._checkExpiredSessionTimer === 'undefined';
46916
+ if (noExpiredSessionTimerId) {
46917
+ Utils.QBLog('[QBChat]', 'Init timer for check session expired at ', ((new Date()).toTimeString().split(' ')[0]));
46918
+ self._checkExpiredSessionTimer = setInterval(function() {
46919
+ var timeNow = new Date();
46920
+ if (typeof config.qbTokenExpirationDate !== 'undefined') {
46921
+ var timeLag = Math.round((timeNow.getTime() - config.qbTokenExpirationDate.getTime()) / (1000 * 60));
46922
+ //artan 25-08-2022
46923
+ // TODO: need to delete in task [CROS-815]
46924
+ console.log('timeLag: ', timeLag);
46925
+ if (timeLag >= 0) {
46926
+ self._sessionHasExpired = true;
46927
+ Utils.safeCallbackCall(self.onSessionExpiredListener, null);
46928
+ }
46929
+ }
46930
+ // TODO: in task [CROS-815], may by need to change 5 * 1000 to config.liveSessionInterval * 1000
46931
+ }, 5 * 1000);
46932
+
46933
+ }
46934
+ }
46935
+
46888
46936
  self._postConnectActions(function(roster) {
46889
46937
  callback(null, roster);
46890
46938
  }, isInitialConnect);
@@ -47005,10 +47053,13 @@ ChatProxy.prototype = {
47005
47053
  _postConnectActions: function(callback, isInitialConnect) {
47006
47054
  Utils.QBLog('[QBChat]', 'Status.CONNECTED at ' + chatUtils.getLocalTime());
47007
47055
 
47008
- var self = this,
47009
- xmppClient = Utils.getEnv().browser ? self.connection : self.Client,
47010
- presence = Utils.getEnv().browser ? $pres() : chatUtils.createStanza(XMPP.Stanza, null, 'presence');
47011
-
47056
+ var self = this;
47057
+ var isBrowser = Utils.getEnv().browser;
47058
+ var xmppClient = isBrowser ? self.connection : self.Client;
47059
+ var presence = isBrowser ?
47060
+ $pres() :
47061
+ chatUtils.createStanza(XMPP.Stanza, null, 'presence');
47062
+
47012
47063
  if (config.streamManagement.enable && config.chatProtocol.active === 2) {
47013
47064
  self.streamManagement.enable(self.connection, null);
47014
47065
  self.streamManagement.sentMessageCallback = self._sentMessageCallback;
@@ -47018,6 +47069,7 @@ ChatProxy.prototype = {
47018
47069
 
47019
47070
  self.isConnected = true;
47020
47071
  self._isConnecting = false;
47072
+ self._sessionHasExpired = false;
47021
47073
 
47022
47074
  self._enableCarbons();
47023
47075
 
@@ -47046,16 +47098,21 @@ ChatProxy.prototype = {
47046
47098
  },
47047
47099
 
47048
47100
  _establishConnection: function(params) {
47101
+ // TODO: must to call if only qbTokenExpirationDate is not expried
47049
47102
  var self = this;
47050
-
47103
+ Utils.QBLog('[QBChat]', '_establishConnection called');
47051
47104
  if (self._isLogout || self._checkConnectionTimer) {
47105
+ Utils.QBLog('[QBChat]', '_establishConnection return');
47052
47106
  return;
47053
47107
  }
47054
47108
 
47055
47109
  var _connect = function() {
47056
- if (!self.isConnected && !self._isConnecting) {
47110
+ Utils.QBLog('[QBChat]', 'call _connect() in _establishConnection ');
47111
+ if (!self.isConnected && !self._isConnecting && !self._sessionHasExpired) {
47112
+ Utils.QBLog('[QBChat]', 'call connect() again in _establishConnection ');
47057
47113
  self.connect(params);
47058
47114
  } else {
47115
+ Utils.QBLog('[QBChat]', 'stop timer in _establishConnection ');
47059
47116
  clearInterval(self._checkConnectionTimer);
47060
47117
  self._checkConnectionTimer = undefined;
47061
47118
  }
@@ -47063,6 +47120,8 @@ ChatProxy.prototype = {
47063
47120
 
47064
47121
  _connect();
47065
47122
 
47123
+
47124
+ // TODO: investigate problem with interval connection
47066
47125
  self._checkConnectionTimer = setInterval(function() {
47067
47126
  _connect();
47068
47127
  }, config.chatReconnectionTimeInterval * 1000);
@@ -47076,6 +47135,7 @@ ChatProxy.prototype = {
47076
47135
  * @returns {String} messageId - The current message id (was generated by SDK)
47077
47136
  * */
47078
47137
  send: function(jid_or_user_id, message) {
47138
+ Utils.QBLog('[QBChat]', 'Call send ' + JSON.stringify(message));
47079
47139
  var self = this,
47080
47140
  builder = Utils.getEnv().browser ? $msg : XMPP.Stanza;
47081
47141
 
@@ -47138,6 +47198,7 @@ ChatProxy.prototype = {
47138
47198
  * @returns {String} messageId - The current message id (was generated by SDK)
47139
47199
  * */
47140
47200
  sendSystemMessage: function(jid_or_user_id, message) {
47201
+ Utils.QBLog('[QBChat]', 'Call sendSystemMessage ' + JSON.stringify(message));
47141
47202
  var self = this,
47142
47203
  builder = Utils.getEnv().browser ? $msg : XMPP.Stanza,
47143
47204
  paramsCreateMsg = {
@@ -47186,6 +47247,7 @@ ChatProxy.prototype = {
47186
47247
  * @param {String | Number} jid_or_user_id - Use opponent id or jid for 1 to 1 chat, and room jid for group chat.
47187
47248
  * */
47188
47249
  sendIsTypingStatus: function(jid_or_user_id) {
47250
+ Utils.QBLog('[QBChat]', 'Call sendIsTypingStatus ');
47189
47251
  var self = this,
47190
47252
  stanzaParams = {
47191
47253
  from: self.helpers.getUserCurrentJid(),
@@ -47200,10 +47262,12 @@ ChatProxy.prototype = {
47200
47262
  xmlns: chatUtils.MARKERS.STATES
47201
47263
  });
47202
47264
 
47203
- if(Utils.getEnv().browser){
47204
- self.connection.send(stanza);
47205
- } else {
47206
- self.Client.send(stanza);
47265
+ if (self.connection.connected) {
47266
+ if(Utils.getEnv().browser){
47267
+ self.connection.send(stanza);
47268
+ } else {
47269
+ self.Client.send(stanza);
47270
+ }
47207
47271
  }
47208
47272
  },
47209
47273
 
@@ -47213,6 +47277,7 @@ ChatProxy.prototype = {
47213
47277
  * @param {String | Number} jid_or_user_id - Use opponent id or jid for 1 to 1 chat, and room jid for group chat.
47214
47278
  * */
47215
47279
  sendIsStopTypingStatus: function(jid_or_user_id) {
47280
+ Utils.QBLog('[QBChat]', 'Call sendIsStopTypingStatus ');
47216
47281
  var self = this,
47217
47282
  stanzaParams = {
47218
47283
  from: self.helpers.getUserCurrentJid(),
@@ -47227,10 +47292,12 @@ ChatProxy.prototype = {
47227
47292
  xmlns: chatUtils.MARKERS.STATES
47228
47293
  });
47229
47294
 
47230
- if(Utils.getEnv().browser){
47231
- self.connection.send(stanza);
47232
- } else {
47233
- self.Client.send(stanza);
47295
+ if (self.connection.connected) {
47296
+ if(Utils.getEnv().browser){
47297
+ self.connection.send(stanza);
47298
+ } else {
47299
+ self.Client.send(stanza);
47300
+ }
47234
47301
  }
47235
47302
  },
47236
47303
 
@@ -47243,6 +47310,7 @@ ChatProxy.prototype = {
47243
47310
  * @param {Number} params.dialogId - The dialog id
47244
47311
  * */
47245
47312
  sendDeliveredStatus: function(params) {
47313
+ Utils.QBLog('[QBChat]', 'Call sendDeliveredStatus ');
47246
47314
  var self = this,
47247
47315
  stanzaParams = {
47248
47316
  type: 'chat',
@@ -47279,6 +47347,7 @@ ChatProxy.prototype = {
47279
47347
  * @param {Number} params.dialogId - The dialog id
47280
47348
  * */
47281
47349
  sendReadStatus: function(params) {
47350
+ Utils.QBLog('[QBChat]', 'Call sendReadStatus ' + JSON.stringify(params));
47282
47351
  var self = this,
47283
47352
  stanzaParams = {
47284
47353
  type: 'chat',
@@ -47312,6 +47381,7 @@ ChatProxy.prototype = {
47312
47381
  * @param {(Number|String)} jid_or_user_id - The user id or jid, that the last activity we want to know
47313
47382
  * */
47314
47383
  getLastUserActivity: function(jid_or_user_id) {
47384
+ Utils.QBLog('[QBChat]', 'Call getLastUserActivity ');
47315
47385
  var iqParams,
47316
47386
  builder,
47317
47387
  iq;
@@ -47338,7 +47408,47 @@ ChatProxy.prototype = {
47338
47408
  }
47339
47409
  },
47340
47410
 
47411
+ _ping: function(jid_or_user_id, callback){
47412
+ var self = this;
47413
+ var id = this.helpers.getUniqueId('ping');
47414
+ var builder = Utils.getEnv().browser ? $iq : XMPP.Stanza;
47415
+ var to;
47416
+ var _callback;
47417
+ var stanza;
47418
+
47419
+ //to = config.endpoints.chat;
47420
+ to = 'http://localhost';
47421
+ _callback = callback;
47422
+
47423
+
47424
+ var iqParams = {
47425
+ from: this.helpers.getUserCurrentJid(),
47426
+ id: id,
47427
+ to: to,
47428
+ type: 'get'
47429
+ };
47430
+ stanza = chatUtils.createStanza(builder, iqParams, 'iq');
47431
+ stanza.c('ping', { xmlns: "urn:xmpp:ping" });
47432
+
47433
+ var noAnswer = function () {
47434
+ _callback('No answer');
47435
+ self._pings[id] = undefined;
47436
+ delete self._pings[id];
47437
+ };
47438
+ if (Utils.getEnv().browser) {
47439
+ this.connection.send(stanza);
47440
+ } else {
47441
+ this.Client.send(stanza);
47442
+ }
47443
+ this._pings[id] = {
47444
+ callback: _callback,
47445
+ interval: setTimeout(noAnswer, config.pingTimeout * 1000)
47446
+ };
47447
+ return id;
47448
+ },
47449
+
47341
47450
  ping: function (jid_or_user_id, callback) {
47451
+ Utils.QBLog('[QBChat]', 'Call ping ');
47342
47452
  var self = this;
47343
47453
  var id = this.helpers.getUniqueId('ping');
47344
47454
  var builder = Utils.getEnv().browser ? $iq : XMPP.Stanza;
@@ -47390,8 +47500,11 @@ ChatProxy.prototype = {
47390
47500
  * @memberof QB.chat
47391
47501
  * */
47392
47502
  disconnect: function() {
47503
+ Utils.QBLog('[QBChat]', 'Call disconnect ');
47393
47504
  clearInterval(this._checkConnectionTimer);
47505
+ clearInterval(this._checkExpiredSessionTimer);
47394
47506
  this._checkConnectionTimer = undefined;
47507
+ this._checkExpiredSessionTimer = undefined;
47395
47508
  this.muc.joinedRooms = {};
47396
47509
  this._isLogout = true;
47397
47510
  this.helpers.setUserCurrentJid('');
@@ -53454,6 +53567,8 @@ function StreamManagement(options) {
53454
53567
  // The client send stanza counter.
53455
53568
  this._clientSentStanzasCounter = null;
53456
53569
 
53570
+ this._intervalId = null;
53571
+
53457
53572
  this._timeInterval = 2000;
53458
53573
 
53459
53574
  this.sentMessageCallback = null;
@@ -53538,7 +53653,12 @@ StreamManagement.prototype._addEnableHandlers = function () {
53538
53653
  if(tagName === 'enabled'){
53539
53654
  self._isStreamManagementEnabled = true;
53540
53655
 
53541
- setInterval(self._timeoutCallback.bind(self), self._timeInterval);
53656
+ return true;
53657
+ }
53658
+
53659
+ if (self._isStreamManagementEnabled && tagName === 'message') {
53660
+ clearInterval(self._intervalId);
53661
+ self._intervalId = setInterval(self._timeoutCallback.bind(self), self._timeInterval);
53542
53662
 
53543
53663
  return true;
53544
53664
  }
@@ -53578,17 +53698,22 @@ StreamManagement.prototype.send = function (stanza, message) {
53578
53698
  bodyContent = chatUtils.getElementText(stanzaXML, 'body') || '',
53579
53699
  attachments = chatUtils.getAllElements(stanzaXML, 'attachment') || '';
53580
53700
 
53581
- self._originalSend.call(self._c, stanza);
53582
-
53583
- if (tagName === 'message' && (type === 'chat' || type === 'groupchat') && (bodyContent || attachments.length)) {
53584
- self._sendStanzasRequest({
53585
- message: message,
53586
- time: Date.now() + self._timeInterval,
53587
- expect: self._clientSentStanzasCounter
53588
- });
53701
+ try {
53702
+ self._originalSend.call(self._c, stanza);
53703
+ } catch (e) {
53704
+ Utils.QBLog('[QBChat]', e.message);
53705
+ } finally {
53706
+ if (tagName === 'message' && (type === 'chat' || type === 'groupchat') && (bodyContent || attachments.length)) {
53707
+ self._sendStanzasRequest({
53708
+ message: message,
53709
+ time: Date.now() + self._timeInterval,
53710
+ expect: self._clientSentStanzasCounter
53711
+ });
53712
+ }
53713
+
53714
+ self._clientSentStanzasCounter++;
53589
53715
  }
53590
53716
 
53591
- self._clientSentStanzasCounter++;
53592
53717
  };
53593
53718
 
53594
53719
  StreamManagement.prototype._sendStanzasRequest = function (data) {
@@ -53597,10 +53722,14 @@ StreamManagement.prototype._sendStanzasRequest = function (data) {
53597
53722
  if(self._isStreamManagementEnabled){
53598
53723
  self._stanzasQueue.push(data);
53599
53724
 
53600
- var stanza = Utils.getEnv().browser ? $build('r', { xmlns: self._NS}) :
53601
- chatUtils.createStanza(self._nodeBuilder, { xmlns: self._NS}, 'r');
53725
+ var stanza = Utils.getEnv().browser ? $build('r', { xmlns: self._NS }) :
53726
+ chatUtils.createStanza(self._nodeBuilder, { xmlns: self._NS }, 'r');
53602
53727
 
53603
- self._originalSend.call(self._c, stanza);
53728
+ if (self._c.connected) {
53729
+ self._originalSend.call(self._c, stanza);
53730
+ } else {
53731
+ self._checkCounterOnIncomeStanza();
53732
+ }
53604
53733
  }
53605
53734
  };
53606
53735
 
@@ -53609,13 +53738,15 @@ StreamManagement.prototype.getClientSentStanzasCounter = function(){
53609
53738
  };
53610
53739
 
53611
53740
  StreamManagement.prototype._checkCounterOnIncomeStanza = function (count){
53612
- if (this._stanzasQueue[0].expect !== count){
53613
- this.sentMessageCallback(this._stanzasQueue[0].message);
53614
- } else {
53615
- this.sentMessageCallback(null, this._stanzasQueue[0].message);
53741
+ if (this._stanzasQueue.length) {
53742
+ if (this._stanzasQueue[0].expect !== count){
53743
+ this.sentMessageCallback(this._stanzasQueue[0].message);
53744
+ } else {
53745
+ this.sentMessageCallback(null, this._stanzasQueue[0].message);
53746
+ }
53747
+
53748
+ this._stanzasQueue.shift();
53616
53749
  }
53617
-
53618
- this._stanzasQueue.shift();
53619
53750
  };
53620
53751
 
53621
53752
  StreamManagement.prototype._increaseReceivedStanzasCounter = function(){
@@ -53639,16 +53770,16 @@ module.exports = StreamManagement;
53639
53770
  */
53640
53771
 
53641
53772
  var config = {
53642
- version: '2.13.10',
53643
- buildNumber: '1104',
53773
+ version: '2.14.0',
53774
+ buildNumber: '1135',
53644
53775
  creds: {
53645
- appId: '',
53646
- authKey: '',
53647
- authSecret: '',
53648
- accountKey: ''
53776
+ 'appId': 0,
53777
+ 'authKey': '',
53778
+ 'authSecret': '',
53779
+ 'accountKey': ''
53649
53780
  },
53650
53781
  endpoints: {
53651
- api: 'api.quickblox.com',
53782
+ api: 'apistage6.quickblox.com/',
53652
53783
  chat: 'chat.quickblox.com',
53653
53784
  muc: 'muc.chat.quickblox.com'
53654
53785
  },
@@ -53662,6 +53793,7 @@ var config = {
53662
53793
  active: 2
53663
53794
  },
53664
53795
  pingTimeout: 30,
53796
+ pingLocalhostTimeInterval: 5,
53665
53797
  chatReconnectionTimeInterval: 5,
53666
53798
  webrtc: {
53667
53799
  answerTimeInterval: 60,
@@ -53672,7 +53804,7 @@ var config = {
53672
53804
  statsReportTimeInterval: false,
53673
53805
  iceServers: [
53674
53806
  {
53675
- urls: 'turn:turn.quickblox.com',
53807
+ urls: ['turn:turn.quickblox.com', 'stun:turn.quickblox.com'],
53676
53808
  username: 'quickblox',
53677
53809
  credential: 'baccb97ba2d92d71e26eb9886da5f1e0'
53678
53810
  }
@@ -53699,10 +53831,12 @@ var config = {
53699
53831
  },
53700
53832
  timeout: null,
53701
53833
  debug: {
53702
- mode: 0,
53834
+ mode: 1,
53703
53835
  file: null
53704
53836
  },
53705
- addISOTime: false
53837
+ addISOTime: false,
53838
+ qbTokenExpirationDate: null,
53839
+ liveSessionInterval: 120,
53706
53840
  };
53707
53841
 
53708
53842
  config.set = function(options) {
@@ -53732,6 +53866,25 @@ config.set = function(options) {
53732
53866
  });
53733
53867
  };
53734
53868
 
53869
+ /*
53870
+ * 17.08.22 artan: waiting for backend fix, look at tasks:
53871
+ * [CROS-815] - Update sessionExpirationDate on each request
53872
+ * [SR-1322] - Set param Access-Control-Expose-Headerson server side
53873
+ */
53874
+ config.updateSessionExpirationDate = function (tokenExpirationDate, headerHasToken = false) {
53875
+ var connectionTimeLag = 1; // minute
53876
+ var newDate = new Date(tokenExpirationDate);
53877
+ newDate.setMinutes ( newDate.getMinutes() - connectionTimeLag);
53878
+ // TODO: need to check in [CROS-815]
53879
+ if (!headerHasToken) {
53880
+ console.log('in date: ', newDate);
53881
+ newDate.setMinutes ( newDate.getMinutes() + config.liveSessionInterval );
53882
+ console.log('out date: ', newDate);
53883
+ }
53884
+ config.qbTokenExpirationDate = newDate;
53885
+ console.log('updateSessionExpirationDate ... Set value: ', tokenExpirationDate);
53886
+ };
53887
+
53735
53888
  module.exports = config;
53736
53889
 
53737
53890
  },{}],255:[function(require,module,exports){
@@ -53765,12 +53918,24 @@ QuickBlox.prototype = {
53765
53918
  _getOS: Utils.getOS.bind(Utils),
53766
53919
 
53767
53920
  /**
53921
+ * Init QuickBlox SDK with User Account data for start session with token.
53768
53922
  * @memberof QB
53769
- * @param {Number | String} appIdOrToken - Application ID (from your admin panel) or Session Token.
53770
- * @param {String | Number} authKeyOrAppId - Authorization key or Application ID. You need to set up Application ID if you use session token as appIdOrToken parameter.
53771
- * @param {String} authSecret - Authorization secret key (from your admin panel).
53923
+ * @param {Number} appId - Application ID (from your admin panel).
53924
+ * @param {String | Number} accountKey - Account key (from your admin panel).
53772
53925
  * @param {Object} configMap - Settings object for QuickBlox SDK.
53773
53926
  */
53927
+ initWithAppId: function(appId, accountKey, configMap) {
53928
+ if (typeof appId !== 'number') {
53929
+ throw new Error('Type of appId must be a number');
53930
+ }
53931
+ if (appId === '' || appId === undefined || appId === null ||
53932
+ accountKey === '' || accountKey === undefined || accountKey === null) {
53933
+ throw new Error('Cannot init QuickBlox without app credentials (app ID, auth key)');
53934
+ } else {
53935
+ this.init('', appId, null, accountKey, configMap);
53936
+ }
53937
+ },
53938
+
53774
53939
  init: function(appIdOrToken, authKeyOrAppId, authSecret, accountKey, configMap) {
53775
53940
  if (typeof accountKey === 'string' && accountKey.length) {
53776
53941
  if (configMap && typeof configMap === 'object') {
@@ -53885,6 +54050,37 @@ QuickBlox.prototype = {
53885
54050
  this.auth.getSession(callback);
53886
54051
  },
53887
54052
 
54053
+ /**
54054
+ * Set up user session token to current session and return it
54055
+ * @memberof QB
54056
+ * @param {String} token - a User Session Token
54057
+ * @param {getSessionCallback} callback - The getSessionCallback function.
54058
+ * @callback getSessionCallback
54059
+ * @param {Object} error - The error object
54060
+ * @param {Object} session - Contains of session object
54061
+ * */
54062
+ startSessionWithToken: function(token, callback) {
54063
+ if (token === undefined) throw new Error('Cannot start session with undefined token');
54064
+ else if (token === '') throw new Error('Cannot start session with empty string token');
54065
+ else if (token === null) throw new Error('Cannot start session with null value token');
54066
+ else if (typeof callback !== 'function') throw new Error('Cannot start session without callback function');
54067
+ else {
54068
+ try {
54069
+ this.service.setSession({token: token});
54070
+ } catch (err) {
54071
+ callback(err, null);
54072
+ }
54073
+ if (typeof callback === 'function') {
54074
+ try{
54075
+ this.auth.getSession(callback);
54076
+ }
54077
+ catch(er){
54078
+ callback(er, null);
54079
+ }
54080
+ }
54081
+ }
54082
+ },
54083
+
53888
54084
  /**
53889
54085
  * Creat new session. {@link https://quickblox.com/developers/Javascript#Authorization More info}
53890
54086
  * @memberof QB
@@ -54101,6 +54297,15 @@ ServiceProxy.prototype = {
54101
54297
  .then(function(response) {
54102
54298
  qbResponse = response;
54103
54299
 
54300
+ if (qbRequest.method === 'GET' || qbRequest.method === 'POST'){
54301
+ // TODO: need to check in [CROS-815]
54302
+ var qbTokenExpirationDate = qbResponse.headers.get('qb-token-expirationdate');
54303
+ var headerHasToken = !(qbTokenExpirationDate === null ||
54304
+ typeof qbTokenExpirationDate === 'undefined');
54305
+ qbTokenExpirationDate = (headerHasToken) ? qbTokenExpirationDate : new Date();
54306
+ self.qbInst.config.updateSessionExpirationDate(qbTokenExpirationDate, headerHasToken);
54307
+ }
54308
+
54104
54309
  if (qbDataType === 'text') {
54105
54310
  return response.text();
54106
54311
  } else {
@@ -54116,6 +54321,8 @@ ServiceProxy.prototype = {
54116
54321
  }).then(function(body) {
54117
54322
  _requestCallback(null, qbResponse, body);
54118
54323
  }, function(error) {
54324
+ // TODO: review in [CROS-815]
54325
+ console.log('Error: ', error);
54119
54326
  _requestCallback(error);
54120
54327
  });
54121
54328
 
@@ -54413,6 +54620,10 @@ var Utils = {
54413
54620
  '000000'.substr(0, 6 - increment.length) + increment;
54414
54621
  },
54415
54622
 
54623
+ getCurrentTime: function() {
54624
+ return ((new Date()).toTimeString().split(' ')[0]);
54625
+ },
54626
+
54416
54627
  injectISOTimes: function(data) {
54417
54628
  if (data.created_at) {
54418
54629
  if (typeof data.created_at === 'number') data.iso_created_at = new Date(data.created_at * 1000).toISOString();