Skip to content

Commit 2b97209

Browse files
author
Oleksandr Shvetsov
committed
SDK version updated to 2.12.9
1 parent 26c5441 commit 2b97209

File tree

7 files changed

+154
-20
lines changed

7 files changed

+154
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Check out our [API Reference](https://quickblox.github.io/quickblox-javascript-s
1616
## Dependencies for browser
1717

1818
```html
19-
<script src="https://unpkg.com/[email protected].8/quickblox.min.js"></script>
19+
<script src="https://unpkg.com/[email protected].9/quickblox.min.js"></script>
2020
```
2121

2222
## Bower and RequireJS

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "quickblox",
33
"description": "QuickBlox JavaScript SDK",
4-
"version": "2.12.8",
4+
"version": "2.12.9",
55
"homepage": "https://quickblox.com/developers/Javascript",
66
"main": "src/qbMain.js",
77
"license": "(Apache-2.0)",

quickblox.js

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38202,7 +38202,7 @@ function ChatProxy(service) {
3820238202
this._isLogout = false;
3820338203

3820438204
this._checkConnectionTimer = undefined;
38205-
38205+
this._pings = {};
3820638206
//
3820738207
this.helpers = new Helpers();
3820838208
//
@@ -38680,18 +38680,46 @@ function ChatProxy(service) {
3868038680
};
3868138681

3868238682
this._onIQ = function(stanza) {
38683-
var stanzaId = chatUtils.getAttr(stanza, 'id'),
38684-
isLastActivity = stanzaId.indexOf('lastActivity') > -1;
38683+
var stanzaId = chatUtils.getAttr(stanza, 'id');
38684+
var isLastActivity = stanzaId.indexOf('lastActivity') > -1;
38685+
var isPong = stanzaId.indexOf('ping') > -1;
38686+
var ping = chatUtils.getElement(stanza, 'ping');
38687+
var type = chatUtils.getAttr(stanza, 'type');
38688+
var from = chatUtils.getAttr(stanza, 'from');
38689+
var userId = from ?
38690+
self.helpers.getIdFromNode(from) :
38691+
null;
3868538692

3868638693
if (typeof self.onLastUserActivityListener === 'function' && isLastActivity) {
38687-
var from = chatUtils.getAttr(stanza, 'from'),
38688-
userId = self.helpers.getIdFromNode(from),
38689-
query = chatUtils.getElement(stanza, 'query'),
38694+
var query = chatUtils.getElement(stanza, 'query'),
3869038695
error = chatUtils.getElement(stanza, 'error'),
3869138696
seconds = error ? undefined : +chatUtils.getAttr(query, 'seconds');
3869238697

3869338698
Utils.safeCallbackCall(self.onLastUserActivityListener, userId, seconds);
3869438699
}
38700+
if ((ping || isPong) && type) {
38701+
if (type === 'get' && ping) {
38702+
// pong
38703+
self.connection.send($iq({
38704+
from: self.helpers.getUserCurrentJid(),
38705+
id: stanzaId,
38706+
to: chatUtils.getAttr(stanza, 'from'),
38707+
type: 'result'
38708+
}));
38709+
} else {
38710+
var pingRequest = self._pings[stanzaId];
38711+
if (pingRequest) {
38712+
if (pingRequest.callback) {
38713+
pingRequest.callback(null);
38714+
}
38715+
if (pingRequest.interval) {
38716+
clearInterval(pingRequest.interval);
38717+
}
38718+
self._pings[stanzaId] = undefined;
38719+
delete self._pings[stanzaId];
38720+
}
38721+
}
38722+
}
3869538723

3869638724
if (!Utils.getEnv().browser) {
3869738725
if (self.nodeStanzasCallbacks[stanzaId]) {
@@ -39321,6 +39349,44 @@ ChatProxy.prototype = {
3932139349
}
3932239350
},
3932339351

39352+
ping: function (jid_or_user_id, callback) {
39353+
var self = this;
39354+
var id = this.helpers.getUniqueId('ping');
39355+
var to;
39356+
var _callback;
39357+
if ((typeof jid_or_user_id === 'string' ||
39358+
typeof jid_or_user_id === 'number') &&
39359+
typeof callback === 'function') {
39360+
to = this.helpers.jidOrUserId(jid_or_user_id);
39361+
_callback = callback;
39362+
} else {
39363+
if (typeof jid_or_user_id === 'function' && !callback) {
39364+
to = config.endpoints.chat;
39365+
_callback = jid_or_user_id;
39366+
} else {
39367+
throw new Error('Invalid arguments provided. Either userId/jid (number/string) and callback or only callback should be provided.');
39368+
}
39369+
}
39370+
var iqParams = {
39371+
from: this.helpers.getUserCurrentJid(),
39372+
id: id,
39373+
to: to,
39374+
type: 'get'
39375+
};
39376+
var stanza = $iq(iqParams).c('ping', { xmlns: "urn:xmpp:ping" });
39377+
var noAnswer = function () {
39378+
_callback('No answer');
39379+
self._pings[id] = undefined;
39380+
delete self._pings[id];
39381+
};
39382+
this.connection.send(stanza);
39383+
this._pings[id] = {
39384+
callback: _callback,
39385+
interval: setTimeout(noAnswer, config.pingTimeout * 1000)
39386+
};
39387+
return id;
39388+
},
39389+
3932439390
/**
3932539391
* Logout from the Chat. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Logout_from_Chat More info.}
3932639392
* @memberof QB.chat
@@ -45585,8 +45651,8 @@ module.exports = StreamManagement;
4558545651
*/
4558645652

4558745653
var config = {
45588-
version: '2.12.8',
45589-
buildNumber: '1086',
45654+
version: '2.12.9',
45655+
buildNumber: '1087',
4559045656
creds: {
4559145657
appId: '',
4559245658
authKey: '',
@@ -45606,6 +45672,7 @@ var config = {
4560645672
websocket: 'wss://chat.quickblox.com:5291',
4560745673
active: 2
4560845674
},
45675+
pingTimeout: 30,
4560945676
chatReconnectionTimeInterval: 5,
4561045677
webrtc: {
4561145678
answerTimeInterval: 60,

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.

src/modules/chat/qbChat.js

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function ChatProxy(service) {
8686
this._isLogout = false;
8787

8888
this._checkConnectionTimer = undefined;
89-
89+
this._pings = {};
9090
//
9191
this.helpers = new Helpers();
9292
//
@@ -564,18 +564,46 @@ function ChatProxy(service) {
564564
};
565565

566566
this._onIQ = function(stanza) {
567-
var stanzaId = chatUtils.getAttr(stanza, 'id'),
568-
isLastActivity = stanzaId.indexOf('lastActivity') > -1;
567+
var stanzaId = chatUtils.getAttr(stanza, 'id');
568+
var isLastActivity = stanzaId.indexOf('lastActivity') > -1;
569+
var isPong = stanzaId.indexOf('ping') > -1;
570+
var ping = chatUtils.getElement(stanza, 'ping');
571+
var type = chatUtils.getAttr(stanza, 'type');
572+
var from = chatUtils.getAttr(stanza, 'from');
573+
var userId = from ?
574+
self.helpers.getIdFromNode(from) :
575+
null;
569576

570577
if (typeof self.onLastUserActivityListener === 'function' && isLastActivity) {
571-
var from = chatUtils.getAttr(stanza, 'from'),
572-
userId = self.helpers.getIdFromNode(from),
573-
query = chatUtils.getElement(stanza, 'query'),
578+
var query = chatUtils.getElement(stanza, 'query'),
574579
error = chatUtils.getElement(stanza, 'error'),
575580
seconds = error ? undefined : +chatUtils.getAttr(query, 'seconds');
576581

577582
Utils.safeCallbackCall(self.onLastUserActivityListener, userId, seconds);
578583
}
584+
if ((ping || isPong) && type) {
585+
if (type === 'get' && ping) {
586+
// pong
587+
self.connection.send($iq({
588+
from: self.helpers.getUserCurrentJid(),
589+
id: stanzaId,
590+
to: chatUtils.getAttr(stanza, 'from'),
591+
type: 'result'
592+
}));
593+
} else {
594+
var pingRequest = self._pings[stanzaId];
595+
if (pingRequest) {
596+
if (pingRequest.callback) {
597+
pingRequest.callback(null);
598+
}
599+
if (pingRequest.interval) {
600+
clearInterval(pingRequest.interval);
601+
}
602+
self._pings[stanzaId] = undefined;
603+
delete self._pings[stanzaId];
604+
}
605+
}
606+
}
579607

580608
if (!Utils.getEnv().browser) {
581609
if (self.nodeStanzasCallbacks[stanzaId]) {
@@ -1205,6 +1233,44 @@ ChatProxy.prototype = {
12051233
}
12061234
},
12071235

1236+
ping: function (jid_or_user_id, callback) {
1237+
var self = this;
1238+
var id = this.helpers.getUniqueId('ping');
1239+
var to;
1240+
var _callback;
1241+
if ((typeof jid_or_user_id === 'string' ||
1242+
typeof jid_or_user_id === 'number') &&
1243+
typeof callback === 'function') {
1244+
to = this.helpers.jidOrUserId(jid_or_user_id);
1245+
_callback = callback;
1246+
} else {
1247+
if (typeof jid_or_user_id === 'function' && !callback) {
1248+
to = config.endpoints.chat;
1249+
_callback = jid_or_user_id;
1250+
} else {
1251+
throw new Error('Invalid arguments provided. Either userId/jid (number/string) and callback or only callback should be provided.');
1252+
}
1253+
}
1254+
var iqParams = {
1255+
from: this.helpers.getUserCurrentJid(),
1256+
id: id,
1257+
to: to,
1258+
type: 'get'
1259+
};
1260+
var stanza = $iq(iqParams).c('ping', { xmlns: "urn:xmpp:ping" });
1261+
var noAnswer = function () {
1262+
_callback('No answer');
1263+
self._pings[id] = undefined;
1264+
delete self._pings[id];
1265+
};
1266+
this.connection.send(stanza);
1267+
this._pings[id] = {
1268+
callback: _callback,
1269+
interval: setTimeout(noAnswer, config.pingTimeout * 1000)
1270+
};
1271+
return id;
1272+
},
1273+
12081274
/**
12091275
* Logout from the Chat. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Logout_from_Chat More info.}
12101276
* @memberof QB.chat

src/qbConfig.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
*/
1313

1414
var config = {
15-
version: '2.12.8',
16-
buildNumber: '1086',
15+
version: '2.12.9',
16+
buildNumber: '1087',
1717
creds: {
1818
appId: '',
1919
authKey: '',
@@ -33,6 +33,7 @@ var config = {
3333
websocket: 'wss://chat.quickblox.com:5291',
3434
active: 2
3535
},
36+
pingTimeout: 30,
3637
chatReconnectionTimeInterval: 5,
3738
webrtc: {
3839
answerTimeInterval: 60,

0 commit comments

Comments
 (0)