-
Notifications
You must be signed in to change notification settings - Fork 217
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
v2.0.5 #109
Changes from 2 commits
f7f655c
a1c2421
8131c5a
5992b28
eff85b2
35e0fa2
fa3005a
86ae9bc
574ca1e
500bfed
6a132f3
c1662d3
841afdf
ac21d0f
36f9c0d
55ee9a4
a54f752
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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(); | ||
|
@@ -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: | ||
|
@@ -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) { | ||
self.delegate._onCallStatsReport(self.userID, res.bytesReceived); | ||
} | ||
/** for chrome */ | ||
if (res.googCodecName == 'opus' && res.bytesReceived) { | ||
self.delegate._onCallStatsReport(self.userID, res.bytesReceived); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. идея в том, чтобы выдавать все статы |
||
} | ||
} | ||
}); | ||
}; | ||
|
||
self.statsReportTimer = setInterval(_statsReportCallback, statsReportInterval); | ||
}; | ||
|
||
RTCPeerConnection.prototype._clearWaitingReconnectTimer = function() { | ||
if(this.waitingReconnectTimeoutCallback){ | ||
Helpers.trace('_clearWaitingReconnectTimer'); | ||
|
@@ -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], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А что будет если вдруг 0 и 0 элементы не будут доступны? |
||
function (res) { | ||
var items = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а зачем мы перегоням массив res в массив items? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а зачем два ифа, у которых внутренний код идентичен?