quickblox 2.13.11 → 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.11/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
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "quickblox",
3
3
  "description": "QuickBlox JavaScript SDK",
4
- "version": "2.13.11",
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)",
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
  /**
@@ -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(),
@@ -47215,6 +47277,7 @@ ChatProxy.prototype = {
47215
47277
  * @param {String | Number} jid_or_user_id - Use opponent id or jid for 1 to 1 chat, and room jid for group chat.
47216
47278
  * */
47217
47279
  sendIsStopTypingStatus: function(jid_or_user_id) {
47280
+ Utils.QBLog('[QBChat]', 'Call sendIsStopTypingStatus ');
47218
47281
  var self = this,
47219
47282
  stanzaParams = {
47220
47283
  from: self.helpers.getUserCurrentJid(),
@@ -47247,6 +47310,7 @@ ChatProxy.prototype = {
47247
47310
  * @param {Number} params.dialogId - The dialog id
47248
47311
  * */
47249
47312
  sendDeliveredStatus: function(params) {
47313
+ Utils.QBLog('[QBChat]', 'Call sendDeliveredStatus ');
47250
47314
  var self = this,
47251
47315
  stanzaParams = {
47252
47316
  type: 'chat',
@@ -47283,6 +47347,7 @@ ChatProxy.prototype = {
47283
47347
  * @param {Number} params.dialogId - The dialog id
47284
47348
  * */
47285
47349
  sendReadStatus: function(params) {
47350
+ Utils.QBLog('[QBChat]', 'Call sendReadStatus ' + JSON.stringify(params));
47286
47351
  var self = this,
47287
47352
  stanzaParams = {
47288
47353
  type: 'chat',
@@ -47316,6 +47381,7 @@ ChatProxy.prototype = {
47316
47381
  * @param {(Number|String)} jid_or_user_id - The user id or jid, that the last activity we want to know
47317
47382
  * */
47318
47383
  getLastUserActivity: function(jid_or_user_id) {
47384
+ Utils.QBLog('[QBChat]', 'Call getLastUserActivity ');
47319
47385
  var iqParams,
47320
47386
  builder,
47321
47387
  iq;
@@ -47342,7 +47408,47 @@ ChatProxy.prototype = {
47342
47408
  }
47343
47409
  },
47344
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
+
47345
47450
  ping: function (jid_or_user_id, callback) {
47451
+ Utils.QBLog('[QBChat]', 'Call ping ');
47346
47452
  var self = this;
47347
47453
  var id = this.helpers.getUniqueId('ping');
47348
47454
  var builder = Utils.getEnv().browser ? $iq : XMPP.Stanza;
@@ -47394,8 +47500,11 @@ ChatProxy.prototype = {
47394
47500
  * @memberof QB.chat
47395
47501
  * */
47396
47502
  disconnect: function() {
47503
+ Utils.QBLog('[QBChat]', 'Call disconnect ');
47397
47504
  clearInterval(this._checkConnectionTimer);
47505
+ clearInterval(this._checkExpiredSessionTimer);
47398
47506
  this._checkConnectionTimer = undefined;
47507
+ this._checkExpiredSessionTimer = undefined;
47399
47508
  this.muc.joinedRooms = {};
47400
47509
  this._isLogout = true;
47401
47510
  this.helpers.setUserCurrentJid('');
@@ -53661,16 +53770,16 @@ module.exports = StreamManagement;
53661
53770
  */
53662
53771
 
53663
53772
  var config = {
53664
- version: '2.13.11',
53665
- buildNumber: '1105',
53773
+ version: '2.14.0',
53774
+ buildNumber: '1135',
53666
53775
  creds: {
53667
- appId: '',
53668
- authKey: '',
53669
- authSecret: '',
53670
- accountKey: ''
53776
+ 'appId': 0,
53777
+ 'authKey': '',
53778
+ 'authSecret': '',
53779
+ 'accountKey': ''
53671
53780
  },
53672
53781
  endpoints: {
53673
- api: 'api.quickblox.com',
53782
+ api: 'apistage6.quickblox.com/',
53674
53783
  chat: 'chat.quickblox.com',
53675
53784
  muc: 'muc.chat.quickblox.com'
53676
53785
  },
@@ -53684,6 +53793,7 @@ var config = {
53684
53793
  active: 2
53685
53794
  },
53686
53795
  pingTimeout: 30,
53796
+ pingLocalhostTimeInterval: 5,
53687
53797
  chatReconnectionTimeInterval: 5,
53688
53798
  webrtc: {
53689
53799
  answerTimeInterval: 60,
@@ -53694,7 +53804,7 @@ var config = {
53694
53804
  statsReportTimeInterval: false,
53695
53805
  iceServers: [
53696
53806
  {
53697
- urls: 'turn:turn.quickblox.com',
53807
+ urls: ['turn:turn.quickblox.com', 'stun:turn.quickblox.com'],
53698
53808
  username: 'quickblox',
53699
53809
  credential: 'baccb97ba2d92d71e26eb9886da5f1e0'
53700
53810
  }
@@ -53721,10 +53831,12 @@ var config = {
53721
53831
  },
53722
53832
  timeout: null,
53723
53833
  debug: {
53724
- mode: 0,
53834
+ mode: 1,
53725
53835
  file: null
53726
53836
  },
53727
- addISOTime: false
53837
+ addISOTime: false,
53838
+ qbTokenExpirationDate: null,
53839
+ liveSessionInterval: 120,
53728
53840
  };
53729
53841
 
53730
53842
  config.set = function(options) {
@@ -53754,6 +53866,25 @@ config.set = function(options) {
53754
53866
  });
53755
53867
  };
53756
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
+
53757
53888
  module.exports = config;
53758
53889
 
53759
53890
  },{}],255:[function(require,module,exports){
@@ -53787,12 +53918,24 @@ QuickBlox.prototype = {
53787
53918
  _getOS: Utils.getOS.bind(Utils),
53788
53919
 
53789
53920
  /**
53921
+ * Init QuickBlox SDK with User Account data for start session with token.
53790
53922
  * @memberof QB
53791
- * @param {Number | String} appIdOrToken - Application ID (from your admin panel) or Session Token.
53792
- * @param {String | Number} authKeyOrAppId - Authorization key or Application ID. You need to set up Application ID if you use session token as appIdOrToken parameter.
53793
- * @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).
53794
53925
  * @param {Object} configMap - Settings object for QuickBlox SDK.
53795
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
+
53796
53939
  init: function(appIdOrToken, authKeyOrAppId, authSecret, accountKey, configMap) {
53797
53940
  if (typeof accountKey === 'string' && accountKey.length) {
53798
53941
  if (configMap && typeof configMap === 'object') {
@@ -53907,6 +54050,37 @@ QuickBlox.prototype = {
53907
54050
  this.auth.getSession(callback);
53908
54051
  },
53909
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
+
53910
54084
  /**
53911
54085
  * Creat new session. {@link https://quickblox.com/developers/Javascript#Authorization More info}
53912
54086
  * @memberof QB
@@ -54123,6 +54297,15 @@ ServiceProxy.prototype = {
54123
54297
  .then(function(response) {
54124
54298
  qbResponse = response;
54125
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
+
54126
54309
  if (qbDataType === 'text') {
54127
54310
  return response.text();
54128
54311
  } else {
@@ -54138,6 +54321,8 @@ ServiceProxy.prototype = {
54138
54321
  }).then(function(body) {
54139
54322
  _requestCallback(null, qbResponse, body);
54140
54323
  }, function(error) {
54324
+ // TODO: review in [CROS-815]
54325
+ console.log('Error: ', error);
54141
54326
  _requestCallback(error);
54142
54327
  });
54143
54328
 
@@ -54435,6 +54620,10 @@ var Utils = {
54435
54620
  '000000'.substr(0, 6 - increment.length) + increment;
54436
54621
  },
54437
54622
 
54623
+ getCurrentTime: function() {
54624
+ return ((new Date()).toTimeString().split(' ')[0]);
54625
+ },
54626
+
54438
54627
  injectISOTimes: function(data) {
54439
54628
  if (data.created_at) {
54440
54629
  if (typeof data.created_at === 'number') data.iso_created_at = new Date(data.created_at * 1000).toISOString();