How to use sdp - 10 common examples

To help you get started, we’ve selected a few sdp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fippo / testbed / video.js View on Github external
t.pass('answer ready to signal');

    // this was fixed into Chrome 51 with https://bugs.chromium.org/p/chromium/issues/detail?id=591971
    if (answerWithCandidates.sdp.indexOf('a=rtpmap:126 H264') !== -1 &&
        answerWithCandidates.sdp.indexOf('a=fmtp:126') === -1) {
      var sections = SDPUtils.splitSections(answerWithCandidates.sdp);
      var lines = SDPUtils.splitLines(sections[2]);
      var idx = lines.indexOf('a=rtpmap:126 H264/90000');
      lines.splice(idx + 1, 0, 'a=fmtp:126 profile-level-id=42e01f;level-asymmetry-allowed=1;packetization-mode=1');
      sections[2] = lines.join('\r\n');
      answerWithCandidates.sdp = sections.join('') + '\r\n';
    }

    if (preferredVideoCodec) {
      var sections = SDPUtils.splitSections(answerWithCandidates.sdp);
      var codecs = SDPUtils.parseRtpParameters(sections[2]).codecs;
      t.ok(codecs[0].name === preferredVideoCodec, 'preferredVideoCodec is used');
    }

    return clientA.setRemoteDescription(answerWithCandidates);
  })
  .then(() => // wait for the iceConnectionState to become either connected/completed
github fippo / testbed / simulcast-playground.js View on Github external
function splitSimulcast(sdp) {
    const sections = SDPUtils.splitSections(sdp);
    const candidates = SDPUtils.matchPrefix(sections[1], 'a=candidate:');
    const dtls = SDPUtils.getDtlsParameters(sections[1], sections[0]);
    const ice = SDPUtils.getIceParameters(sections[1], sections[0]);
    const rtpParameters = SDPUtils.parseRtpParameters(sections[1]);

    // unified plan things.
    rtpParameters.headerExtensions = rtpParameters.headerExtensions.filter(ext => {
        return ext.uri !== 'urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id' &&
            ext.uri !== 'urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id' &&
            ext.uri !== 'urn:ietf:params:rtp-hdrext:sdes:mid';
    });
    sdp = 'v=0\r\n' +
      'o=mozilla...THIS_IS_SDPARTA-61.0 8324701712193024513 0 IN IP4 0.0.0.0\r\n' +
      's=-\r\n' +
      't=0 0\r\n' +
      'a=fingerprint:' + dtls.fingerprints[0].algorithm + ' ' + dtls.fingerprints[0].value + '\r\n' +
      'a=ice-ufrag:' + ice.usernameFragment + '\r\n' +
      'a=ice-pwd:' + ice.password + '\r\n' +
      'a=group:BUNDLE 0 1\r\n' +
      'a=msid-semantic:WMS *\r\n';
github fippo / testbed / simulcast-playground.js View on Github external
function splitSimulcast(sdp) {
    const sections = SDPUtils.splitSections(sdp);
    const candidates = SDPUtils.matchPrefix(sections[1], 'a=candidate:');
    const dtls = SDPUtils.getDtlsParameters(sections[1], sections[0]);
    const ice = SDPUtils.getIceParameters(sections[1], sections[0]);
    const rtpParameters = SDPUtils.parseRtpParameters(sections[1]);

    // unified plan things.
    rtpParameters.headerExtensions = rtpParameters.headerExtensions.filter(ext => {
        return ext.uri !== 'urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id' &&
            ext.uri !== 'urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id' &&
            ext.uri !== 'urn:ietf:params:rtp-hdrext:sdes:mid';
    });
    sdp = 'v=0\r\n' +
      'o=mozilla...THIS_IS_SDPARTA-61.0 8324701712193024513 0 IN IP4 0.0.0.0\r\n' +
      's=-\r\n' +
      't=0 0\r\n' +
      'a=fingerprint:' + dtls.fingerprints[0].algorithm + ' ' + dtls.fingerprints[0].value + '\r\n' +
      'a=ice-ufrag:' + ice.usernameFragment + '\r\n' +
      'a=ice-pwd:' + ice.password + '\r\n' +
github fippo / testbed / video.js View on Github external
.then(answerWithCandidates => {
    t.pass('answer ready to signal');

    // this was fixed into Chrome 51 with https://bugs.chromium.org/p/chromium/issues/detail?id=591971
    if (answerWithCandidates.sdp.indexOf('a=rtpmap:126 H264') !== -1 &&
        answerWithCandidates.sdp.indexOf('a=fmtp:126') === -1) {
      var sections = SDPUtils.splitSections(answerWithCandidates.sdp);
      var lines = SDPUtils.splitLines(sections[2]);
      var idx = lines.indexOf('a=rtpmap:126 H264/90000');
      lines.splice(idx + 1, 0, 'a=fmtp:126 profile-level-id=42e01f;level-asymmetry-allowed=1;packetization-mode=1');
      sections[2] = lines.join('\r\n');
      answerWithCandidates.sdp = sections.join('') + '\r\n';
    }

    if (preferredVideoCodec) {
      var sections = SDPUtils.splitSections(answerWithCandidates.sdp);
      var codecs = SDPUtils.parseRtpParameters(sections[2]).codecs;
      t.ok(codecs[0].name === preferredVideoCodec, 'preferredVideoCodec is used');
    }

    return clientA.setRemoteDescription(answerWithCandidates);
  })
  .then(() => // wait for the iceConnectionState to become either connected/completed
github otalk / attachMediaStream / attachmediastream.bundle.js View on Github external
function(description) {
          var self = this;
          var stream = new MediaStream();
          var receiverList = [];
          var sections = SDPUtils.splitSections(description.sdp);
          var sessionpart = sections.shift();
          var isIceLite = SDPUtils.matchPrefix(sessionpart,
              'a=ice-lite').length > 0;
          this.usingBundle = SDPUtils.matchPrefix(sessionpart,
              'a=group:BUNDLE ').length > 0;
          sections.forEach(function(mediaSection, sdpMLineIndex) {
            var lines = SDPUtils.splitLines(mediaSection);
            var mline = lines[0].substr(2).split(' ');
            var kind = mline[0];
            var rejected = mline[1] === '0';
            var direction = SDPUtils.getDirection(mediaSection, sessionpart);

            var mid = SDPUtils.matchPrefix(mediaSection, 'a=mid:');
            if (mid.length) {
              mid = mid[0].substr(6);
            } else {
              mid = SDPUtils.generateIdentifier();
            }

            // Reject datachannels which are not implemented yet.
github t-mullen / techno-synesthesia / dist / bundle.js View on Github external
sections.forEach(function(mediaSection, sdpMLineIndex) {
              var transceiver = self.transceivers[sdpMLineIndex];
              var iceGatherer = transceiver.iceGatherer;
              var iceTransport = transceiver.iceTransport;
              var dtlsTransport = transceiver.dtlsTransport;
              var localCapabilities = transceiver.localCapabilities;
              var remoteCapabilities = transceiver.remoteCapabilities;

              var rejected = mediaSection.split('\n', 1)[0]
                  .split(' ', 2)[1] === '0';

              if (!rejected && !transceiver.isDatachannel) {
                var remoteIceParameters = SDPUtils.getIceParameters(
                    mediaSection, sessionpart);
                if (isIceLite) {
                  var cands = SDPUtils.matchPrefix(mediaSection, 'a=candidate:')
                  .map(function(cand) {
                    return SDPUtils.parseCandidate(cand);
                  })
                  .filter(function(cand) {
                    return cand.component === '1';
                  });
                  // ice-lite only includes host candidates in the SDP so we can
                  // use setRemoteCandidates (which implies an
                  // RTCIceCandidateComplete)
                  if (cands.length) {
                    iceTransport.setRemoteCandidates(cands);
                  }
                }
github roomrtc / roomrtc / src / adapter.js View on Github external
sections.forEach(function(mediaSection, sdpMLineIndex) {
              var transceiver = self.transceivers[sdpMLineIndex];
              var iceGatherer = transceiver.iceGatherer;
              var iceTransport = transceiver.iceTransport;
              var dtlsTransport = transceiver.dtlsTransport;
              var localCapabilities = transceiver.localCapabilities;
              var remoteCapabilities = transceiver.remoteCapabilities;

              var rejected = mediaSection.split('\n', 1)[0]
                  .split(' ', 2)[1] === '0';

              if (!rejected && !transceiver.isDatachannel) {
                var remoteIceParameters = SDPUtils.getIceParameters(
                    mediaSection, sessionpart);
                if (isIceLite) {
                  var cands = SDPUtils.matchPrefix(mediaSection, 'a=candidate:')
                  .map(function(cand) {
                    return SDPUtils.parseCandidate(cand);
                  })
                  .filter(function(cand) {
                    return cand.component === '1';
                  });
                  // ice-lite only includes host candidates in the SDP so we can
                  // use setRemoteCandidates (which implies an
                  // RTCIceCandidateComplete)
                  if (cands.length) {
                    iceTransport.setRemoteCandidates(cands);
                  }
                }
github red5pro / streaming-html5 / static / lib / webrtc / adapter.js View on Github external
sections.forEach(function(mediaSection, sdpMLineIndex) {
      var lines = SDPUtils.splitLines(mediaSection);
      var mline = lines[0].substr(2).split(' ');
      var kind = mline[0];
      var rejected = mline[1] === '0';
      var direction = SDPUtils.getDirection(mediaSection, sessionpart);
      var remoteMsid = SDPUtils.parseMsid(mediaSection);

      var mid = SDPUtils.matchPrefix(mediaSection, 'a=mid:');
      if (mid.length) {
        mid = mid[0].substr(6);
      } else {
        mid = SDPUtils.generateIdentifier();
      }

      // Reject datachannels which are not implemented yet.
      if (kind === 'application' && mline[2] === 'DTLS/SCTP') {
        self.transceivers[sdpMLineIndex] = {
          mid: mid,
          isDatachannel: true
        };
        return;
      }

      var transceiver;
      var iceGatherer;
      var iceTransport;
      var dtlsTransport;
      var rtpSender;
github otalk / attachMediaStream / attachmediastream.bundle.js View on Github external
sections.forEach(function(mediaSection, sdpMLineIndex) {
            var lines = SDPUtils.splitLines(mediaSection);
            var mline = lines[0].substr(2).split(' ');
            var kind = mline[0];
            var rejected = mline[1] === '0';
            var direction = SDPUtils.getDirection(mediaSection, sessionpart);

            var mid = SDPUtils.matchPrefix(mediaSection, 'a=mid:');
            if (mid.length) {
              mid = mid[0].substr(6);
            } else {
              mid = SDPUtils.generateIdentifier();
            }

            // Reject datachannels which are not implemented yet.
            if (kind === 'application' && mline[2] === 'DTLS/SCTP') {
              self.transceivers[sdpMLineIndex] = {
                mid: mid,
                isDatachannel: true
              };
              return;
            }

            var transceiver;
            var iceGatherer;
            var iceTransport;
            var dtlsTransport;
            var rtpSender;
github webrtcHacks / adapter / src / js / edge / edge_shim.js View on Github external
sections.forEach(function(mediaSection, sdpMLineIndex) {
            var lines = SDPUtils.splitLines(mediaSection);
            var mline = lines[0].substr(2).split(' ');
            var kind = mline[0];
            var rejected = mline[1] === '0';
            var direction = SDPUtils.getDirection(mediaSection, sessionpart);
            var remoteMsid = SDPUtils.parseMsid(mediaSection);

            var mid = SDPUtils.matchPrefix(mediaSection, 'a=mid:');
            if (mid.length) {
              mid = mid[0].substr(6);
            } else {
              mid = SDPUtils.generateIdentifier();
            }

            // Reject datachannels which are not implemented yet.
            if (kind === 'application' && mline[2] === 'DTLS/SCTP') {
              self.transceivers[sdpMLineIndex] = {
                mid: mid,
                isDatachannel: true
              };
              return;
            }

            var transceiver;
            var iceGatherer;
            var iceTransport;
            var dtlsTransport;
            var rtpSender;