Skip to content

Commit 41499ef

Browse files
committed
Merge pull request #116 from QuickBlox/develop
for v2.0.5
2 parents b9e2a73 + f42b1d9 commit 41499ef

File tree

12 files changed

+309
-141
lines changed

12 files changed

+309
-141
lines changed

.bowerrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

bower.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.0.4",
4+
"version": "2.1.0",
55
"homepage": "http://quickblox.com/developers/Javascript",
66
"main": "quickblox.js",
77
"license": "MIT",

js/modules/qbChat.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -328,22 +328,22 @@ ChatProxy.prototype = {
328328

329329
switch (status) {
330330
case Strophe.Status.ERROR:
331-
err = getError(422, 'Status.ERROR - An error has occurred');
331+
err = Utils.getError(422, 'Status.ERROR - An error has occurred');
332332
if (typeof callback === 'function') callback(err, null);
333333
break;
334334
case Strophe.Status.CONNECTING:
335335
Utils.QBLog('[ChatProxy]', 'Status.CONNECTING');
336336
Utils.QBLog('[ChatProxy]', 'Chat Protocol - ' + (config.chatProtocol.active === 1 ? 'BOSH' : 'WebSocket'));
337337
break;
338338
case Strophe.Status.CONNFAIL:
339-
err = getError(422, 'Status.CONNFAIL - The connection attempt failed');
339+
err = Utils.getError(422, 'Status.CONNFAIL - The connection attempt failed');
340340
if (typeof callback === 'function') callback(err, null);
341341
break;
342342
case Strophe.Status.AUTHENTICATING:
343343
Utils.QBLog('[ChatProxy]', 'Status.AUTHENTICATING');
344344
break;
345345
case Strophe.Status.AUTHFAIL:
346-
err = getError(401, 'Status.AUTHFAIL - The authentication attempt failed');
346+
err = Utils.getError(401, 'Status.AUTHFAIL - The authentication attempt failed');
347347
if (typeof callback === 'function') callback(err, null);
348348
break;
349349
case Strophe.Status.CONNECTED:
@@ -1001,7 +1001,7 @@ PrivacyListProxy.prototype = {
10011001
var errorObject = getErrorFromXMLNode(stanzaError);
10021002
callback(errorObject, null);
10031003
}else{
1004-
callback(getError(408), null);
1004+
callback(Utils.getError(408), null);
10051005
}
10061006
});
10071007
},
@@ -1041,7 +1041,7 @@ PrivacyListProxy.prototype = {
10411041
var errorObject = getErrorFromXMLNode(stanzaError);
10421042
callback(errorObject, null);
10431043
}else{
1044-
callback(getError(408), null);
1044+
callback(Utils.getError(408), null);
10451045
}
10461046
});
10471047
},
@@ -1105,7 +1105,7 @@ PrivacyListProxy.prototype = {
11051105
var errorObject = getErrorFromXMLNode(stanzaError);
11061106
callback(errorObject);
11071107
}else{
1108-
callback(getError(408));
1108+
callback(Utils.getError(408));
11091109
}
11101110
});
11111111
},
@@ -1154,7 +1154,7 @@ PrivacyListProxy.prototype = {
11541154
var errorObject = getErrorFromXMLNode(stanzaError);
11551155
callback(errorObject);
11561156
}else{
1157-
callback(getError(408));
1157+
callback(Utils.getError(408));
11581158
}
11591159
});
11601160
},
@@ -1177,7 +1177,7 @@ PrivacyListProxy.prototype = {
11771177
var errorObject = getErrorFromXMLNode(stanzaError);
11781178
callback(errorObject);
11791179
}else{
1180-
callback(getError(408));
1180+
callback(Utils.getError(408));
11811181
}
11821182
});
11831183
},
@@ -1200,7 +1200,7 @@ PrivacyListProxy.prototype = {
12001200
var errorObject = getErrorFromXMLNode(stanzaError);
12011201
callback(errorObject);
12021202
}else{
1203-
callback(getError(408));
1203+
callback(Utils.getError(408));
12041204
}
12051205
});
12061206
}
@@ -1407,7 +1407,7 @@ function getErrorFromXMLNode(stanzaError) {
14071407
var errorElement = stanzaError.getElementsByTagName('error')[0];
14081408
var errorCode = parseInt(errorElement.getAttribute('code'));
14091409
var errorText = errorElement.getElementsByTagName('text')[0].textContent;
1410-
return getError(errorCode, errorText);
1410+
return Utils.getError(errorCode, errorText);
14111411
}
14121412

14131413
function getLocalTime() {

js/modules/webrtc/qbRTCPeerConnection.js

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ RTCPeerConnection.prototype.init = function(delegate, userID, sessionID, type) {
4545
/** We use this timer interval to dial a user - produce the call requests each N seconds. */
4646
this.dialingTimer = null;
4747
this.answerTimeInterval = 0;
48+
this.statsReportTimer = null;
4849

4950
/** timer to detect network blips */
5051
this.reconnectTimer = 0;
@@ -54,6 +55,7 @@ RTCPeerConnection.prototype.init = function(delegate, userID, sessionID, type) {
5455

5556
RTCPeerConnection.prototype.release = function(){
5657
this._clearDialingTimer();
58+
this._clearStatsReportTimer();
5759

5860
if(this.signalingState !== 'closed'){
5961
this.close();
@@ -174,16 +176,19 @@ RTCPeerConnection.prototype.onIceCandidateCallback = function(event) {
174176

175177
/** handler of remote media stream */
176178
RTCPeerConnection.prototype.onAddRemoteStreamCallback = function(event) {
179+
var self = this;
180+
177181
if (typeof this.delegate._onRemoteStreamListener === 'function'){
178182
this.delegate._onRemoteStreamListener(this.userID, event.stream);
179183
}
184+
185+
self._getStatsWrap();
180186
};
181187

182188
RTCPeerConnection.prototype.onIceConnectionStateCallback = function() {
183189
var newIceConnectionState = this.iceConnectionState;
184-
185-
Helpers.trace("onIceConnectionStateCallback: " + this.iceConnectionState);
186190

191+
Helpers.trace("onIceConnectionStateCallback: " + this.iceConnectionState);
187192

188193
/**
189194
* read more about all states:
@@ -226,6 +231,45 @@ RTCPeerConnection.prototype.onIceConnectionStateCallback = function() {
226231
/**
227232
* PRIVATE
228233
*/
234+
RTCPeerConnection.prototype._clearStatsReportTimer = function(){
235+
if(this.statsReportTimer){
236+
clearInterval(this.statsReportTimer);
237+
this.statsReportTimer = null;
238+
}
239+
};
240+
241+
RTCPeerConnection.prototype._getStatsWrap = function() {
242+
var self = this,
243+
selector = self.delegate.callType == 1 ? self.getLocalStreams()[0].getVideoTracks()[0] : self.getLocalStreams()[0].getAudioTracks()[0],
244+
statsReportInterval;
245+
246+
if (!config.webrtc && !config.webrtc.statsReportTimeInterval) {
247+
return;
248+
}
249+
250+
if (isNaN(+config.webrtc.statsReportTimeInterval)) {
251+
Helpers.traceError('statsReportTimeInterval (' + config.webrtc.statsReportTimeInterval + ') must be integer.');
252+
return;
253+
}
254+
255+
statsReportInterval = config.webrtc.statsReportTimeInterval * 1000;
256+
257+
var _statsReportCallback = function() {
258+
_getStats(self, selector,
259+
function (results) {
260+
self.delegate._onCallStatsReport(self.userID, results);
261+
},
262+
function errorLog(err) {
263+
Helpers.traceError("_getStats error. " + err.name + ": " + err.message);
264+
}
265+
);
266+
};
267+
268+
Helpers.trace('Stats tracker has been started.');
269+
270+
self.statsReportTimer = setInterval(_statsReportCallback, statsReportInterval);
271+
};
272+
229273
RTCPeerConnection.prototype._clearWaitingReconnectTimer = function() {
230274
if(this.waitingReconnectTimeoutCallback){
231275
Helpers.trace('_clearWaitingReconnectTimer');
@@ -292,4 +336,40 @@ RTCPeerConnection.prototype._startDialingTimer = function(extension, withOnNotAn
292336
_dialingCallback(extension, withOnNotAnswerCallback, true);
293337
};
294338

295-
module.exports = RTCPeerConnection;
339+
/**
340+
* PRIVATE
341+
*/
342+
function _getStats(peer, selector, successCallback, errorCallback) {
343+
/**
344+
* http://stackoverflow.com/questions/25069419/webrtc-getstat-api-set-up
345+
*/
346+
if (navigator.mozGetUserMedia) {
347+
peer.getStats(selector,
348+
function (res) {
349+
var items = [];
350+
res.forEach(function (result) {
351+
items.push(result);
352+
});
353+
successCallback(items);
354+
},
355+
errorCallback
356+
);
357+
} else {
358+
peer.getStats(function (res) {
359+
var items = [];
360+
res.result().forEach(function (result) {
361+
var item = {};
362+
result.names().forEach(function (name) {
363+
item[name] = result.stat(name);
364+
});
365+
item.id = result.id;
366+
item.type = result.type;
367+
item.timestamp = result.timestamp;
368+
items.push(item);
369+
});
370+
successCallback(items);
371+
});
372+
}
373+
}
374+
375+
module.exports = RTCPeerConnection;

js/modules/webrtc/qbWebRTCClient.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ WebRTCClient.prototype._createAndStoreSession = function(sessionID, callerID, op
8080
newSession.onRemoteStreamListener = this.onRemoteStreamListener;
8181
newSession.onSessionConnectionStateChangedListener = this.onSessionConnectionStateChangedListener;
8282
newSession.onSessionCloseListener = this.onSessionCloseListener;
83+
newSession.onCallStatsReport = this.onCallStatsReport;
8384

8485
this.sessions[newSession.ID] = newSession;
8586
return newSession;

js/modules/webrtc/qbWebRTCSession.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* - onRemoteStreamListener(session, userID, stream)
1010
* - onSessionConnectionStateChangedListener(session, userID, connectionState)
1111
* - onSessionCloseListener(session)
12+
* - onCallStatsReport(session, userId, stats)
1213
*/
1314

1415
var config = require('../../qbConfig');
@@ -360,6 +361,24 @@ WebRTCSession.prototype.stop = function(extension) {
360361
self._close();
361362
};
362363

364+
/**
365+
* [function close connection with user]
366+
* @param {[type]} userId [id of user]
367+
*/
368+
WebRTCSession.prototype.closeConnection = function(userId) {
369+
var self = this,
370+
peer = this.peerConnections[userId];
371+
372+
if(peer) {
373+
peer.release();
374+
375+
self._closeSessionIfAllConnectionsClosed();
376+
} else {
377+
Helpers.traceWarn('Not found connection with user (' + userId + ')');
378+
}
379+
};
380+
381+
363382
/**
364383
* Update a call
365384
* @param {array} A map with custom parameters
@@ -594,6 +613,12 @@ WebRTCSession.prototype._onRemoteStreamListener = function(userID, stream) {
594613
}
595614
};
596615

616+
WebRTCSession.prototype._onCallStatsReport = function(userId, stats) {
617+
if (typeof this.onCallStatsReport === 'function'){
618+
Utils.safeCallbackCall(this.onCallStatsReport, this, userId, stats);
619+
}
620+
};
621+
597622
WebRTCSession.prototype._onSessionConnectionStateChangedListener = function(userID, connectionState) {
598623
var self = this;
599624

js/qbConfig.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
*
44
* Configuration Module
55
*
6+
* NOTE:
7+
* - config.webrtc.statsReportTimeInterval [integer, sec]:
8+
* could add listener onCallStatsReport(session, userId, bytesReceived) if
9+
* want to get stats (bytesReceived) about peer every X sec;
610
*/
711

812
var config = {
9-
version: '2.0.4',
13+
version: '2.1.0',
1014
creds: {
1115
appId: '',
1216
authKey: '',
@@ -26,6 +30,7 @@ var config = {
2630
answerTimeInterval: 60,
2731
dialingTimeInterval: 5,
2832
disconnectTimeInterval: 30,
33+
statsReportTimeInterval: 10,
2934
iceServers: [
3035
{
3136
'url': 'stun:stun.l.google.com:19302'

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "quickblox",
33
"description": "QuickBlox JavaScript SDK",
4-
"version": "2.0.4",
4+
"version": "2.1.0",
55
"homepage": "http://quickblox.com/developers/Javascript",
66
"main": "js/qbMain.js",
77
"license": [
@@ -44,7 +44,7 @@
4444
"crypto-js": "3.1.2-2",
4545
"jquery": "^2.2.0",
4646
"request": "^2.48.0",
47-
"strophe": "^1.2.3",
47+
"strophe": "~1.2.4",
4848
"xml2js": "^0.4.13"
4949
},
5050
"devDependencies": {

quickblox.min.js

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/chat/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ <h5 class="col-md-12 col-sm-12 col-xs-12" id="all_occupants"></h5>
147147
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-timeago/1.4.1/jquery.timeago.min.js" type="text/javascript"></script>
148148
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js" type="text/javascript"></script>
149149

150-
<script src="../../quickblox.min.js"></script>
150+
<script src="../../quickblox.js"></script>
151151
<script src="js/config.js"></script>
152152
<script src="js/connection.js"></script>
153153
<script src="js/messages.js"></script>

samples/webrtc/config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Possible options:
77
* https://examples.com?users=prod
8-
* https://examples.com?users=dev
8+
* https://examples.com?users=dev
99
* https://examples.com - for qa by default
1010
*/
1111
var usersQuery = _getQueryVar('users');
@@ -15,7 +15,8 @@
1515
webrtc: {
1616
answerTimeInterval: 30,
1717
dialingTimeInterval: 5,
18-
disconnectTimeInterval: 30
18+
disconnectTimeInterval: 30,
19+
statsReportTimeInterval: 5
1920
}
2021
};
2122

0 commit comments

Comments
 (0)