Skip to content

Commit

Permalink
SDK version updated to 2.12.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksandr Shvetsov committed Aug 11, 2020
1 parent 26c5441 commit 2b97209
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Check out our [API Reference](https://quickblox.github.io/quickblox-javascript-s
## Dependencies for browser

```html
<script src="https://unpkg.com/quickblox@2.12.8/quickblox.min.js"></script>
<script src="https://unpkg.com/quickblox@2.12.9/quickblox.min.js"></script>
```

## Bower and RequireJS
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "quickblox",
"description": "QuickBlox JavaScript SDK",
"version": "2.12.8",
"version": "2.12.9",
"homepage": "https://quickblox.com/developers/Javascript",
"main": "src/qbMain.js",
"license": "(Apache-2.0)",
Expand Down
83 changes: 75 additions & 8 deletions quickblox.js
Original file line number Diff line number Diff line change
Expand Up @@ -38202,7 +38202,7 @@ function ChatProxy(service) {
this._isLogout = false;

this._checkConnectionTimer = undefined;

this._pings = {};
//
this.helpers = new Helpers();
//
Expand Down Expand Up @@ -38680,18 +38680,46 @@ function ChatProxy(service) {
};

this._onIQ = function(stanza) {
var stanzaId = chatUtils.getAttr(stanza, 'id'),
isLastActivity = stanzaId.indexOf('lastActivity') > -1;
var stanzaId = chatUtils.getAttr(stanza, 'id');
var isLastActivity = stanzaId.indexOf('lastActivity') > -1;
var isPong = stanzaId.indexOf('ping') > -1;
var ping = chatUtils.getElement(stanza, 'ping');
var type = chatUtils.getAttr(stanza, 'type');
var from = chatUtils.getAttr(stanza, 'from');
var userId = from ?
self.helpers.getIdFromNode(from) :
null;

if (typeof self.onLastUserActivityListener === 'function' && isLastActivity) {
var from = chatUtils.getAttr(stanza, 'from'),
userId = self.helpers.getIdFromNode(from),
query = chatUtils.getElement(stanza, 'query'),
var query = chatUtils.getElement(stanza, 'query'),
error = chatUtils.getElement(stanza, 'error'),
seconds = error ? undefined : +chatUtils.getAttr(query, 'seconds');

Utils.safeCallbackCall(self.onLastUserActivityListener, userId, seconds);
}
if ((ping || isPong) && type) {
if (type === 'get' && ping) {
// pong
self.connection.send($iq({
from: self.helpers.getUserCurrentJid(),
id: stanzaId,
to: chatUtils.getAttr(stanza, 'from'),
type: 'result'
}));
} else {
var pingRequest = self._pings[stanzaId];
if (pingRequest) {
if (pingRequest.callback) {
pingRequest.callback(null);
}
if (pingRequest.interval) {
clearInterval(pingRequest.interval);
}
self._pings[stanzaId] = undefined;
delete self._pings[stanzaId];
}
}
}

if (!Utils.getEnv().browser) {
if (self.nodeStanzasCallbacks[stanzaId]) {
Expand Down Expand Up @@ -39321,6 +39349,44 @@ ChatProxy.prototype = {
}
},

ping: function (jid_or_user_id, callback) {
var self = this;
var id = this.helpers.getUniqueId('ping');
var to;
var _callback;
if ((typeof jid_or_user_id === 'string' ||
typeof jid_or_user_id === 'number') &&
typeof callback === 'function') {
to = this.helpers.jidOrUserId(jid_or_user_id);
_callback = callback;
} else {
if (typeof jid_or_user_id === 'function' && !callback) {
to = config.endpoints.chat;
_callback = jid_or_user_id;
} else {
throw new Error('Invalid arguments provided. Either userId/jid (number/string) and callback or only callback should be provided.');
}
}
var iqParams = {
from: this.helpers.getUserCurrentJid(),
id: id,
to: to,
type: 'get'
};
var stanza = $iq(iqParams).c('ping', { xmlns: "urn:xmpp:ping" });
var noAnswer = function () {
_callback('No answer');
self._pings[id] = undefined;
delete self._pings[id];
};
this.connection.send(stanza);
this._pings[id] = {
callback: _callback,
interval: setTimeout(noAnswer, config.pingTimeout * 1000)
};
return id;
},

/**
* Logout from the Chat. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Logout_from_Chat More info.}
* @memberof QB.chat
Expand Down Expand Up @@ -45585,8 +45651,8 @@ module.exports = StreamManagement;
*/

var config = {
version: '2.12.8',
buildNumber: '1086',
version: '2.12.9',
buildNumber: '1087',
creds: {
appId: '',
authKey: '',
Expand All @@ -45606,6 +45672,7 @@ var config = {
websocket: 'wss://chat.quickblox.com:5291',
active: 2
},
pingTimeout: 30,
chatReconnectionTimeInterval: 5,
webrtc: {
answerTimeInterval: 60,
Expand Down
2 changes: 1 addition & 1 deletion quickblox.min.js

Large diffs are not rendered by default.

78 changes: 72 additions & 6 deletions src/modules/chat/qbChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function ChatProxy(service) {
this._isLogout = false;

this._checkConnectionTimer = undefined;

this._pings = {};
//
this.helpers = new Helpers();
//
Expand Down Expand Up @@ -564,18 +564,46 @@ function ChatProxy(service) {
};

this._onIQ = function(stanza) {
var stanzaId = chatUtils.getAttr(stanza, 'id'),
isLastActivity = stanzaId.indexOf('lastActivity') > -1;
var stanzaId = chatUtils.getAttr(stanza, 'id');
var isLastActivity = stanzaId.indexOf('lastActivity') > -1;
var isPong = stanzaId.indexOf('ping') > -1;
var ping = chatUtils.getElement(stanza, 'ping');
var type = chatUtils.getAttr(stanza, 'type');
var from = chatUtils.getAttr(stanza, 'from');
var userId = from ?
self.helpers.getIdFromNode(from) :
null;

if (typeof self.onLastUserActivityListener === 'function' && isLastActivity) {
var from = chatUtils.getAttr(stanza, 'from'),
userId = self.helpers.getIdFromNode(from),
query = chatUtils.getElement(stanza, 'query'),
var query = chatUtils.getElement(stanza, 'query'),
error = chatUtils.getElement(stanza, 'error'),
seconds = error ? undefined : +chatUtils.getAttr(query, 'seconds');

Utils.safeCallbackCall(self.onLastUserActivityListener, userId, seconds);
}
if ((ping || isPong) && type) {
if (type === 'get' && ping) {
// pong
self.connection.send($iq({
from: self.helpers.getUserCurrentJid(),
id: stanzaId,
to: chatUtils.getAttr(stanza, 'from'),
type: 'result'
}));
} else {
var pingRequest = self._pings[stanzaId];
if (pingRequest) {
if (pingRequest.callback) {
pingRequest.callback(null);
}
if (pingRequest.interval) {
clearInterval(pingRequest.interval);
}
self._pings[stanzaId] = undefined;
delete self._pings[stanzaId];
}
}
}

if (!Utils.getEnv().browser) {
if (self.nodeStanzasCallbacks[stanzaId]) {
Expand Down Expand Up @@ -1205,6 +1233,44 @@ ChatProxy.prototype = {
}
},

ping: function (jid_or_user_id, callback) {
var self = this;
var id = this.helpers.getUniqueId('ping');
var to;
var _callback;
if ((typeof jid_or_user_id === 'string' ||
typeof jid_or_user_id === 'number') &&
typeof callback === 'function') {
to = this.helpers.jidOrUserId(jid_or_user_id);
_callback = callback;
} else {
if (typeof jid_or_user_id === 'function' && !callback) {
to = config.endpoints.chat;
_callback = jid_or_user_id;
} else {
throw new Error('Invalid arguments provided. Either userId/jid (number/string) and callback or only callback should be provided.');
}
}
var iqParams = {
from: this.helpers.getUserCurrentJid(),
id: id,
to: to,
type: 'get'
};
var stanza = $iq(iqParams).c('ping', { xmlns: "urn:xmpp:ping" });
var noAnswer = function () {
_callback('No answer');
self._pings[id] = undefined;
delete self._pings[id];
};
this.connection.send(stanza);
this._pings[id] = {
callback: _callback,
interval: setTimeout(noAnswer, config.pingTimeout * 1000)
};
return id;
},

/**
* Logout from the Chat. {@link https://quickblox.com/developers/Web_XMPP_Chat_Sample#Logout_from_Chat More info.}
* @memberof QB.chat
Expand Down
5 changes: 3 additions & 2 deletions src/qbConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*/

var config = {
version: '2.12.8',
buildNumber: '1086',
version: '2.12.9',
buildNumber: '1087',
creds: {
appId: '',
authKey: '',
Expand All @@ -33,6 +33,7 @@ var config = {
websocket: 'wss://chat.quickblox.com:5291',
active: 2
},
pingTimeout: 30,
chatReconnectionTimeInterval: 5,
webrtc: {
answerTimeInterval: 60,
Expand Down

0 comments on commit 2b97209

Please sign in to comment.