Skip to content

Commit ac14645

Browse files
authored
Merge pull request #1603 from fippo/bandwidth
Update bandwidth sample
2 parents 301a09c + 3df85d9 commit ac14645

File tree

1 file changed

+14
-16
lines changed
  • src/content/peerconnection/bandwidth/js

1 file changed

+14
-16
lines changed

src/content/peerconnection/bandwidth/js/main.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,14 @@ function onSetSessionDescriptionError(error) {
200200
bandwidthSelector.onchange = () => {
201201
bandwidthSelector.disabled = true;
202202
const bandwidth = bandwidthSelector.options[bandwidthSelector.selectedIndex].value;
203+
setBandwidth(bandwidth)
204+
.then(() => {
205+
bandwidthSelector.disabled = false;
206+
});
207+
};
203208

204-
// In Chrome, use RTCRtpSender.setParameters to change bandwidth without
209+
function setBandwidth(bandwidthInKbps) {
210+
// In modern browsers, use RTCRtpSender.setParameters to change bandwidth without
205211
// (local) renegotiation. Note that this will be within the envelope of
206212
// the initial maximum bandwidth negotiated via SDP.
207213
if ((adapter.browserDetails.browser === 'chrome' ||
@@ -215,36 +221,28 @@ bandwidthSelector.onchange = () => {
215221
if (!parameters.encodings) {
216222
parameters.encodings = [{}];
217223
}
218-
if (bandwidth === 'unlimited') {
224+
if (bandwidthInKbps === 'unlimited') {
219225
delete parameters.encodings[0].maxBitrate;
220226
} else {
221-
parameters.encodings[0].maxBitrate = bandwidth * 1000;
227+
parameters.encodings[0].maxBitrate = bandwidthInKbps * 1000;
222228
}
223-
sender.setParameters(parameters)
224-
.then(() => {
225-
bandwidthSelector.disabled = false;
226-
})
227-
.catch(e => console.error(e));
228-
return;
229+
return sender.setParameters(parameters);
229230
}
230-
// Fallback to the SDP munging with local renegotiation way of limiting
231+
// Fallback to the SDP changes with local renegotiation as way of limiting
231232
// the bandwidth.
232-
pc1.createOffer()
233+
return pc1.createOffer()
233234
.then(offer => pc1.setLocalDescription(offer))
234235
.then(() => {
235236
const desc = {
236237
type: pc1.remoteDescription.type,
237-
sdp: bandwidth === 'unlimited' ?
238+
sdp: bandwidthInKbps === 'unlimited' ?
238239
removeBandwidthRestriction(pc1.remoteDescription.sdp) :
239-
updateBandwidthRestriction(pc1.remoteDescription.sdp, bandwidth)
240+
updateBandwidthRestriction(pc1.remoteDescription.sdp, bandwidthInKbps)
240241
};
241242
console.log('Applying bandwidth restriction to setRemoteDescription:\n' +
242243
desc.sdp);
243244
return pc1.setRemoteDescription(desc);
244245
})
245-
.then(() => {
246-
bandwidthSelector.disabled = false;
247-
})
248246
.catch(onSetSessionDescriptionError);
249247
};
250248

0 commit comments

Comments
 (0)