Comparing version 3.0.3 to 3.1.0
@@ -1,1 +0,1 @@ | ||
{"processes":{"d12e8ec5-0ac8-468a-ac39-70a07d494b89":{"parent":null,"children":[]}},"files":{"/media/fippo/houseparty/webrtc/sdp/sdp.js":["d12e8ec5-0ac8-468a-ac39-70a07d494b89"]},"externalIds":{}} | ||
{"processes":{"a9b935d8-5f14-4c64-b895-6b0ece2e9d7c":{"parent":null,"children":[]}},"files":{"/media/fippo/houseparty/webrtc/sdp/sdp.js":["a9b935d8-5f14-4c64-b895-6b0ece2e9d7c"]},"externalIds":{}} |
@@ -13,3 +13,3 @@ /* eslint-env node */ | ||
SDPUtils.generateIdentifier = function () { | ||
return Math.random().toString(36).substr(2, 10); | ||
return Math.random().toString(36).substring(2, 12); | ||
}; | ||
@@ -148,3 +148,3 @@ | ||
SDPUtils.parseIceOptions = function (line) { | ||
return line.substr(14).split(' '); | ||
return line.substring(14).split(' '); | ||
}; | ||
@@ -155,3 +155,3 @@ | ||
SDPUtils.parseRtpMap = function (line) { | ||
var parts = line.substr(9).split(' '); | ||
var parts = line.substring(9).split(' '); | ||
var parsed = { | ||
@@ -186,7 +186,8 @@ payloadType: parseInt(parts.shift(), 10) // was: id | ||
SDPUtils.parseExtmap = function (line) { | ||
var parts = line.substr(9).split(' '); | ||
var parts = line.substring(9).split(' '); | ||
return { | ||
id: parseInt(parts[0], 10), | ||
direction: parts[0].indexOf('/') > 0 ? parts[0].split('/')[1] : 'sendrecv', | ||
uri: parts[1] | ||
uri: parts[1], | ||
attributes: parts.slice(2).join(' ') | ||
}; | ||
@@ -198,3 +199,3 @@ }; | ||
SDPUtils.writeExtmap = function (headerExtension) { | ||
return 'a=extmap:' + (headerExtension.id || headerExtension.preferredId) + (headerExtension.direction && headerExtension.direction !== 'sendrecv' ? '/' + headerExtension.direction : '') + ' ' + headerExtension.uri + '\r\n'; | ||
return 'a=extmap:' + (headerExtension.id || headerExtension.preferredId) + (headerExtension.direction && headerExtension.direction !== 'sendrecv' ? '/' + headerExtension.direction : '') + ' ' + headerExtension.uri + (headerExtension.attributes ? ' ' + headerExtension.attributes : '') + '\r\n'; | ||
}; | ||
@@ -208,3 +209,3 @@ | ||
var kv = void 0; | ||
var parts = line.substr(line.indexOf(' ') + 1).split(';'); | ||
var parts = line.substring(line.indexOf(' ') + 1).split(';'); | ||
for (var j = 0; j < parts.length; j++) { | ||
@@ -241,3 +242,3 @@ kv = parts[j].trim().split('='); | ||
SDPUtils.parseRtcpFb = function (line) { | ||
var parts = line.substr(line.indexOf(' ') + 1).split(' '); | ||
var parts = line.substring(line.indexOf(' ') + 1).split(' '); | ||
return { | ||
@@ -270,10 +271,10 @@ type: parts.shift(), | ||
var parts = { | ||
ssrc: parseInt(line.substr(7, sp - 7), 10) | ||
ssrc: parseInt(line.substring(7, sp), 10) | ||
}; | ||
var colon = line.indexOf(':', sp); | ||
if (colon > -1) { | ||
parts.attribute = line.substr(sp + 1, colon - sp - 1); | ||
parts.value = line.substr(colon + 1); | ||
parts.attribute = line.substring(sp + 1, colon); | ||
parts.value = line.substring(colon + 1); | ||
} else { | ||
parts.attribute = line.substr(sp + 1); | ||
parts.attribute = line.substring(sp + 1); | ||
} | ||
@@ -286,3 +287,3 @@ return parts; | ||
SDPUtils.parseSsrcGroup = function (line) { | ||
var parts = line.substr(13).split(' '); | ||
var parts = line.substring(13).split(' '); | ||
return { | ||
@@ -301,3 +302,3 @@ semantics: parts.shift(), | ||
if (mid) { | ||
return mid.substr(6); | ||
return mid.substring(6); | ||
} | ||
@@ -308,3 +309,3 @@ }; | ||
SDPUtils.parseFingerprint = function (line) { | ||
var parts = line.substr(14).split(' '); | ||
var parts = line.substring(14).split(' '); | ||
return { | ||
@@ -340,3 +341,3 @@ algorithm: parts[0].toLowerCase(), // algorithm is case-sensitive in Edge. | ||
SDPUtils.parseCryptoLine = function (line) { | ||
var parts = line.substr(9).split(' '); | ||
var parts = line.substring(9).split(' '); | ||
return { | ||
@@ -360,3 +361,3 @@ tag: parseInt(parts[0], 10), | ||
} | ||
var parts = keyParams.substr(7).split('|'); | ||
var parts = keyParams.substring(7).split('|'); | ||
return { | ||
@@ -391,4 +392,4 @@ keyMethod: 'inline', | ||
return { | ||
usernameFragment: ufrag.substr(12), | ||
password: pwd.substr(10) | ||
usernameFragment: ufrag.substring(12), | ||
password: pwd.substring(10) | ||
}; | ||
@@ -442,2 +443,13 @@ }; | ||
}); | ||
var wildcardRtcpFb = SDPUtils.matchPrefix(mediaSection, 'a=rtcp-fb:* ').map(SDPUtils.parseRtcpFb); | ||
description.codecs.forEach(function (codec) { | ||
wildcardRtcpFb.forEach(function (fb) { | ||
var duplicate = codec.rtcpFeedback.find(function (existingFeedback) { | ||
return existingFeedback.type === fb.type && existingFeedback.parameter === fb.parameter; | ||
}); | ||
if (!duplicate) { | ||
codec.rtcpFeedback.push(fb); | ||
} | ||
}); | ||
}); | ||
// FIXME: parse rtcp. | ||
@@ -509,3 +521,3 @@ return description; | ||
var flows = SDPUtils.matchPrefix(mediaSection, 'a=ssrc-group:FID').map(function (line) { | ||
var parts = line.substr(17).split(' '); | ||
var parts = line.substring(17).split(' '); | ||
return parts.map(function (part) { | ||
@@ -549,6 +561,6 @@ return parseInt(part, 10); | ||
if (bandwidth[0].indexOf('b=TIAS:') === 0) { | ||
bandwidth = parseInt(bandwidth[0].substr(7), 10); | ||
bandwidth = parseInt(bandwidth[0].substring(7), 10); | ||
} else if (bandwidth[0].indexOf('b=AS:') === 0) { | ||
// use formula from JSEP to convert b=AS to TIAS value. | ||
bandwidth = parseInt(bandwidth[0].substr(5), 10) * 1000 * 0.95 - 50 * 40 * 8; | ||
bandwidth = parseInt(bandwidth[0].substring(5), 10) * 1000 * 0.95 - 50 * 40 * 8; | ||
} else { | ||
@@ -614,3 +626,3 @@ bandwidth = undefined; | ||
if (spec.length === 1) { | ||
parts = spec[0].substr(7).split(' '); | ||
parts = spec[0].substring(7).split(' '); | ||
return { stream: parts[0], track: parts[1] }; | ||
@@ -637,3 +649,3 @@ } | ||
if (maxSizeLine.length > 0) { | ||
maxMessageSize = parseInt(maxSizeLine[0].substr(19), 10); | ||
maxMessageSize = parseInt(maxSizeLine[0].substring(19), 10); | ||
} | ||
@@ -646,3 +658,3 @@ if (isNaN(maxMessageSize)) { | ||
return { | ||
port: parseInt(sctpPort[0].substr(12), 10), | ||
port: parseInt(sctpPort[0].substring(12), 10), | ||
protocol: mline.fmt, | ||
@@ -654,3 +666,3 @@ maxMessageSize: maxMessageSize | ||
if (sctpMapLines.length > 0) { | ||
var parts = sctpMapLines[0].substr(10).split(' '); | ||
var parts = sctpMapLines[0].substring(10).split(' '); | ||
return { | ||
@@ -687,3 +699,3 @@ port: parseInt(parts[0], 10), | ||
SDPUtils.generateSessionId = function () { | ||
return Math.random().toString().substr(2, 21); | ||
return Math.random().toString().substr(2, 22); | ||
}; | ||
@@ -719,3 +731,3 @@ | ||
case 'a=inactive': | ||
return lines[i].substr(2); | ||
return lines[i].substring(2); | ||
default: | ||
@@ -734,3 +746,3 @@ // FIXME: What should happen here? | ||
var mline = lines[0].split(' '); | ||
return mline[0].substr(2); | ||
return mline[0].substring(2); | ||
}; | ||
@@ -744,3 +756,3 @@ | ||
var lines = SDPUtils.splitLines(mediaSection); | ||
var parts = lines[0].substr(2).split(' '); | ||
var parts = lines[0].substring(2).split(' '); | ||
return { | ||
@@ -756,3 +768,3 @@ kind: parts[0], | ||
var line = SDPUtils.matchPrefix(mediaSection, 'o=')[0]; | ||
var parts = line.substr(2).split(' '); | ||
var parts = line.substring(2).split(' '); | ||
return { | ||
@@ -759,0 +771,0 @@ username: parts[0], |
{ | ||
"name": "sdp", | ||
"version": "3.0.3", | ||
"version": "3.1.0", | ||
"description": "SDP parsing and serialization utilities", | ||
@@ -14,5 +14,5 @@ "main": "dist/sdp.js", | ||
"build": "babel sdp.js --presets babel-preset-env --out-dir dist", | ||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov", | ||
"coverage": "c8 report --reporter=text-lcov > coverage.lcov", | ||
"prepare": "npm run build", | ||
"test": "eslint sdp.js test/sdp.js && nyc --reporter html mocha test/sdp.js" | ||
"test": "eslint sdp.js test/sdp.js && c8 --reporter html mocha test/sdp.js" | ||
}, | ||
@@ -29,10 +29,10 @@ "keywords": [ | ||
"babel-preset-env": "^1.7.0", | ||
"chai": "^4.0.0", | ||
"c8": "^7.12.0", | ||
"chai": "^4.3.7", | ||
"codecov": "^3.6.5", | ||
"eslint": "^6.0.1", | ||
"mocha": "^7.1.2", | ||
"nyc": "^14.1.1", | ||
"sinon": "^2.3.2", | ||
"sinon-chai": "^2.10.0" | ||
"eslint": "^8.31.0", | ||
"mocha": "^10.2.0", | ||
"sinon": "^15.0.1", | ||
"sinon-chai": "^3.7.0" | ||
} | ||
} |
@@ -47,2 +47,3 @@ export type SDPBlob = string; | ||
uri: string; | ||
atrributes: string | undefined; | ||
} | ||
@@ -49,0 +50,0 @@ |
76
sdp.js
@@ -10,3 +10,3 @@ /* eslint-env node */ | ||
SDPUtils.generateIdentifier = function() { | ||
return Math.random().toString(36).substr(2, 10); | ||
return Math.random().toString(36).substring(2, 12); | ||
}; | ||
@@ -140,3 +140,3 @@ | ||
SDPUtils.parseIceOptions = function(line) { | ||
return line.substr(14).split(' '); | ||
return line.substring(14).split(' '); | ||
}; | ||
@@ -147,3 +147,3 @@ | ||
SDPUtils.parseRtpMap = function(line) { | ||
let parts = line.substr(9).split(' '); | ||
let parts = line.substring(9).split(' '); | ||
const parsed = { | ||
@@ -179,3 +179,3 @@ payloadType: parseInt(parts.shift(), 10), // was: id | ||
SDPUtils.parseExtmap = function(line) { | ||
const parts = line.substr(9).split(' '); | ||
const parts = line.substring(9).split(' '); | ||
return { | ||
@@ -185,2 +185,3 @@ id: parseInt(parts[0], 10), | ||
uri: parts[1], | ||
attributes: parts.slice(2).join(' '), | ||
}; | ||
@@ -196,3 +197,5 @@ }; | ||
: '') + | ||
' ' + headerExtension.uri + '\r\n'; | ||
' ' + headerExtension.uri + | ||
(headerExtension.attributes ? ' ' + headerExtension.attributes : '') + | ||
'\r\n'; | ||
}; | ||
@@ -206,3 +209,3 @@ | ||
let kv; | ||
const parts = line.substr(line.indexOf(' ') + 1).split(';'); | ||
const parts = line.substring(line.indexOf(' ') + 1).split(';'); | ||
for (let j = 0; j < parts.length; j++) { | ||
@@ -239,3 +242,3 @@ kv = parts[j].trim().split('='); | ||
SDPUtils.parseRtcpFb = function(line) { | ||
const parts = line.substr(line.indexOf(' ') + 1).split(' '); | ||
const parts = line.substring(line.indexOf(' ') + 1).split(' '); | ||
return { | ||
@@ -270,10 +273,10 @@ type: parts.shift(), | ||
const parts = { | ||
ssrc: parseInt(line.substr(7, sp - 7), 10), | ||
ssrc: parseInt(line.substring(7, sp), 10), | ||
}; | ||
const colon = line.indexOf(':', sp); | ||
if (colon > -1) { | ||
parts.attribute = line.substr(sp + 1, colon - sp - 1); | ||
parts.value = line.substr(colon + 1); | ||
parts.attribute = line.substring(sp + 1, colon); | ||
parts.value = line.substring(colon + 1); | ||
} else { | ||
parts.attribute = line.substr(sp + 1); | ||
parts.attribute = line.substring(sp + 1); | ||
} | ||
@@ -286,3 +289,3 @@ return parts; | ||
SDPUtils.parseSsrcGroup = function(line) { | ||
const parts = line.substr(13).split(' '); | ||
const parts = line.substring(13).split(' '); | ||
return { | ||
@@ -299,3 +302,3 @@ semantics: parts.shift(), | ||
if (mid) { | ||
return mid.substr(6); | ||
return mid.substring(6); | ||
} | ||
@@ -306,3 +309,3 @@ }; | ||
SDPUtils.parseFingerprint = function(line) { | ||
const parts = line.substr(14).split(' '); | ||
const parts = line.substring(14).split(' '); | ||
return { | ||
@@ -339,3 +342,3 @@ algorithm: parts[0].toLowerCase(), // algorithm is case-sensitive in Edge. | ||
SDPUtils.parseCryptoLine = function(line) { | ||
const parts = line.substr(9).split(' '); | ||
const parts = line.substring(9).split(' '); | ||
return { | ||
@@ -365,3 +368,3 @@ tag: parseInt(parts[0], 10), | ||
} | ||
const parts = keyParams.substr(7).split('|'); | ||
const parts = keyParams.substring(7).split('|'); | ||
return { | ||
@@ -404,4 +407,4 @@ keyMethod: 'inline', | ||
return { | ||
usernameFragment: ufrag.substr(12), | ||
password: pwd.substr(10), | ||
usernameFragment: ufrag.substring(12), | ||
password: pwd.substring(10), | ||
}; | ||
@@ -458,2 +461,15 @@ }; | ||
}); | ||
const wildcardRtcpFb = SDPUtils.matchPrefix(mediaSection, 'a=rtcp-fb:* ') | ||
.map(SDPUtils.parseRtcpFb); | ||
description.codecs.forEach(codec => { | ||
wildcardRtcpFb.forEach(fb=> { | ||
const duplicate = codec.rtcpFeedback.find(existingFeedback => { | ||
return existingFeedback.type === fb.type && | ||
existingFeedback.parameter === fb.parameter; | ||
}); | ||
if (!duplicate) { | ||
codec.rtcpFeedback.push(fb); | ||
} | ||
}); | ||
}); | ||
// FIXME: parse rtcp. | ||
@@ -524,3 +540,3 @@ return description; | ||
.map(line => { | ||
const parts = line.substr(17).split(' '); | ||
const parts = line.substring(17).split(' '); | ||
return parts.map(part => parseInt(part, 10)); | ||
@@ -562,6 +578,6 @@ }); | ||
if (bandwidth[0].indexOf('b=TIAS:') === 0) { | ||
bandwidth = parseInt(bandwidth[0].substr(7), 10); | ||
bandwidth = parseInt(bandwidth[0].substring(7), 10); | ||
} else if (bandwidth[0].indexOf('b=AS:') === 0) { | ||
// use formula from JSEP to convert b=AS to TIAS value. | ||
bandwidth = parseInt(bandwidth[0].substr(5), 10) * 1000 * 0.95 | ||
bandwidth = parseInt(bandwidth[0].substring(5), 10) * 1000 * 0.95 | ||
- (50 * 40 * 8); | ||
@@ -628,3 +644,3 @@ } else { | ||
if (spec.length === 1) { | ||
parts = spec[0].substr(7).split(' '); | ||
parts = spec[0].substring(7).split(' '); | ||
return {stream: parts[0], track: parts[1]}; | ||
@@ -649,3 +665,3 @@ } | ||
if (maxSizeLine.length > 0) { | ||
maxMessageSize = parseInt(maxSizeLine[0].substr(19), 10); | ||
maxMessageSize = parseInt(maxSizeLine[0].substring(19), 10); | ||
} | ||
@@ -658,3 +674,3 @@ if (isNaN(maxMessageSize)) { | ||
return { | ||
port: parseInt(sctpPort[0].substr(12), 10), | ||
port: parseInt(sctpPort[0].substring(12), 10), | ||
protocol: mline.fmt, | ||
@@ -667,3 +683,3 @@ maxMessageSize, | ||
const parts = sctpMapLines[0] | ||
.substr(10) | ||
.substring(10) | ||
.split(' '); | ||
@@ -709,3 +725,3 @@ return { | ||
SDPUtils.generateSessionId = function() { | ||
return Math.random().toString().substr(2, 21); | ||
return Math.random().toString().substr(2, 22); | ||
}; | ||
@@ -745,3 +761,3 @@ | ||
case 'a=inactive': | ||
return lines[i].substr(2); | ||
return lines[i].substring(2); | ||
default: | ||
@@ -760,3 +776,3 @@ // FIXME: What should happen here? | ||
const mline = lines[0].split(' '); | ||
return mline[0].substr(2); | ||
return mline[0].substring(2); | ||
}; | ||
@@ -770,3 +786,3 @@ | ||
const lines = SDPUtils.splitLines(mediaSection); | ||
const parts = lines[0].substr(2).split(' '); | ||
const parts = lines[0].substring(2).split(' '); | ||
return { | ||
@@ -782,3 +798,3 @@ kind: parts[0], | ||
const line = SDPUtils.matchPrefix(mediaSection, 'o=')[0]; | ||
const parts = line.substr(2).split(' '); | ||
const parts = line.substring(2).split(' '); | ||
return { | ||
@@ -785,0 +801,0 @@ username: parts[0], |
Sorry, the diff of this file is not supported yet
142480
12
1613