api/easyrtc.js
function getCommonCapabilities(localCapabilities, remoteCapabilities) {
  var commonCapabilities = {
    codecs: [],
    headerExtensions: [],
    fecMechanisms: []
  };

  var findCodecByPayloadType = function(pt, codecs) {
    pt = parseInt(pt, 10);
    for (var i = 0; i < codecs.length; i++) {
      if (codecs[i].payloadType === pt ||
          codecs[i].preferredPayloadType === pt) {
        return codecs[i];
      }
    }
  };

  var rtxCapabilityMatches = function(lRtx, rRtx, lCodecs, rCodecs) {
    var lCodec = findCodecByPayloadType(lRtx.parameters.apt, lCodecs);
    var rCodec = findCodecByPayloadType(rRtx.parameters.apt, rCodecs);
    return lCodec && rCodec &&
        lCodec.name.toLowerCase() === rCodec.name.toLowerCase();
  };

  localCapabilities.codecs.forEach(function(lCodec) {
    for (var i = 0; i < remoteCapabilities.codecs.length; i++) {
      var rCodec = remoteCapabilities.codecs[i];
      if (lCodec.name.toLowerCase() === rCodec.name.toLowerCase() &&
          lCodec.clockRate === rCodec.clockRate) {
        if (lCodec.name.toLowerCase() === 'rtx' &&
            lCodec.parameters && rCodec.parameters.apt) {
          // for RTX we need to find the local rtx that has a apt
          // which points to the same local codec as the remote one.
          if (!rtxCapabilityMatches(lCodec, rCodec,
              localCapabilities.codecs, remoteCapabilities.codecs)) {
            continue;
          }
        }
        rCodec = JSON.parse(JSON.stringify(rCodec)); // deepcopy
        // number of channels is the highest common number of channels
        rCodec.numChannels = Math.min(lCodec.numChannels,
            rCodec.numChannels);
        // push rCodec so we reply with offerer payload type
        commonCapabilities.codecs.push(rCodec);

        // determine common feedback mechanisms
        rCodec.rtcpFeedback = rCodec.rtcpFeedback.filter(function(fb) {
          for (var j = 0; j < lCodec.rtcpFeedback.length; j++) {
            if (lCodec.rtcpFeedback[j].type === fb.type &&
                lCodec.rtcpFeedback[j].parameter === fb.parameter) {
              return true;
            }
          }
          return false;
        });
        // FIXME: also need to determine .parameters
        //  see https://github.com/openpeer/ortc/issues/569
        break;
      }
    }
  });

  localCapabilities.headerExtensions.forEach(function(lHeaderExtension) {
    for (var i = 0; i < remoteCapabilities.headerExtensions.length;
         i++) {
      var rHeaderExtension = remoteCapabilities.headerExtensions[i];
      if (lHeaderExtension.uri === rHeaderExtension.uri) {
        commonCapabilities.headerExtensions.push(rHeaderExtension);
        break;
      }
    }
  });

  // FIXME: fecMechanisms
  return commonCapabilities;
}
function getCommonCapabilities(localCapabilities, remoteCapabilities) {
  var commonCapabilities = {
    codecs: [],
    headerExtensions: [],
    fecMechanisms: []
  };

  var findCodecByPayloadType = function(pt, codecs) {
    pt = parseInt(pt, 10);
    for (var i = 0; i < codecs.length; i++) {
      if (codecs[i].payloadType === pt ||
          codecs[i].preferredPayloadType === pt) {
        return codecs[i];
      }
    }
  };

  var rtxCapabilityMatches = function(lRtx, rRtx, lCodecs, rCodecs) {
    var lCodec = findCodecByPayloadType(lRtx.parameters.apt, lCodecs);
    var rCodec = findCodecByPayloadType(rRtx.parameters.apt, rCodecs);
    return lCodec && rCodec &&
        lCodec.name.toLowerCase() === rCodec.name.toLowerCase();
  };

  localCapabilities.codecs.forEach(function(lCodec) {
    for (var i = 0; i < remoteCapabilities.codecs.length; i++) {
      var rCodec = remoteCapabilities.codecs[i];
      if (lCodec.name.toLowerCase() === rCodec.name.toLowerCase() &&
          lCodec.clockRate === rCodec.clockRate) {
        if (lCodec.name.toLowerCase() === 'rtx' &&
            lCodec.parameters && rCodec.parameters.apt) {
          // for RTX we need to find the local rtx that has a apt
          // which points to the same local codec as the remote one.
          if (!rtxCapabilityMatches(lCodec, rCodec,
              localCapabilities.codecs, remoteCapabilities.codecs)) {
            continue;
          }
        }
        rCodec = JSON.parse(JSON.stringify(rCodec)); // deepcopy
        // number of channels is the highest common number of channels
        rCodec.numChannels = Math.min(lCodec.numChannels,
            rCodec.numChannels);
        // push rCodec so we reply with offerer payload type
        commonCapabilities.codecs.push(rCodec);

        // determine common feedback mechanisms
        rCodec.rtcpFeedback = rCodec.rtcpFeedback.filter(function(fb) {
          for (var j = 0; j < lCodec.rtcpFeedback.length; j++) {
            if (lCodec.rtcpFeedback[j].type === fb.type &&
                lCodec.rtcpFeedback[j].parameter === fb.parameter) {
              return true;
            }
          }
          return false;
        });
        // FIXME: also need to determine .parameters
        //  see https://github.com/openpeer/ortc/issues/569
        break;
      }
    }
  });

  localCapabilities.headerExtensions.forEach(function(lHeaderExtension) {
    for (var i = 0; i < remoteCapabilities.headerExtensions.length;
         i++) {
      var rHeaderExtension = remoteCapabilities.headerExtensions[i];
      if (lHeaderExtension.uri === rHeaderExtension.uri) {
        commonCapabilities.headerExtensions.push(rHeaderExtension);
        break;
      }
    }
  });

  // FIXME: fecMechanisms
  return commonCapabilities;
}
function getCommonCapabilities ( localCapabilities , remoteCapabilities ) { var commonCapabilities = { codecs : [ ] , headerExtensions : [ ] , fecMechanisms : [ ] } ; var findCodecByPayloadType = function ( pt , codecs ) { pt = parseInt ( pt , 10 ) ; for ( var i = 0 ; i < codecs . length ; i ++ ) { if ( codecs [ i ] . payloadType === pt || codecs [ i ] . preferredPayloadType === pt ) { return codecs [ i ] ; } } } ; var rtxCapabilityMatches = function ( lRtx , rRtx , lCodecs , rCodecs ) { var lCodec = findCodecByPayloadType ( lRtx . parameters . apt , lCodecs ) ; var rCodec = findCodecByPayloadType ( rRtx . parameters . apt , rCodecs ) ; return lCodec && rCodec && lCodec . name . toLowerCase ( ) === rCodec . name . toLowerCase ( ) ; } ; localCapabilities . codecs . forEach ( function ( lCodec ) { for ( var i = 0 ; i < remoteCapabilities . codecs . length ; i ++ ) { var rCodec = remoteCapabilities . codecs [ i ] ; if ( lCodec . name . toLowerCase ( ) === rCodec . name . toLowerCase ( ) && lCodec . clockRate === rCodec . clockRate ) { if ( lCodec . name . toLowerCase ( ) === 'rtx' && lCodec . parameters && rCodec . parameters . apt ) { // for RTX we need to find the local rtx that has a apt // which points to the same local codec as the remote one. if ( ! rtxCapabilityMatches ( lCodec , rCodec , localCapabilities . codecs , remoteCapabilities . codecs ) ) { continue ; } } rCodec = JSON . parse ( JSON . stringify ( rCodec ) ) ; // deepcopy // number of channels is the highest common number of channels rCodec . numChannels = Math . min ( lCodec . numChannels , rCodec . numChannels ) ; // push rCodec so we reply with offerer payload type commonCapabilities . codecs . push ( rCodec ) ; // determine common feedback mechanisms rCodec . rtcpFeedback = rCodec . rtcpFeedback . filter ( function ( fb ) { for ( var j = 0 ; j < lCodec . rtcpFeedback . length ; j ++ ) { if ( lCodec . rtcpFeedback [ j ] . type === fb . type && lCodec . rtcpFeedback [ j ] . parameter === fb . parameter ) { return true ; } } return false ; } ) ; // FIXME: also need to determine .parameters //  see https://github.com/openpeer/ortc/issues/569 break ; } } } ) ; localCapabilities . headerExtensions . forEach ( function ( lHeaderExtension ) { for ( var i = 0 ; i < remoteCapabilities . headerExtensions . length ; i ++ ) { var rHeaderExtension = remoteCapabilities . headerExtensions [ i ] ; if ( lHeaderExtension . uri === rHeaderExtension . uri ) { commonCapabilities . headerExtensions . push ( rHeaderExtension ) ; break ; } } } ) ; // FIXME: fecMechanisms return commonCapabilities ; }
Determines the intersection of local and remote capabilities.
Determines the intersection of local and remote capabilities .