Skip to content

v2.0.5 #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Feb 18, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 81 additions & 3 deletions js/modules/webrtc/qbRTCPeerConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ RTCPeerConnection.prototype.init = function(delegate, userID, sessionID, type) {
/** We use this timer interval to dial a user - produce the call requests each N seconds. */
this.dialingTimer = null;
this.answerTimeInterval = 0;
this.statsReportTimer = null;

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

RTCPeerConnection.prototype.release = function(){
this._clearDialingTimer();
this._clearStatsReportTimer();

if(this.signalingState !== 'closed'){
this.close();
Expand Down Expand Up @@ -174,16 +176,25 @@ RTCPeerConnection.prototype.onIceCandidateCallback = function(event) {

/** handler of remote media stream */
RTCPeerConnection.prototype.onAddRemoteStreamCallback = function(event) {
var self = this;

if (typeof this.delegate._onRemoteStreamListener === 'function'){
this.delegate._onRemoteStreamListener(this.userID, event.stream);
}

if (config.webrtc && config.webrtc.statsReportTimeInterval) {
if(isNaN(+config.webrtc.statsReportTimeInterval)) {
Helpers.traceError('statsReportTimeInterval (' + config.webrtc.statsReportTimeInterval + ') must be integer.');
} else {
self._getStatsWrap();
}
}
};

RTCPeerConnection.prototype.onIceConnectionStateCallback = function() {
var newIceConnectionState = this.iceConnectionState;

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

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

/**
* read more about all states:
Expand Down Expand Up @@ -226,6 +237,40 @@ RTCPeerConnection.prototype.onIceConnectionStateCallback = function() {
/**
* PRIVATE
*/
RTCPeerConnection.prototype._clearStatsReportTimer = function(){
if(this.statsReportTimer){
Helpers.trace('_clearStatsReportTimer');

clearInterval(this.statsReportTimer);
this.statsReportTimer = null;
}
};

RTCPeerConnection.prototype._getStatsWrap = function() {
var self = this,
statsReportInterval = config.webrtc.statsReportTimeInterval * 1000;

var _statsReportCallback = function() {
_getStats(self, function (results) {
for (var i = 0; i < results.length; ++i) {
var res = results[i],
is_firefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;

/** for firefox */
if(is_firefox && res.bytesReceived) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а зачем два ифа, у которых внутренний код идентичен?

self.delegate._onCallStatsReport(self.userID, res.bytesReceived);
}
/** for chrome */
if (res.googCodecName == 'opus' && res.bytesReceived) {
self.delegate._onCallStatsReport(self.userID, res.bytesReceived);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

идея в том, чтобы выдавать все статы
и юзер уже в приложении будет хендлить сам логику с bytesReceived.
Сделай выдачу всех статов в калбек.

}
}
});
};

self.statsReportTimer = setInterval(_statsReportCallback, statsReportInterval);
};

RTCPeerConnection.prototype._clearWaitingReconnectTimer = function() {
if(this.waitingReconnectTimeoutCallback){
Helpers.trace('_clearWaitingReconnectTimer');
Expand Down Expand Up @@ -292,4 +337,37 @@ RTCPeerConnection.prototype._startDialingTimer = function(extension, withOnNotAn
_dialingCallback(extension, withOnNotAnswerCallback, true);
};

module.exports = RTCPeerConnection;
/**
* PRIVATE
*/
function _getStats(peer, cb) {
if (!!navigator.mozGetUserMedia) {
peer.getStats(peer.getLocalStreams()[0].getAudioTracks()[0],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А что будет если вдруг 0 и 0 элементы не будут доступны?

function (res) {
var items = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а зачем мы перегоням массив res в массив items?
почему нельзя просто сделать cb(res); ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

res.forEach(function (result) {
items.push(result);
});
cb(items);
},
cb
);
} else {
peer.getStats(function (res) {
var items = [];
res.result().forEach(function (result) {
var item = {};
result.names().forEach(function (name) {
item[name] = result.stat(name);
});
item.id = result.id;
item.type = result.type;
item.timestamp = result.timestamp;
items.push(item);
});
cb(items);
});
}
}

module.exports = RTCPeerConnection;
1 change: 1 addition & 0 deletions js/modules/webrtc/qbWebRTCClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ WebRTCClient.prototype._createAndStoreSession = function(sessionID, callerID, op
newSession.onRemoteStreamListener = this.onRemoteStreamListener;
newSession.onSessionConnectionStateChangedListener = this.onSessionConnectionStateChangedListener;
newSession.onSessionCloseListener = this.onSessionCloseListener;
newSession.onCallStatsReport = this.onCallStatsReport;

this.sessions[newSession.ID] = newSession;
return newSession;
Expand Down
7 changes: 7 additions & 0 deletions js/modules/webrtc/qbWebRTCSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* - onRemoteStreamListener(session, userID, stream)
* - onSessionConnectionStateChangedListener(session, userID, connectionState)
* - onSessionCloseListener(session)
* - onCallStatsReport(session, userId, bytesReceived)
*/

var config = require('../../qbConfig');
Expand Down Expand Up @@ -594,6 +595,12 @@ WebRTCSession.prototype._onRemoteStreamListener = function(userID, stream) {
}
};

WebRTCSession.prototype._onCallStatsReport = function(userId, bytesReceived) {
if (typeof this.onCallStatsReport === 'function'){
Utils.safeCallbackCall(this.onCallStatsReport, this, userId, bytesReceived);
}
};

WebRTCSession.prototype._onSessionConnectionStateChangedListener = function(userID, connectionState) {
var self = this;

Expand Down
5 changes: 5 additions & 0 deletions js/qbConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
*
* Configuration Module
*
* NOTE:
* - config.webrtc.statsReportTimeInterval [integer, sec]:
* could add listener onCallStatsReport(session, userId, bytesReceived) if
* want to get stats (bytesReceived) about peer every X sec;
*/

var config = {
Expand All @@ -26,6 +30,7 @@ var config = {
answerTimeInterval: 60,
dialingTimeInterval: 5,
disconnectTimeInterval: 30,
statsReportTimeInterval: 3,
iceServers: [
{
'url': 'stun:stun.l.google.com:19302'
Expand Down
20 changes: 10 additions & 10 deletions quickblox.min.js

Large diffs are not rendered by default.

Loading