_setPreferredCodecs(description) {
    if (cache.config.preferredVideoCodec || cache.config.preferredAudioCodec) {
      Log.d('PeerConnection~_setPreferredCodecs', { description, config: cache.config });
      const sdpLines = description.sdp.split(/\r?\n/);
      const medias = { audio: [], video: [] };
      let current = null;
      // Parse SDP
      sdpLines.forEach((sdpLine, i) => {
        if (/^m=/.test(sdpLine)) {
          // eslint-disable-next-line no-useless-escape
          const d = /^m=(\w+)\s[0-9\/]+\s[A-Za-z0-9\/]+\s([0-9\s]+)/.exec(sdpLine);
          current = {
            fmt: d[2].split(/\s/),
            index: i,
            codecs: []
          };
          medias[d[1]].push(current);
        } else if (current && /^a=rtpmap:/.test(sdpLine)) {
          // eslint-disable-next-line no-useless-escape
          const c = /^a=rtpmap:(\d+)\s([a-zA-Z0-9\-\/]+)/.exec(sdpLine);
          if (c) {
            current.codecs.push({
              id: c[1],
              name: c[2],
              index: i
            });
          }
        }
      });
      Log.d('PeerConnection~_setPreferredCodecs', medias);
      let update = false;
      const prefer = (mediaList, preferedCodec) => {
        mediaList.forEach((media) => {
          const selected = media.codecs.find(codec => preferedCodec.test(codec.name));
          if (selected) {
            const fmt = [selected.id].concat(media.fmt.filter(ids => ids !== selected.id));
            sdpLines[media.index] = sdpLines[media.index].replace(media.fmt.join(' '),
              fmt.join(' '));
            update = true;
          }
        });
      };
      if (cache.config.preferredVideoCodec) {
        prefer(medias.video, cache.config.preferredVideoCodec);
      }
      if (cache.config.preferredAudioCodec) {
        prefer(medias.audio, cache.config.preferredAudioCodec);
      }
      if (update) {
        Log.d('PeerConnection~_setPreferredCodecs', sdpLines.join('\r\n'));
        return {
          sdp: sdpLines.join('\r\n'),
          type: description.type
        };
      }
    }
    return description;
  }
/**
   * Edits the SDP to set the preferred audio/video codec
   * @access private
   * @param {RTCSessionDescription} description
   * The description retrieved by createOffer/createAnswer
   * @returns {RTCSessionDescription|{sdp: string, type: string}}
   */
Edits the SDP to set the preferred audio/video codec
@access private
@param {RTCSessionDescription} description
The description retrieved by createOffer/createAnswer
@returns {RTCSessionDescription|{sdp: string, type: string}}
Edits the SDP to set the preferred audio / video codec @access private @param { RTCSessionDescription } description The description retrieved by createOffer / createAnswer @returns { RTCSessionDescription| { sdp : string type : string }}
_setPreferredCodecs(description) {
    if (cache.config.preferredVideoCodec || cache.config.preferredAudioCodec) {
      Log.d('PeerConnection~_setPreferredCodecs', { description, config: cache.config });
      const sdpLines = description.sdp.split(/\r?\n/);
      const medias = { audio: [], video: [] };
      let current = null;
      sdpLines.forEach((sdpLine, i) => {
        if (/^m=/.test(sdpLine)) {
          const d = /^m=(\w+)\s[0-9\/]+\s[A-Za-z0-9\/]+\s([0-9\s]+)/.exec(sdpLine);
          current = {
            fmt: d[2].split(/\s/),
            index: i,
            codecs: []
          };
          medias[d[1]].push(current);
        } else if (current && /^a=rtpmap:/.test(sdpLine)) {
          const c = /^a=rtpmap:(\d+)\s([a-zA-Z0-9\-\/]+)/.exec(sdpLine);
          if (c) {
            current.codecs.push({
              id: c[1],
              name: c[2],
              index: i
            });
          }
        }
      });
      Log.d('PeerConnection~_setPreferredCodecs', medias);
      let update = false;
      const prefer = (mediaList, preferedCodec) => {
        mediaList.forEach((media) => {
          const selected = media.codecs.find(codec => preferedCodec.test(codec.name));
          if (selected) {
            const fmt = [selected.id].concat(media.fmt.filter(ids => ids !== selected.id));
            sdpLines[media.index] = sdpLines[media.index].replace(media.fmt.join(' '),
              fmt.join(' '));
            update = true;
          }
        });
      };
      if (cache.config.preferredVideoCodec) {
        prefer(medias.video, cache.config.preferredVideoCodec);
      }
      if (cache.config.preferredAudioCodec) {
        prefer(medias.audio, cache.config.preferredAudioCodec);
      }
      if (update) {
        Log.d('PeerConnection~_setPreferredCodecs', sdpLines.join('\r\n'));
        return {
          sdp: sdpLines.join('\r\n'),
          type: description.type
        };
      }
    }
    return description;
  }
_setPreferredCodecs ( description ) { if ( cache . config . preferredVideoCodec || cache . config . preferredAudioCodec ) { Log . d ( 'PeerConnection~_setPreferredCodecs' , { description , config : cache . config } ) ; const sdpLines = description . sdp . split ( / \r?\n / ) ; const medias = { audio : [ ] , video : [ ] } ; let current = null ; sdpLines . forEach ( ( sdpLine , i ) => { if ( / ^m= / . test ( sdpLine ) ) { const d = / ^m=(\w+)\s[0-9\/]+\s[A-Za-z0-9\/]+\s([0-9\s]+) / . exec ( sdpLine ) ; current = { fmt : d [ 2 ] . split ( / \s / ) , index : i , codecs : [ ] } ; medias [ d [ 1 ] ] . push ( current ) ; } else if ( current && / ^a=rtpmap: / . test ( sdpLine ) ) { const c = / ^a=rtpmap:(\d+)\s([a-zA-Z0-9\-\/]+) / . exec ( sdpLine ) ; if ( c ) { current . codecs . push ( { id : c [ 1 ] , name : c [ 2 ] , index : i } ) ; } } } ) ; Log . d ( 'PeerConnection~_setPreferredCodecs' , medias ) ; let update = false ; const prefer = ( mediaList , preferedCodec ) => { mediaList . forEach ( ( media ) => { const selected = media . codecs . find ( codec => preferedCodec . test ( codec . name ) ) ; if ( selected ) { const fmt = [ selected . id ] . concat ( media . fmt . filter ( ids => ids !== selected . id ) ) ; sdpLines [ media . index ] = sdpLines [ media . index ] . replace ( media . fmt . join ( ' ' ) , fmt . join ( ' ' ) ) ; update = true ; } } ) ; } ; if ( cache . config . preferredVideoCodec ) { prefer ( medias . video , cache . config . preferredVideoCodec ) ; } if ( cache . config . preferredAudioCodec ) { prefer ( medias . audio , cache . config . preferredAudioCodec ) ; } if ( update ) { Log . d ( 'PeerConnection~_setPreferredCodecs' , sdpLines . join ( '\r\n' ) ) ; return { sdp : sdpLines . join ( '\r\n' ) , type : description . type } ; } } return description ; }
Edits the SDP to set the preferred audio/video codec
 @access private
 @param {RTCSessionDescription} description
 The description retrieved by createOffer/createAnswer
 @returns {RTCSessionDescription|{sdp: string, type: string}}
Edits the SDP to set the preferred audio / video codec @access private @param { RTCSessionDescription } description The description retrieved by createOffer / createAnswer @returns { RTCSessionDescription| { sdp : string type : string }}
// Parse SDP // eslint-disable-next-line no-useless-escape // eslint-disable-next-line no-useless-escape