Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sdp

Package Overview
Dependencies
Maintainers
2
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sdp - npm Package Compare versions

Comparing version 1.5.0 to 1.5.1

LICENSE

2

package.json
{
"name": "sdp",
"version": "1.5.0",
"version": "1.5.1",
"description": "SDP parsing and serialization utilities",

@@ -5,0 +5,0 @@ "main": "sdp.js",

@@ -71,3 +71,4 @@ /* eslint-env node */

break;
default: // Unknown extensions are silently ignored.
default: // extension handling, in particular ufrag
candidate[parts[i]] = parts[i + 1];
break;

@@ -106,2 +107,8 @@ }

// Parses an ice-options line, returns an array of option tags.
// a=ice-options:foo bar
SDPUtils.parseIceOptions = function(line) {
return line.substr(14).split(' ');
}
// Parses an rtpmap line, returns RTCRtpCoddecParameters. Sample input:

@@ -137,2 +144,3 @@ // a=rtpmap:111 opus/48000/2

// a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
// a=extmap:2/sendonly urn:ietf:params:rtp-hdrext:toffset
SDPUtils.parseExtmap = function(line) {

@@ -142,2 +150,3 @@ var parts = line.substr(9).split(' ');

id: parseInt(parts[0], 10),
direction: parts[0].indexOf('/') > 0 ? parts[0].split('/')[1] : 'sendrecv',
uri: parts[1]

@@ -151,3 +160,6 @@ };

return 'a=extmap:' + (headerExtension.id || headerExtension.preferredId) +
' ' + headerExtension.uri + '\r\n';
(headerExtension.direction && headerExtension.direction !== 'sendrecv'
? '/' + headerExtension.direction
: '') +
' ' + headerExtension.uri + '\r\n';
};

@@ -239,2 +251,10 @@

SDPUtils.parseFingerprint = function(line) {
var parts = line.substr(14).split(' ');
return {
algorithm: parts[0].toLowerCase(), // algorithm is case-sensitive in Edge.
value: parts[1]
};
};
// Extracts DTLS parameters from SDP media section or sessionpart.

@@ -244,18 +264,10 @@ // FIXME: for consistency with other functions this should only

SDPUtils.getDtlsParameters = function(mediaSection, sessionpart) {
var lines = SDPUtils.splitLines(mediaSection);
// Search in session part, too.
lines = lines.concat(SDPUtils.splitLines(sessionpart));
var fpLine = lines.filter(function(line) {
return line.indexOf('a=fingerprint:') === 0;
})[0].substr(14);
var lines = SDPUtils.matchPrefix(mediaSection + sessionpart,
'a=fingerprint:');
// Note: a=setup line is ignored since we use the 'auto' role.
// Note2: 'algorithm' is not case sensitive except in Edge.
var dtlsParameters = {
return {
role: 'auto',
fingerprints: [{
algorithm: fpLine.split(' ')[0].toLowerCase(),
value: fpLine.split(' ')[1]
}]
fingerprints: lines.map(SDPUtils.parseFingerprint)
};
return dtlsParameters;
};

@@ -529,3 +541,5 @@

if (transceiver.rtpSender && transceiver.rtpReceiver) {
if (transceiver.direction) {
sdp += 'a=' + transceiver.direction + '\r\n';
} else if (transceiver.rtpSender && transceiver.rtpReceiver) {
sdp += 'a=sendrecv\r\n';

@@ -532,0 +546,0 @@ } else if (transceiver.rtpSender) {

@@ -216,13 +216,19 @@ /* jshint node: true */

test('parseFingerprint', function(t) {
var res = SDPUtils.parseFingerprint('a=fingerprint:ALG fp');
t.ok(res.algorithm === 'alg', 'algorithm is parsed and lowercased');
t.ok(res.value === 'fp', 'value is parsed');
t.end();
});
test('getDtlsParameters', function(t) {
var fp = 'a=fingerprint:sha-256 so:me:th:in:g1\r\n';
var fp = 'a=fingerprint:sha-256 so:me:th:in:g1\r\na=fingerprint:SHA-1 somethingelse';
var dtlsParameters = SDPUtils.getDtlsParameters(fp, '');
t.ok(dtlsParameters.role === 'auto', 'set role to "auto"');
t.ok(dtlsParameters.fingerprints.length === 1, 'parsed one fingerprint');
t.ok(dtlsParameters.fingerprints.length === 2, 'parsed two fingerprints');
t.ok(dtlsParameters.fingerprints[0].algorithm === 'sha-256', 'extracted algorithm');
t.ok(dtlsParameters.fingerprints[0].value === 'so:me:th:in:g1', 'extracted value');
// test that values are lowercased
t.ok(SDPUtils.getDtlsParameters(fp.replace('sha-256', 'SHA-256'), '').fingerprints[0].algorithm === 'sha-256',
'algorithm value is extracted as lower-case');
t.ok(dtlsParameters.fingerprints[1].algorithm === 'sha-1', 'extracted second algorithm (lowercased)');
t.ok(dtlsParameters.fingerprints[1].value === 'somethingelse', 'extracted second value');
t.end();

@@ -238,1 +244,53 @@ });

});
test('parseIceOptions', function(t) {
var result = SDPUtils.parseIceOptions('a=ice-options:trickle something');
t.ok(Array.isArray(result), 'returns an array of options');
t.ok(result.length === 2, 'returns two items for the given data');
t.ok(result[0] === 'trickle', 'first option equals "trickle"');
t.ok(result[1] === 'something', 'first option equals "something"');
t.end()
});
test('parseExtmap', function(t) {
var res = SDPUtils.parseExtmap('a=extmap:2 uri');
t.ok(res.id === 2, 'parses extmap id');
t.ok(res.uri === 'uri', 'parses extmap uri');
t.ok(res.direction === 'sendrecv', 'direction defaults to sendrecv');
res = SDPUtils.parseExtmap('a=extmap:2/sendonly uri');
t.ok(res.id === 2, 'parses extmap id when direction is present');
t.ok(res.direction === 'sendonly', 'parses extmap direction');
t.end();
});
test('writeExtmap', function(t) {
t.ok(SDPUtils.writeExtmap({id: 1, uri: 'uri'}) === 'a=extmap:1 uri\r\n',
'writes extmap without direction');
t.ok(SDPUtils.writeExtmap({id: 1, uri: 'uri', direction: 'sendrecv'}) === 'a=extmap:1 uri\r\n',
'writes extmap without direction when direction is sendrecv (default)');
t.ok(SDPUtils.writeExtmap({id: 1, uri: 'uri', direction: 'sendonly'}) === 'a=extmap:1/sendonly uri\r\n',
'writes extmap with direction when direction is not sendrecv');
t.end();
});
test('parseCandidate', function(t) {
var candidateString = 'candidate:702786350 2 udp 41819902 8.8.8.8 60769 ' +
'typ relay raddr 8.8.8.8 rport 1234 ' +
'tcptype active ' +
'ufrag abc';
var candidate = SDPUtils.parseCandidate(candidateString);
t.ok(candidate.foundation === '702786350', 'parsed foundation');
t.ok(candidate.component === '2', 'parsed component');
t.ok(candidate.priority === 41819902, 'parsed priority');
t.ok(candidate.ip === '8.8.8.8', 'parsed ip');
t.ok(candidate.protocol === 'udp', 'parsed protocol');
t.ok(candidate.port === 60769, 'parsed port');
t.ok(candidate.tcpType === 'active', 'parsed tcpType');
t.ok(candidate.relatedAddress === '8.8.8.8', 'parsed relatedAddress');
t.ok(candidate.relatedPort === 1234, 'parsed relatedPort');
t.ok(candidate.ufrag === 'abc', 'parsed ufrag');
t.end();
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc