src/js/utils.js
/**
 * Modifies input SDP according to sdpOptions.
 * See SdpOptions for available options.
 * @param sdp original SDP
 * @param sdpOptions defines changes to be applied to SDP
 * @returns a map with 'sdp' containing the transformed SDP and 'mLines' containing the number of m lines in SDP
 */
Modifies input SDP according to sdpOptions.
See SdpOptions for available options.
@param sdp original SDP
@param sdpOptions defines changes to be applied to SDP
@returns a map with 'sdp' containing the transformed SDP and 'mLines' containing the number of m lines in SDP
Modifies input SDP according to sdpOptions . See SdpOptions for available options . @param sdp original SDP @param sdpOptions defines changes to be applied to SDP @returns a map with ' sdp ' containing the transformed SDP and ' mLines ' containing the number of m lines in SDP
function transformSdp(sdp, sdpOptions) {
    var sections = splitSections(sdp);
    for (var i = 1; i < sections.length; i++) {
        var mediaType = getKind(sections[i]);
        var rtpParams = parseRtpParameters(sections[i]);
        var codecMap = rtpParams.codecs.reduce((map, codec) => {
            map['' + codec.payloadType] = codec;
            return map;
        }, {});
        sections[i] = splitLines(sections[i]).map(line => {
            if (line.startsWith('m=')) {
                if (sdpOptions.forceCodec[mediaType]) {
                    var targetCodecPts = Object.keys(codecMap).filter(pt => !sdpOptions._shouldDeleteCodec(mediaType, codecMap[pt].name));
                    return /.*RTP\/S?AVPF? /.exec(line) + targetCodecPts.join(' ');
                } else {
                    return line;
                }
            } else if (line.startsWith('a=rtpmap:')) {
                var rtpMap = parseRtpMap(line);
                var currentCodec = codecMap[rtpMap.payloadType];
                if (sdpOptions._shouldDeleteCodec(mediaType, currentCodec.name)) {
                    return null;
                }
                if (currentCodec.name.toUpperCase() === 'OPUS') { 
                    currentCodec.parameters.usedtx = sdpOptions.enableOpusDtx ? "1" : "0";
                    return (line + "\r\n" + writeFmtp(currentCodec)).trim();
                } else {
                    return line;
                }
            } else if (line.startsWith('a=fmtp:')) {
                var pt = line.substring('a=fmtp:'.length, line.indexOf(' '));
                var currentCodec = codecMap[pt];
                if (sdpOptions._shouldDeleteCodec(mediaType, currentCodec.name)) {
                    return null;
                }
                if (currentCodec.name.toUpperCase() === 'OPUS') {
                    return null;
                } else {
                    return line;
                }
            } else if (line.startsWith('a=rtcp-fb:')) {
                var pt = line.substring(line.indexOf(':') + 1, line.indexOf(' '));
                var currentCodec = codecMap[pt];
                if (sdpOptions._shouldDeleteCodec(mediaType, currentCodec.name)) {
                    return null;
                } else {
                    return line;
                }
            } else {
                return line;
            }
        }).filter(line => line !== null).join('\r\n');
    }
    return {
        sdp: sections.map(section => section.trim()).join('\r\n') + '\r\n',
        mLines: sections.length - 1 
    };
}
function transformSdp ( sdp , sdpOptions ) { var sections = splitSections ( sdp ) ; for ( var i = 1 ; i < sections . length ; i ++ ) { var mediaType = getKind ( sections [ i ] ) ; var rtpParams = parseRtpParameters ( sections [ i ] ) ; var codecMap = rtpParams . codecs . reduce ( ( map , codec ) => { map [ '' + codec . payloadType ] = codec ; return map ; } , { } ) ; sections [ i ] = splitLines ( sections [ i ] ) . map ( line => { if ( line . startsWith ( 'm=' ) ) { if ( sdpOptions . forceCodec [ mediaType ] ) { var targetCodecPts = Object . keys ( codecMap ) . filter ( pt => ! sdpOptions . _shouldDeleteCodec ( mediaType , codecMap [ pt ] . name ) ) ; return / .*RTP\/S?AVPF?  / . exec ( line ) + targetCodecPts . join ( ' ' ) ; } else { return line ; } } else if ( line . startsWith ( 'a=rtpmap:' ) ) { var rtpMap = parseRtpMap ( line ) ; var currentCodec = codecMap [ rtpMap . payloadType ] ; if ( sdpOptions . _shouldDeleteCodec ( mediaType , currentCodec . name ) ) { return null ; } if ( currentCodec . name . toUpperCase ( ) === 'OPUS' ) { currentCodec . parameters . usedtx = sdpOptions . enableOpusDtx ? "1" : "0" ; return ( line + "\r\n" + writeFmtp ( currentCodec ) ) . trim ( ) ; } else { return line ; } } else if ( line . startsWith ( 'a=fmtp:' ) ) { var pt = line . substring ( 'a=fmtp:' . length , line . indexOf ( ' ' ) ) ; var currentCodec = codecMap [ pt ] ; if ( sdpOptions . _shouldDeleteCodec ( mediaType , currentCodec . name ) ) { return null ; } if ( currentCodec . name . toUpperCase ( ) === 'OPUS' ) { return null ; } else { return line ; } } else if ( line . startsWith ( 'a=rtcp-fb:' ) ) { var pt = line . substring ( line . indexOf ( ':' ) + 1 , line . indexOf ( ' ' ) ) ; var currentCodec = codecMap [ pt ] ; if ( sdpOptions . _shouldDeleteCodec ( mediaType , currentCodec . name ) ) { return null ; } else { return line ; } } else { return line ; } } ) . filter ( line => line !== null ) . join ( '\r\n' ) ; } return { sdp : sections . map ( section => section . trim ( ) ) . join ( '\r\n' ) + '\r\n' , mLines : sections . length - 1 } ; }
Modifies input SDP according to sdpOptions.
Modifies input SDP according to sdpOptions .
// a map from payload type (string) to codec object // modify m= line if SdpOptions#forceCodec specifies codec for current media type // remove this codec if SdpOptions#forceCodec specifies a different codec for current media type // append a=fmtp line immediately if current codec is OPUS (to explicitly specify OPUS parameters) // generate fmtp line immediately after rtpmap line, and remove original fmtp line once we see it // eslint-disable-line no-redeclare // remove this codec if SdpOptions#forceCodec specifies a different codec for current media type // this is a line for OPUS, remove it because FMTP line is already generated when rtpmap line is processed // eslint-disable-line no-redeclare // eslint-disable-line no-redeclare // remove this codec if SdpOptions#forceCodec specifies a different codec for current media type // first section is session description, the rest are media descriptions