export default ( sdp , mediaType , bitrate ) => { const sdpLines = sdp . split ( '\n' ) ; let mediaLineIndex = - 1 ; const mediaLine = `m=${ mediaType }` ; let bitrateLineIndex = - 1 ; const bitrateLine = `b=AS:${ bitrate }` ; mediaLineIndex = sdpLines . findIndex ( ( line ) => line . startsWith ( mediaLine ) ) ; if ( mediaLineIndex && mediaLineIndex < sdpLines . length ) { bitrateLineIndex = mediaLineIndex + 1 ; while ( sdpLines [ bitrateLineIndex ] . startsWith ( 'i=' ) || sdpLines [ bitrateLineIndex ] . startsWith ( 'c=' ) ) { bitrateLineIndex += 1 ; } if ( sdpLines [ bitrateLineIndex ] . startsWith ( 'b=' ) ) { sdpLines [ bitrateLineIndex ] = bitrateLine ; } else { sdpLines . splice ( bitrateLineIndex , 0 , bitrateLine ) ; } } return sdpLines . join ( '\n' ) ; } ;