@@ -42353,26 +42353,29 @@ RTCPeerConnection.prototype.updateRemoteSDP = function(newSDP){
42353
42353
};
42354
42354
42355
42355
RTCPeerConnection.prototype.getRemoteSDP = function(){
42356
- return this.remoteSDP;
42356
+ return this.remoteSDP;
42357
42357
};
42358
42358
42359
42359
RTCPeerConnection.prototype.setRemoteSessionDescription = function(type, remoteSessionDescription, callback) {
42360
- var desc = new RTCSessionDescription({sdp: remoteSessionDescription, type: type});
42361
-
42362
- var ffVersion = Helpers.getVersionFirefox();
42363
-
42364
- if(ffVersion !== null && (ffVersion === 56 || ffVersion === 57) ) {
42365
- desc.sdp = _modifySDPforFixIssueFFAndFreezes(desc.sdp);
42366
- }
42360
+ var self = this,
42361
+ desc = new RTCSessionDescription({sdp: remoteSessionDescription, type: type}),
42362
+ ffVersion = Helpers.getVersionFirefox();
42363
+
42364
+ if (ffVersion !== null && (ffVersion === 56 || ffVersion === 57) && !self.delegate.bandwidth) {
42365
+ desc.sdp = _modifySDPforFixIssueFFAndFreezes(desc.sdp);
42366
+ } else {
42367
+ desc.sdp = setMediaBitrate(desc.sdp, 'video', self.delegate.bandwidth);
42368
+ }
42369
+
42370
+ function successCallback(desc) {
42371
+ callback(null);
42372
+ }
42367
42373
42368
- function successCallback() {
42369
- callback(null);
42370
- }
42371
- function errorCallback(error) {
42372
- callback(error);
42373
- }
42374
+ function errorCallback(error) {
42375
+ callback(error);
42376
+ }
42374
42377
42375
- this .setRemoteDescription(desc, successCallback, errorCallback);
42378
+ self .setRemoteDescription(desc).then( successCallback, errorCallback);
42376
42379
};
42377
42380
42378
42381
RTCPeerConnection.prototype.addLocalStream = function(localStream){
@@ -42392,20 +42395,20 @@ RTCPeerConnection.prototype.getAndSetLocalSessionDescription = function(callType
42392
42395
// Additional parameters for SDP Constraints
42393
42396
// http://www.w3.org/TR/webrtc/#h-offer-answer-options
42394
42397
42395
- // self.createOffer(successCallback, errorCallback, constraints)
42398
+ self.createOffer().then(function(offer) {
42399
+ offer.sdp = setMediaBitrate(offer.sdp, 'video', self.delegate.bandwidth);
42400
+ successCallback(offer);
42401
+ }).catch(function(reason) {
42402
+ errorCallback(reason);
42403
+ });
42396
42404
42397
- if (Helpers.getVersionSafari() >= 11) {
42398
- self.createOffer().then(function(offer) {
42399
- successCallback(offer);
42400
- }).catch(function(reason) {
42401
- errorCallback(reason);
42402
- });
42403
- // TODO for safari
42404
- } else {
42405
- self.createOffer(successCallback, errorCallback);
42406
- }
42407
42405
} else {
42408
- self.createAnswer(successCallback, errorCallback);
42406
+ self.createAnswer().then(function(answer) {
42407
+ answer.sdp = setMediaBitrate(answer.sdp, 'video', self.delegate.bandwidth);
42408
+ successCallback(answer);
42409
+ }).catch(function(reason) {
42410
+ errorCallback(reason);
42411
+ });
42409
42412
}
42410
42413
42411
42414
function successCallback(desc) {
@@ -42415,22 +42418,16 @@ RTCPeerConnection.prototype.getAndSetLocalSessionDescription = function(callType
42415
42418
* callType === 2 is audio only
42416
42419
*/
42417
42420
var ffVersion = Helpers.getVersionFirefox();
42418
-
42421
+
42419
42422
if (ffVersion !== null && ffVersion < 55 && callType === 2 && self.type === 'offer') {
42420
42423
desc.sdp = _modifySDPforFixIssue(desc.sdp);
42421
42424
}
42422
-
42423
- if(Helpers.getVersionSafari() >= 11) {
42424
- self.setLocalDescription(desc).then(function() {
42425
- callback(null);
42426
- }).catch(function(error) {
42427
- errorCallback(error);
42428
- });
42429
- } else {
42430
- self.setLocalDescription(desc, function() {
42431
- callback(null);
42432
- }, errorCallback);
42433
- }
42425
+
42426
+ self.setLocalDescription(desc).then(function() {
42427
+ callback(null);
42428
+ }).catch(function(error) {
42429
+ errorCallback(error);
42430
+ });
42434
42431
}
42435
42432
42436
42433
function errorCallback(error) {
@@ -42595,8 +42592,8 @@ RTCPeerConnection.prototype._clearStatsReportTimer = function(){
42595
42592
RTCPeerConnection.prototype._getStatsWrap = function() {
42596
42593
var self = this,
42597
42594
localStream = self.getLocalStreams().length ? self.getLocalStreams()[0] : self.delegate.localStream,
42598
- selector = self.delegate.callType == 1 ? localStream.getVideoTracks()[0] : localStream.getAudioTracks()[0] ,
42599
- statsReportInterval ;
42595
+ statsReportInterval ,
42596
+ lastResult ;
42600
42597
42601
42598
if (config.webrtc && config.webrtc.statsReportTimeInterval) {
42602
42599
if (isNaN(+config.webrtc.statsReportTimeInterval)) {
@@ -42606,15 +42603,13 @@ RTCPeerConnection.prototype._getStatsWrap = function() {
42606
42603
statsReportInterval = config.webrtc.statsReportTimeInterval * 1000;
42607
42604
42608
42605
var _statsReportCallback = function() {
42609
- _getStats(self, selector,
42610
- function (results) {
42611
- self.delegate._onCallStatsReport(self.userID, results, null);
42612
- },
42613
- function errorLog(err) {
42614
- Helpers.traceError('_getStats error. ' + err.name + ': ' + err.message);
42615
- self.delegate._onCallStatsReport(self.userID, null, err);
42616
- }
42617
- );
42606
+ _getStats(self, lastResult, function(results, lastResults) {
42607
+ lastResult = lastResults;
42608
+ self.delegate._onCallStatsReport(self.userID, results, null);
42609
+ }, function errorLog(err) {
42610
+ Helpers.traceError('_getStats error. ' + err.name + ': ' + err.message);
42611
+ self.delegate._onCallStatsReport(self.userID, null, err);
42612
+ });
42618
42613
};
42619
42614
42620
42615
Helpers.trace('Stats tracker has been started.');
@@ -42691,18 +42686,63 @@ RTCPeerConnection.prototype._startDialingTimer = function(extension, withOnNotAn
42691
42686
/**
42692
42687
* PRIVATE
42693
42688
*/
42694
- function _getStats(peer, selector, successCallback, errorCallback) {
42695
- peer.getStats(selector, function (res) {
42696
- var items = [];
42697
- res.forEach(function (result) {
42689
+ function _getStats(peer, lastResults, successCallback, errorCallback) {
42690
+ var statistic = {
42691
+ 'inbound_audio': null,
42692
+ 'inbound_video': null,
42693
+ 'outbound_audio': null,
42694
+ 'outbound_video': null,
42695
+ 'total_transport': null,
42696
+ };
42697
+
42698
+ peer.getStats(null).then(function(results) {
42699
+ results.forEach(function(result) {
42698
42700
var item = {};
42699
- item.id = result.id;
42700
- item.type = result.type;
42701
- item.timestamp = result.timestamp;
42702
- items.push(item);
42701
+ if (result.bytesSent && result.type === 'outbound-rtp') {
42702
+ item.bitrate = _getBitratePerSecond(result, lastResults, true);
42703
+ item.type = result.type;
42704
+ item.mediaType = result.mediaType;
42705
+ item.bytesSent = result.bytesSent;
42706
+ item.packetsSent = result.packetsSent;
42707
+ item.timestamp = result.timestamp;
42708
+ statistic['outbound_' + result.mediaType] = item;
42709
+ }
42710
+ if (result.bytesReceived && result.type === 'inbound-rtp') {
42711
+ item.bitrate = _getBitratePerSecond(result, lastResults, false);
42712
+ item.type = result.type;
42713
+ item.mediaType = result.mediaType;
42714
+ item.bytesReceived = result.bytesReceived;
42715
+ item.packetsReceived = result.packetsReceived;
42716
+ item.timestamp = result.timestamp;
42717
+ statistic['inbound_' + result.mediaType] = item;
42718
+ }
42719
+ if (result.bytesSent && result.bytesReceived && result.type === 'transport') {
42720
+ item.bitrate_out = _getBitratePerSecond(result, lastResults, true);
42721
+ item.bitrate_in = _getBitratePerSecond(result, lastResults, false);
42722
+ item.type = result.type;
42723
+ item.bytesSent = result.bytesSent;
42724
+ item.bytesReceived = result.bytesReceived;
42725
+ item.timestamp = result.timestamp;
42726
+ statistic['total_' + result.type] = item;
42727
+ }
42703
42728
});
42704
- successCallback(items );
42729
+ successCallback(statistic, results );
42705
42730
}, errorCallback);
42731
+
42732
+ function _getBitratePerSecond(result, lastResults, isSent) {
42733
+ var lastResult = lastResults && lastResults.get(result.id),
42734
+ bit = 8,
42735
+ bitrate;
42736
+
42737
+ if (!lastResult) {
42738
+ bitrate = 0;
42739
+ } else if (isSent) {
42740
+ bitrate = bit*(result.bytesSent-lastResult.bytesSent)/(result.timestamp-lastResult.timestamp);
42741
+ } else {
42742
+ bitrate = bit*(result.bytesReceived-lastResult.bytesReceived)/(result.timestamp-lastResult.timestamp);
42743
+ }
42744
+ return Math.round(bitrate);
42745
+ }
42706
42746
}
42707
42747
42708
42748
/**
@@ -42730,8 +42770,9 @@ function _modifySDPforFixIssueFFAndFreezes(sdp) {
42730
42770
}
42731
42771
42732
42772
function setMediaBitrate(sdp, media, bitrate) {
42733
- var lines = sdp.split("\n" );
42773
+ var lines = sdp.split('\n' );
42734
42774
var line = -1;
42775
+ var modifier = 'AS';
42735
42776
42736
42777
for (var i = 0; i < lines.length; i++) {
42737
42778
if (lines[i].indexOf("m="+media) === 0) {
@@ -42741,32 +42782,26 @@ function setMediaBitrate(sdp, media, bitrate) {
42741
42782
}
42742
42783
42743
42784
if (line === -1) {
42744
- console.debug("Could not find the m line for", media);
42745
42785
return sdp;
42746
42786
}
42747
- console.debug("Found the m line for", media, "at line", line);
42748
42787
42749
- // Pass the m line
42750
42788
line++;
42751
42789
42752
- // Skip i and c lines
42753
- while(lines[line].indexOf("i=") === 0 || lines[line].indexOf("c=") === 0) {
42790
+ while(lines[line].indexOf('i=') === 0 || lines[line].indexOf('c=') === 0) {
42754
42791
line++;
42755
42792
}
42756
42793
42757
- // If we're on a b line, replace it
42758
- if (lines[line].indexOf("b") === 0) {
42759
- console.debug("Replaced b line at line", line);
42760
- lines[line] = "b=AS:"+bitrate;
42761
- return lines.join("\n");
42794
+ if (lines[line].indexOf('b') === 0) {
42795
+ lines[line] = 'b='+modifier+':'+bitrate;
42796
+ return lines.join('\n');
42762
42797
}
42763
42798
42764
- // Add a new b line
42765
- console.debug("Adding new b line before line", line);
42766
42799
var newLines = lines.slice(0, line);
42767
- newLines.push("b=AS:"+bitrate);
42800
+
42801
+ newLines.push('b='+modifier+':'+bitrate);
42768
42802
newLines = newLines.concat(lines.slice(line, lines.length));
42769
- return newLines.join("\n");
42803
+
42804
+ return newLines.join('\n');
42770
42805
}
42771
42806
42772
42807
module.exports = RTCPeerConnection;
@@ -42858,13 +42893,15 @@ WebRTCClient.prototype.sessions = {};
42858
42893
42859
42894
/**
42860
42895
* Creates the new session.
42861
- * @param {array} opponentsIDs Opponents IDs
42862
- * @param {number} ct Call type
42863
- * @param {number} cID Initiator ID
42896
+ * @param {array} opponentsIDs - Opponents IDs
42897
+ * @param {number} ct - Call type
42898
+ * @param {number} [cID=yourUserId] - Initiator ID
42899
+ * @param {number} [bw=0] - Bandwidth limit (kbps)
42864
42900
*/
42865
- WebRTCClient.prototype.createNewSession = function(opponentsIDs, ct, cID) {
42901
+ WebRTCClient.prototype.createNewSession = function(opponentsIDs, ct, cID, bw ) {
42866
42902
var opponentsIdNASessions = getOpponentsIdNASessions(this.sessions),
42867
42903
callerID = cID || Helpers.getIdFromNode(this.connection.jid),
42904
+ bandwidth = isNaN(bw) ? 0 : +bw,
42868
42905
isIdentifyOpponents = false,
42869
42906
callType = ct || 2;
42870
42907
@@ -42875,14 +42912,14 @@ WebRTCClient.prototype.createNewSession = function(opponentsIDs, ct, cID) {
42875
42912
isIdentifyOpponents = isOpponentsEqual(opponentsIdNASessions, opponentsIDs);
42876
42913
42877
42914
if (!isIdentifyOpponents) {
42878
- return this._createAndStoreSession(null, callerID, opponentsIDs, callType);
42915
+ return this._createAndStoreSession(null, callerID, opponentsIDs, callType, bandwidth );
42879
42916
} else {
42880
42917
throw new Error('Can\'t create a session with the same opponentsIDs. There is a session already in NEW or ACTIVE state.');
42881
42918
}
42882
42919
};
42883
42920
42884
- WebRTCClient.prototype._createAndStoreSession = function(sessionID, callerID, opponentsIDs, callType) {
42885
- var newSession = new WebRTCSession(sessionID, callerID, opponentsIDs, callType, this.signalingProvider, Helpers.getIdFromNode(this.connection.jid));
42921
+ WebRTCClient.prototype._createAndStoreSession = function(sessionID, callerID, opponentsIDs, callType, bandwidth ) {
42922
+ var newSession = new WebRTCSession(sessionID, callerID, opponentsIDs, callType, this.signalingProvider, Helpers.getIdFromNode(this.connection.jid), bandwidth );
42886
42923
42887
42924
/** set callbacks */
42888
42925
newSession.onUserNotAnswerListener = this.onUserNotAnswerListener;
@@ -42952,7 +42989,7 @@ WebRTCClient.prototype._onCallListener = function(userID, sessionID, extension)
42952
42989
var session = this.sessions[sessionID];
42953
42990
42954
42991
if (!session) {
42955
- session = this._createAndStoreSession(sessionID, extension.callerID, extension.opponentsIDs, extension.callType);
42992
+ session = this._createAndStoreSession(sessionID, extension.callerID, extension.opponentsIDs, extension.callType, +extension.userInfo.bandwidth );
42956
42993
42957
42994
if (typeof this.onCallListener === 'function') {
42958
42995
Utils.safeCallbackCall(this.onCallListener, session, userInfo);
@@ -43256,7 +43293,7 @@ WebRTCSession.State = {
43256
43293
* @param {array} An array with opponents
43257
43294
* @param {enum} Type of a call
43258
43295
*/
43259
- function WebRTCSession(sessionID, initiatorID, opIDs, callType, signalingProvider, currentUserID) {
43296
+ function WebRTCSession(sessionID, initiatorID, opIDs, callType, signalingProvider, currentUserID, bandwidth ) {
43260
43297
this.ID = sessionID ? sessionID : generateUUID();
43261
43298
this.state = WebRTCSession.State.NEW;
43262
43299
@@ -43272,6 +43309,8 @@ function WebRTCSession(sessionID, initiatorID, opIDs, callType, signalingProvide
43272
43309
43273
43310
this.currentUserID = currentUserID;
43274
43311
43312
+ this.bandwidth = bandwidth;
43313
+
43275
43314
/**
43276
43315
* We use this timeout to fix next issue:
43277
43316
* "From Android/iOS make a call to Web and kill the Android/iOS app instantly. Web accept/reject popup will be still visible.
@@ -43786,6 +43825,10 @@ WebRTCSession.prototype.processCall = function(peerConnection, ext) {
43786
43825
extension.opponentsIDs = this.opponentsIDs;
43787
43826
extension.sdp = peerConnection.localDescription.sdp;
43788
43827
43828
+ //TODO: set bandwidth to the userInfo object
43829
+ extension.userInfo = ext.userInfo || {};
43830
+ extension.userInfo.bandwidth = this.bandwidth;
43831
+
43789
43832
this.signalingProvider.sendMessage(peerConnection.userID, extension, SignalingConstants.SignalingType.CALL);
43790
43833
};
43791
43834
@@ -43838,10 +43881,8 @@ WebRTCSession.prototype._onCallStatsReport = function(userId, stats, error) {
43838
43881
};
43839
43882
43840
43883
WebRTCSession.prototype._onSessionConnectionStateChangedListener = function(userID, connectionState) {
43841
- var self = this;
43842
-
43843
- if (typeof self.onSessionConnectionStateChangedListener === 'function') {
43844
- Utils.safeCallbackCall(self.onSessionConnectionStateChangedListener, self, userID, connectionState);
43884
+ if (typeof this.onSessionConnectionStateChangedListener === 'function') {
43885
+ Utils.safeCallbackCall(this.onSessionConnectionStateChangedListener, this, userID, connectionState);
43845
43886
}
43846
43887
};
43847
43888
@@ -44617,7 +44658,7 @@ module.exports = StreamManagement;
44617
44658
44618
44659
var config = {
44619
44660
version: '2.8.1',
44620
- buildNumber: '1067 ',
44661
+ buildNumber: '1068 ',
44621
44662
creds: {
44622
44663
appId: '',
44623
44664
authKey: '',
0 commit comments