quickblox 2.21.0-alpha.1 → 2.21.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "quickblox",
3
3
  "description": "QuickBlox JavaScript SDK",
4
- "version": "2.21.0-alpha.1",
4
+ "version": "2.21.0",
5
5
  "homepage": "https://quickblox.com/developers/Javascript",
6
6
  "main": "src/qbMain.js",
7
7
  "types": "quickblox.d.ts",
@@ -38,6 +38,7 @@
38
38
  "email": "web@quickblox.com"
39
39
  },
40
40
  "dependencies": {
41
+ "cordova-custom-config": "^5.1.1",
41
42
  "crypto-js": "3.1.2-2",
42
43
  "form-data": "^2.3.1",
43
44
  "nativescript-xmpp-client": "^1.2.0",
package/quickblox.d.ts CHANGED
@@ -144,6 +144,10 @@ export declare interface QBConfig {
144
144
  pingDebug?: boolean
145
145
  pingLocalhostTimeInterval?: number
146
146
  chatReconnectionTimeInterval?: number
147
+ /** If true, QB.init will do a short synchronous block after starting account_settings. Default: true. */
148
+ initBlockOnSettings?: boolean
149
+ /** Busy-wait duration in ms used when initBlockOnSettings=true. Default: 3000. */
150
+ initBlockDurationMs?: number
147
151
  }
148
152
 
149
153
  export declare interface QBError {
@@ -1637,6 +1641,13 @@ export class QuickBlox {
1637
1641
  config?: QBConfig,
1638
1642
  ): void
1639
1643
 
1644
+ /**
1645
+ * Resolves when internal async initialization (e.g., fetching `account_settings`
1646
+ * and rebinding endpoints) is finished. If no async work was scheduled during
1647
+ * `init`, it resolves immediately.
1648
+ */
1649
+ ready(): Promise<void>
1650
+
1640
1651
  /**
1641
1652
  * Init QuickBlox SDK with User Account data to start session with token
1642
1653
  * ([read more](https://docs.quickblox.com/docs/js-setup#initialize-quickblox-sdk-without-authorization-key-and-secret)).
package/quickblox.js CHANGED
@@ -15129,8 +15129,10 @@ function isUndefined(arg) {
15129
15129
  }
15130
15130
 
15131
15131
  },{}],80:[function(require,module,exports){
15132
+ 'use strict';
15133
+
15132
15134
  /* eslint-env browser */
15133
- module.exports = typeof self == 'object' ? self.FormData : window.FormData;
15135
+ module.exports = typeof self === 'object' ? self.FormData : window.FormData;
15134
15136
 
15135
15137
  },{}],81:[function(require,module,exports){
15136
15138
  'use strict';
@@ -55078,8 +55080,8 @@ module.exports = StreamManagement;
55078
55080
  */
55079
55081
 
55080
55082
  var config = {
55081
- version: '2.20.0',
55082
- buildNumber: '1166',
55083
+ version: '2.21.0',
55084
+ buildNumber: '1167',
55083
55085
  creds: {
55084
55086
  'appId': 0,
55085
55087
  'authKey': '',
@@ -55102,6 +55104,8 @@ var config = {
55102
55104
  },
55103
55105
  pingTimeout: 1,
55104
55106
  pingDebug: false,
55107
+ initBlockOnSettings: false,
55108
+ initBlockDurationMs: 3000,
55105
55109
  pingLocalhostTimeInterval: 5,
55106
55110
  chatReconnectionTimeInterval: 3,
55107
55111
  webrtc: {
@@ -55210,6 +55214,7 @@ const MessageProxy = require("./modules/chat/qbMessage");
55210
55214
  const Chat = require("./modules/chat/qbChat");
55211
55215
  const DialogProxy = require("./modules/chat/qbDialog");
55212
55216
  const WebRTCClient = require("./modules/webrtc/qbWebRTCClient");
55217
+ const PushNotifications = require("./modules/qbPushNotifications");
55213
55218
 
55214
55219
  // Actual QuickBlox API starts here
55215
55220
  function QuickBlox() {}
@@ -55294,6 +55299,10 @@ QuickBlox.prototype = {
55294
55299
  } else {
55295
55300
  this.webrtc = false;
55296
55301
  }
55302
+ this._initReady = Promise.resolve();
55303
+ var initBlockOnSettings = (typeof config.initBlockOnSettings === 'boolean') ? config.initBlockOnSettings : true;
55304
+ var initBlockDurationMs = (typeof config.initBlockDurationMs === 'number') ? config.initBlockDurationMs : 3000;
55305
+
55297
55306
 
55298
55307
  // Initialization by outside token
55299
55308
  if (typeof appIdOrToken === 'string' && (!authKeyOrAppId || typeof authKeyOrAppId === 'number') && !authSecret) {
@@ -55321,42 +55330,148 @@ QuickBlox.prototype = {
55321
55330
  config.urls.account,
55322
55331
  config.urls.type
55323
55332
  ].join('');
55333
+
55334
+ // generic function to capture (extract) listeners
55335
+ var preserveListeners = function (obj) {
55336
+ var map = {};
55337
+ if (!obj) return map;
55338
+ Object.keys(obj).forEach(function (k) {
55339
+ if (/^on[A-Z]/.test(k) && typeof obj[k] === 'function') {
55340
+ map[k] = obj[k];
55341
+ }
55342
+ });
55343
+ return map;
55344
+ };
55345
+
55346
+ // restore
55347
+ var reassignListeners = function (target, map) {
55348
+ if (!target || !map) return;
55349
+ Object.keys(map).forEach(function (k) {
55350
+ target[k] = map[k];
55351
+ });
55352
+ };
55353
+
55324
55354
  // account settings
55325
55355
  var self = this;
55326
- this.service.ajax({
55327
- url: accountSettingsUrl
55328
- }, function (err, response) {
55329
- if (!err && typeof response === 'object') {
55330
- var update = {
55331
- endpoints: {
55332
- api: response.api_endpoint.replace(/^https?:\/\//, ''),
55333
- chat: response.chat_endpoint
55334
- }
55335
- };
55336
- config.set(update);
55337
- //
55338
- self.chat = new Chat(self.service);
55339
- self.chat.dialog = new DialogProxy(self.service);
55340
- self.chat.message = new MessageProxy(self.service);
55341
- //
55342
- if (Utils.getEnv().browser) {
55343
- /** add adapter.js*/
55344
- require('webrtc-adapter');
55345
-
55346
- /** add WebRTC API if API is avaible */
55347
- if( Utils.isWebRTCAvailble() ) {
55348
- var WebRTCClient = require('./modules/webrtc/qbWebRTCClient');
55349
- self.webrtc = new WebRTCClient(self.service, self.chat);
55356
+ //
55357
+ this._initReady = new Promise(function(resolve) {
55358
+ self.service.ajax({ url: accountSettingsUrl }, function (err, response) {
55359
+ // resolve in any case (so legacy clients won’t hang)
55360
+ if (!err && typeof response === 'object') {
55361
+ // 1) apply endpoints
55362
+ var update = {
55363
+ endpoints: {
55364
+ api: response.api_endpoint.replace(/^https?:\/\//, ''),
55365
+ chat: response.chat_endpoint
55366
+ }
55367
+ };
55368
+ config.set(update);
55369
+
55370
+ // 2) preserve ALL previously assigned listeners (dynamically)
55371
+ var savedChatListeners = preserveListeners(self.chat);
55372
+ var savedWebRTCListeners = preserveListeners(self.webrtc);
55373
+
55374
+ // 3) re-create dependent components for the new endpoints
55375
+ self.pushnotifications = new PushNotifications(self.service);
55376
+ self.chat = new Chat(self.service);
55377
+ self.chat.dialog = new DialogProxy(self.service);
55378
+ self.chat.message = new MessageProxy(self.service);
55379
+
55380
+ if (Utils.getEnv().browser) {
55381
+ require('webrtc-adapter');
55382
+ if (Utils.isWebRTCAvailble()) {
55383
+ var WebRTCClient = require('./modules/webrtc/qbWebRTCClient');
55384
+ self.webrtc = new WebRTCClient(self.service, self.chat);
55385
+ } else {
55386
+ self.webrtc = false;
55387
+ }
55350
55388
  } else {
55351
55389
  self.webrtc = false;
55352
55390
  }
55353
- } else {
55354
- self.webrtc = false;
55391
+
55392
+ // 4) reattach listeners to the new instances
55393
+ reassignListeners(self.chat, savedChatListeners);
55394
+ reassignListeners(self.webrtc, savedWebRTCListeners);
55355
55395
  }
55356
- //
55357
- }
55396
+
55397
+ resolve(); // init completed (with or without migration)
55398
+ });
55358
55399
  });
55400
+ //
55401
+ // previous version with callback
55402
+ // this.service.ajax({
55403
+ // url: accountSettingsUrl
55404
+ // }, function (err, response) {
55405
+ // if (!err && typeof response === 'object') {
55406
+ // var update = {
55407
+ // endpoints: {
55408
+ // api: response.api_endpoint.replace(/^https?:\/\//, ''),
55409
+ // chat: response.chat_endpoint
55410
+ // }
55411
+ // };
55412
+ // config.set(update);
55413
+ // //
55414
+ // self.pushnotifications = new PushNotifications(self.service);
55415
+ // self.chat = new Chat(self.service);
55416
+ // self.chat.dialog = new DialogProxy(self.service);
55417
+ // self.chat.message = new MessageProxy(self.service);
55418
+ // //
55419
+ // if (Utils.getEnv().browser) {
55420
+ // /** add adapter.js*/
55421
+ // require('webrtc-adapter');
55422
+ //
55423
+ // /** add WebRTC API if API is avaible */
55424
+ // if( Utils.isWebRTCAvailble() ) {
55425
+ // var WebRTCClient = require('./modules/webrtc/qbWebRTCClient');
55426
+ // self.webrtc = new WebRTCClient(self.service, self.chat);
55427
+ // } else {
55428
+ // self.webrtc = false;
55429
+ // }
55430
+ // } else {
55431
+ // self.webrtc = false;
55432
+ // }
55433
+ // //
55434
+ // }
55435
+ // });
55436
+ //
55437
+ }
55438
+ //
55439
+ // --- artificial sync delay to increase the chance account_settings completes before legacy code continues
55440
+ // enabled only when shouldGetSettings && config.initBlockOnSettings !== false
55441
+ if (shouldGetSettings && initBlockOnSettings) {
55442
+ try {
55443
+ var __qb_init_block_until__ = Date.now() + initBlockDurationMs;
55444
+ while (Date.now() < __qb_init_block_until__) {
55445
+ // intentional busy-wait (do not remove)
55446
+ }
55447
+ } catch (_) { /* never throw from here */ }
55359
55448
  }
55449
+ //
55450
+
55451
+ },
55452
+
55453
+ /**
55454
+ * Wait until SDK async initialization finishes (if any).
55455
+ * It resolves after internal tasks like fetching `account_settings`,
55456
+ * rebinding endpoints, and re-instantiating dependent modules are completed.
55457
+ * If no async work was scheduled during `QB.init(...)`, it resolves immediately.
55458
+ *
55459
+ * @memberof QB
55460
+ * @returns {Promise<void>} A promise that resolves when initialization is complete.
55461
+ *
55462
+ * @example
55463
+ * QB.init(appId, authKey, authSecret, accountKey, config);
55464
+ * QB.ready().then(function () {
55465
+ * // Safe point: endpoints are updated, chat/webrtc are re-created, listeners preserved.
55466
+ * QB.startSession({ login: 'john', password: 'secret' }, function (err, res) {
55467
+ * if (!err) {
55468
+ * QB.chat.connect({ userId: res.user.id, password: res.session.token }, function(){});
55469
+ * }
55470
+ * });
55471
+ * });
55472
+ */
55473
+ ready: function() {
55474
+ return this._initReady || Promise.resolve();
55360
55475
  },
55361
55476
 
55362
55477
  /**