Skip to content

Commit 8131c5a

Browse files
author
dimaspirit
committed
https://quickblox.atlassian.net/browse/QBWEBSDK-179
hack mozilla
1 parent a1c2421 commit 8131c5a

File tree

6 files changed

+86
-60
lines changed

6 files changed

+86
-60
lines changed

js/modules/webrtc/qbRTCPeerConnection.js

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,8 @@ RTCPeerConnection.prototype.onAddRemoteStreamCallback = function(event) {
182182
this.delegate._onRemoteStreamListener(this.userID, event.stream);
183183
}
184184

185-
if (config.webrtc && config.webrtc.statsReportTimeInterval) {
186-
if(isNaN(+config.webrtc.statsReportTimeInterval)) {
187-
Helpers.traceError('statsReportTimeInterval (' + config.webrtc.statsReportTimeInterval + ') must be integer.');
188-
} else {
189-
self._getStatsWrap();
190-
}
191-
}
185+
186+
self._getStatsWrap();
192187
};
193188

194189
RTCPeerConnection.prototype.onIceConnectionStateCallback = function() {
@@ -246,26 +241,40 @@ RTCPeerConnection.prototype.onIceConnectionStateCallback = function() {
246241
}
247242
};
248243

249-
RTCPeerConnection.prototype._getStatsWrap = function() {
250-
var self = this,
251-
statsReportInterval = config.webrtc.statsReportTimeInterval * 1000;
244+
RTCPeerConnection.prototype._getStatsWrap = function() {
245+
var self = this,
246+
selector = self.delegate.callType == 1 ? self.getLocalStreams()[0].getVideoTracks()[0] : self.getLocalStreams()[0].getAudioTracks()[0],
247+
statsReportInterval = 0;
248+
249+
if (config.webrtc && config.webrtc.statsReportTimeInterval && isNaN(+config.webrtc.statsReportTimeInterval)) {
250+
Helpers.traceError('statsReportTimeInterval (' + config.webrtc.statsReportTimeInterval + ') must be integer.');
251+
return;
252+
}
253+
254+
statsReportInterval = config.webrtc.statsReportTimeInterval * 1000;
252255

253-
var _statsReportCallback = function() {
254-
_getStats(self, function (results) {
255-
for (var i = 0; i < results.length; ++i) {
256+
var _statsReportCallback = function() {
257+
_getStats(self, function (results) {
258+
for (var i = 0; i < results.length; ++i) {
256259
var res = results[i],
257260
is_firefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
258261

259-
/** for firefox */
260-
if(is_firefox && res.bytesReceived) {
261-
self.delegate._onCallStatsReport(self.userID, res.bytesReceived);
262-
}
262+
/** for firefox */
263+
if(is_firefox && res.type == 'inboundrtp') {
264+
self.delegate._onCallStatsReport(self.userID, res);
265+
}
266+
263267
/** for chrome */
264-
if (res.googCodecName == 'opus' && res.bytesReceived) {
265-
self.delegate._onCallStatsReport(self.userID, res.bytesReceived);
266-
}
267-
}
268-
});
268+
if (res.googCodecName == 'opus') {
269+
self.delegate._onCallStatsReport(self.userID, res);
270+
}
271+
}
272+
},
273+
selector,
274+
function errorLog(err) {
275+
Helpers.traceError(error.name + ": " + error.message);
276+
}
277+
);
269278
};
270279

271280
self.statsReportTimer = setInterval(_statsReportCallback, statsReportInterval);
@@ -340,17 +349,17 @@ RTCPeerConnection.prototype._startDialingTimer = function(extension, withOnNotAn
340349
/**
341350
* PRIVATE
342351
*/
343-
function _getStats(peer, cb) {
352+
function _getStats(peer, cb, selector, errorCallback) {
344353
if (!!navigator.mozGetUserMedia) {
345-
peer.getStats(peer.getLocalStreams()[0].getAudioTracks()[0],
354+
peer.getStats(selector,
346355
function (res) {
347356
var items = [];
348357
res.forEach(function (result) {
349358
items.push(result);
350359
});
351360
cb(items);
352361
},
353-
cb
362+
errorCallback
354363
);
355364
} else {
356365
peer.getStats(function (res) {

js/modules/webrtc/qbWebRTCSession.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* - onRemoteStreamListener(session, userID, stream)
1010
* - onSessionConnectionStateChangedListener(session, userID, connectionState)
1111
* - onSessionCloseListener(session)
12-
* - onCallStatsReport(session, userId, bytesReceived)
12+
* - onCallStatsReport(session, userId, stats)
1313
*/
1414

1515
var config = require('../../qbConfig');
@@ -595,9 +595,9 @@ WebRTCSession.prototype._onRemoteStreamListener = function(userID, stream) {
595595
}
596596
};
597597

598-
WebRTCSession.prototype._onCallStatsReport = function(userId, bytesReceived) {
598+
WebRTCSession.prototype._onCallStatsReport = function(userId, stats) {
599599
if (typeof this.onCallStatsReport === 'function'){
600-
Utils.safeCallbackCall(this.onCallStatsReport, this, userId, bytesReceived);
600+
Utils.safeCallbackCall(this.onCallStatsReport, this, userId, stats);
601601
}
602602
};
603603

js/qbConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var config = {
3030
answerTimeInterval: 60,
3131
dialingTimeInterval: 5,
3232
disconnectTimeInterval: 30,
33-
statsReportTimeInterval: 3,
33+
statsReportTimeInterval: 10,
3434
iceServers: [
3535
{
3636
'url': 'stun:stun.l.google.com:19302'

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/webrtc/config.js

Lines changed: 4 additions & 3 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

@@ -231,4 +232,4 @@
231232
window.CONFIG = CONFIG;
232233
window.QBUsers = QBUsers;
233234
window.MESSAGES = MESSAGES;
234-
}(window));
235+
}(window));

samples/webrtc/js/app.js

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@
107107
remoteStreamCounter = 0,
108108
authorizationing = false,
109109
callTimer,
110-
network = {},
110+
network = {
111+
users: {},
112+
timer: null
113+
},
111114
is_firefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
112115

113116
function initializeUI(arg) {
@@ -483,37 +486,48 @@
483486
authorizationing = false;
484487
};
485488

486-
QB.webrtc.onCallStatsReport = function onCallStatsReport(session, userId, bytesReceived) {
489+
QB.webrtc.onCallStatsReport = function onCallStatsReport(session, userId, stats) {
487490
console.group('onCallStatsReport');
488491
console.log('userId: ' + userId);
489-
console.log('bytesReceived: ' + bytesReceived);
492+
console.log('Stats: ', stats);
490493
console.groupEnd();
491494

492495
/**
493496
* Hack for Firefox
494497
* (https://bugzilla.mozilla.org/show_bug.cgi?id=852665)
495498
*/
496499
if(is_firefox) {
497-
if( network[userId] === undefined ) {
498-
network[userId] = {
499-
'bytesReceived': bytesReceived,
500-
'attempt': 1
500+
if(!network.timer) {
501+
network.timer = window.setInterval(checkNetwork, 7000);
502+
}
503+
504+
if(network.users[userId] === undefined ) {
505+
network.users[userId] = {
506+
userId: userId,
507+
prevBytesReceived: 0,
508+
bytesReceived: stats.bytesReceived
501509
};
502510
} else {
503-
if( network[userId].bytesReceived === bytesReceived) {
504-
if(network[userId].attempt > 2) {
505-
QB.webrtc.onStopCallListener(session, userId);
506-
session.processOnStop(userId);
507-
} else {
508-
network[userId].attempt += 1;
509-
}
510-
} else {
511-
network[userId].bytesReceived = bytesReceived;
512-
}
511+
network.users[userId].prevBytesReceived = network.users[userId].bytesReceived;
512+
network.users[userId].bytesReceived = stats.bytesReceived;
513513
}
514514
}
515515
};
516516

517+
function checkNetwork() {
518+
_.each(network.users, function(user) {
519+
if(!user.isClosed) {
520+
if(user.prevBytesReceived >= user.bytesReceived) {
521+
QB.webrtc.onStopCallListener(app.currentSession, user.userId);
522+
app.currentSession.processOnStop(user.userId);
523+
user.isClosed = true;
524+
} else {
525+
user.bytesReceived = user.prevBytesReceived;
526+
}
527+
}
528+
});
529+
}
530+
517531
QB.webrtc.onSessionCloseListener = function onSessionCloseListener(session){
518532
console.log('onSessionCloseListener: ' + session);
519533

@@ -771,10 +785,12 @@
771785
if( _.isEmpty(app.currentSession) || isCallEnded ) {
772786
if(callTimer) {
773787
$('#timer').addClass('hidden');
774-
775788
clearInterval(callTimer);
776789
callTimer = null;
777790
ui.callTime = 0;
791+
792+
clearInterval(network.timer);
793+
network = {};
778794
}
779795
}
780796
}

0 commit comments

Comments
 (0)