@@ -200,8 +200,14 @@ function onSetSessionDescriptionError(error) {
200200bandwidthSelector . 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