Skip to content

Commit 45d3b38

Browse files
v2.21.0
1 parent 54a2999 commit 45d3b38

File tree

1,333 files changed

+256515
-181095
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,333 files changed

+256515
-181095
lines changed

quickblox-minus-h264.js

Lines changed: 52645 additions & 0 deletions
Large diffs are not rendered by default.

quickblox-recv-codecs.js

Lines changed: 52633 additions & 0 deletions
Large diffs are not rendered by default.

quickblox.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,13 @@ export declare interface QBConfig {
141141
) => void
142142
}
143143
pingTimeout?: number
144+
pingDebug?: boolean
144145
pingLocalhostTimeInterval?: number
145146
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
146151
}
147152

148153
export declare interface QBError {
@@ -1636,6 +1641,13 @@ export class QuickBlox {
16361641
config?: QBConfig,
16371642
): void
16381643

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+
16391651
/**
16401652
* Init QuickBlox SDK with User Account data to start session with token
16411653
* ([read more](https://docs.quickblox.com/docs/js-setup#initialize-quickblox-sdk-without-authorization-key-and-secret)).

quickblox.js

Lines changed: 266 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15129,8 +15129,10 @@ function isUndefined(arg) {
1512915129
}
1513015130

1513115131
},{}],80:[function(require,module,exports){
15132+
'use strict';
15133+
1513215134
/* eslint-env browser */
15133-
module.exports = typeof self == 'object' ? self.FormData : window.FormData;
15135+
module.exports = typeof self === 'object' ? self.FormData : window.FormData;
1513415136

1513515137
},{}],81:[function(require,module,exports){
1513615138
'use strict';
@@ -55078,8 +55080,8 @@ module.exports = StreamManagement;
5507855080
*/
5507955081

5508055082
var config = {
55081-
version: '2.20.0',
55082-
buildNumber: '1165',
55083+
version: '2.21.0',
55084+
buildNumber: '1167',
5508355085
creds: {
5508455086
'appId': 0,
5508555087
'authKey': '',
@@ -55101,6 +55103,9 @@ var config = {
5510155103
active: 2
5510255104
},
5510355105
pingTimeout: 1,
55106+
pingDebug: false,
55107+
initBlockOnSettings: false,
55108+
initBlockDurationMs: 3000,
5510455109
pingLocalhostTimeInterval: 5,
5510555110
chatReconnectionTimeInterval: 3,
5510655111
webrtc: {
@@ -55206,6 +55211,10 @@ module.exports = config;
5520655211
var config = require('./qbConfig');
5520755212
var Utils = require('./qbUtils');
5520855213
const MessageProxy = require("./modules/chat/qbMessage");
55214+
const Chat = require("./modules/chat/qbChat");
55215+
const DialogProxy = require("./modules/chat/qbDialog");
55216+
const WebRTCClient = require("./modules/webrtc/qbWebRTCClient");
55217+
const PushNotifications = require("./modules/qbPushNotifications");
5520955218

5521055219
// Actual QuickBlox API starts here
5521155220
function QuickBlox() {}
@@ -55290,6 +55299,10 @@ QuickBlox.prototype = {
5529055299
} else {
5529155300
this.webrtc = false;
5529255301
}
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+
5529355306

5529455307
// Initialization by outside token
5529555308
if (typeof appIdOrToken === 'string' && (!authKeyOrAppId || typeof authKeyOrAppId === 'number') && !authSecret) {
@@ -55317,21 +55330,148 @@ QuickBlox.prototype = {
5531755330
config.urls.account,
5531855331
config.urls.type
5531955332
].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+
5532055354
// account settings
55321-
this.service.ajax({
55322-
url: accountSettingsUrl
55323-
}, function (err, response) {
55324-
if (!err && typeof response === 'object') {
55325-
var update = {
55326-
endpoints: {
55327-
api: response.api_endpoint.replace(/^https?:\/\//, ''),
55328-
chat: response.chat_endpoint
55355+
var self = this;
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+
}
55388+
} else {
55389+
self.webrtc = false;
5532955390
}
55330-
};
55331-
config.set(update);
55332-
}
55391+
55392+
// 4) reattach listeners to the new instances
55393+
reassignListeners(self.chat, savedChatListeners);
55394+
reassignListeners(self.webrtc, savedWebRTCListeners);
55395+
}
55396+
55397+
resolve(); // init completed (with or without migration)
55398+
});
5533355399
});
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 */ }
5533455448
}
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();
5533555475
},
5533655476

5533755477
/**
@@ -55755,13 +55895,58 @@ ServiceProxy.prototype = {
5575555895

5575655896
self.handleResponse(null, body, callback, retry);
5575755897
}
55898+
// if (self._fetchingSettings) {
55899+
// self._fetchingSettings = false;
55900+
// while (self._queue.length) {
55901+
// var args = self._queue.shift();
55902+
// self.ajax.apply(self, args);
55903+
// }
55904+
// }
55905+
//
5575855906
if (self._fetchingSettings) {
5575955907
self._fetchingSettings = false;
55908+
55909+
var sharedApiHost = 'api.quickblox.com';
55910+
var sharedChatHost = 'chat.quickblox.com';
55911+
55912+
sharedApiHost = sharedApiHost.replace(/^https?:\/\//i, '').replace(/\/+$/, '');
55913+
sharedChatHost = sharedChatHost.replace(/^https?:\/\//i, '').replace(/\/+$/, '');
55914+
55915+
var RE_SHARED_API = new RegExp('^https?://' + sharedApiHost.replace(/\./g, '\\.') + '(?=[:/]|$)', 'i');
55916+
var RE_SHARED_CHAT = new RegExp('^https?://' + sharedChatHost.replace(/\./g, '\\.') + '(?=[:/]|$)', 'i');
55917+
55918+
var newApiHost = (self.qbInst.config.endpoints.api || '').replace(/^https?:\/\//i, '').replace(/\/+$/, '');
55919+
var newChatHost = (self.qbInst.config.endpoints.chat || '').replace(/^https?:\/\//i, '').replace(/\/+$/, '');
55920+
var NEW_API_URL = 'https://' + newApiHost;
55921+
var NEW_CHAT_URL = 'https://' + newChatHost;
55922+
5576055923
while (self._queue.length) {
55761-
var args = self._queue.shift();
55924+
var args = self._queue.shift(); // [params, callback]
55925+
var p = args && args[0];
55926+
55927+
if (p && typeof p.url === 'string') {
55928+
var url = p.url;
55929+
var changed = false;
55930+
55931+
if (RE_SHARED_API.test(url)) {
55932+
url = url.replace(RE_SHARED_API, NEW_API_URL);
55933+
changed = true;
55934+
}
55935+
if (RE_SHARED_CHAT.test(url)) {
55936+
url = url.replace(RE_SHARED_CHAT, NEW_CHAT_URL);
55937+
changed = true;
55938+
}
55939+
55940+
if (changed) {
55941+
p.url = url;
55942+
}
55943+
}
55944+
5576255945
self.ajax.apply(self, args);
5576355946
}
5576455947
}
55948+
55949+
//
5576555950
}
5576655951

5576755952
function retry(session) {
@@ -56029,9 +56214,68 @@ var Utils = {
5602956214
},
5603056215

5603156216
QBLog: function(){
56217+
var argsArr = Array.prototype.slice.call(arguments);
56218+
56219+
function containsPing(x) {
56220+
var needle = 'ping';
56221+
56222+
try {
56223+
if (x == null) return false;
56224+
56225+
if (typeof x === 'string') {
56226+
return x.toLowerCase().indexOf(needle) !== -1;
56227+
}
56228+
56229+
if (typeof x === 'number' || typeof x === 'boolean') {
56230+
return false;
56231+
}
56232+
56233+
if (typeof x === 'object') {
56234+
//DELETE XEP-0198 SM packages from log:
56235+
// <r xmlns="urn:xmpp:sm:3"/> and <a xmlns="urn:xmpp:sm:3" h="..."/>
56236+
if (typeof x.outerHTML === 'string') {
56237+
var oh = x.outerHTML.replace(/\s+/g, ' ').toLowerCase();
56238+
if (
56239+
oh.indexOf('urn:xmpp:sm:3') !== -1 &&
56240+
(/^<\s*r\b/.test(oh) || /^<\s*a\b/.test(oh))
56241+
) {
56242+
return true;
56243+
}
56244+
}
56245+
56246+
var candidates = [
56247+
x.textContent,
56248+
x.innerHTML,
56249+
x.outerHTML,
56250+
x.nodeName,
56251+
x.tagName,
56252+
x.id
56253+
];
56254+
56255+
for (var j = 0; j < candidates.length; j++) {
56256+
var s = candidates[j];
56257+
if (typeof s === 'string' && s.toLowerCase().indexOf(needle) !== -1) {
56258+
return true;
56259+
}
56260+
}
56261+
}
56262+
} catch (_) {}
56263+
56264+
return false;
56265+
}
56266+
56267+
56268+
let shouldSuppressPing1 =
56269+
config && config.pingDebug === false;
56270+
let shouldSuppressPing2 =argsArr.some(containsPing);
56271+
56272+
let shouldSuppressPing = shouldSuppressPing1 && shouldSuppressPing2;
56273+
5603256274
if (this.loggers) {
5603356275
for (var i=0; i<this.loggers.length; ++i) {
56034-
this.loggers[i](arguments);
56276+
if (!shouldSuppressPing) {
56277+
this.loggers[i](arguments);
56278+
}
5603556279
}
5603656280

5603756281
return;
@@ -56112,7 +56356,12 @@ var Utils = {
5611256356

5611356357
if(this.loggers){
5611456358
for(var j=0;j<this.loggers.length;++j){
56115-
this.loggers[j](arguments);
56359+
// this.loggers[j](arguments);
56360+
//
56361+
if (!shouldSuppressPing) {
56362+
this.loggers[j](arguments);
56363+
}
56364+
//
5611656365
}
5611756366
}
5611856367
},

quickblox.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/chat/js/QBconfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var QBconfig = {
1717
enable: true
1818
},
1919
debug: true,
20+
pingDebug: true,
2021
callBackInterval: 30,
2122
},
2223
};

0 commit comments

Comments
 (0)