Skip to content

Commit

Permalink
update sjj to work with latest sdp examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jensengar committed Sep 6, 2019
1 parent ffb0dea commit 8e4913a
Show file tree
Hide file tree
Showing 11 changed files with 2,240 additions and 167 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
build
.vscode
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sudo: false
language: node_js
node_js:
- '0.10'
- 10
21 changes: 20 additions & 1 deletion lib/tojson.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ exports.toSessionJSON = function (sdp, opts) {
}
var session = media.shift() + '\r\n';
var sessionLines = parsers.lines(session);
var type;
if (sessionLines[0].indexOf('type:') >= 0) {
type = sessionLines[0].split('type:')[1].split(',')[0].trim();
}
var parsed = {};

var contents = [];
Expand All @@ -35,6 +39,7 @@ exports.toSessionJSON = function (sdp, opts) {
}));
}
parsed.contents = contents;
parsed.type = type;

var groupLines = parsers.findLines('a=group:', sessionLines);
if (groupLines.length) {
Expand All @@ -60,6 +65,7 @@ exports.toMediaJSON = function (media, session, opts) {
applicationType: 'rtp',
media: mline.media,
payloads: [],
port: mline.port,
encryption: [],
feedback: [],
headerExtensions: []
Expand All @@ -73,8 +79,17 @@ exports.toMediaJSON = function (media, session, opts) {
if (mline.media == 'application') {
// FIXME: the description is most likely to be independent
// of the SDP and should be processed by other parts of the library

var sctpLine = parsers.findLine('a=sctp-port', lines);
var sctpPort = sctpLine && sctpLine.split('sctp-port:')[1];
var maxMessageSizeLine = parsers.findLine('a=max-message-size', lines);
var maxMessageSize = maxMessageSizeLine && maxMessageSizeLine.split('max-message-size:')[1];

content.application = {
applicationType: 'datachannel'
applicationType: 'datachannel',
port: mline.port,
sctpPort: sctpPort,
maxMessageSize: maxMessageSize
};
content.transport.sctp = [];
}
Expand Down Expand Up @@ -194,6 +209,10 @@ exports.toMediaJSON = function (media, session, opts) {
trans.fingerprints.push(fp);
});

if (parsers.findLine('a=ice-options:trickle', lines)) {
trans.trickleIce = true;
}

var ufragLine = parsers.findLine('a=ice-ufrag:', lines, sessionLines);
var pwdLine = parsers.findLine('a=ice-pwd:', lines, sessionLines);
if (ufragLine && pwdLine) {
Expand Down
25 changes: 19 additions & 6 deletions lib/tosdp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ exports.toSessionSDP = function (session, opts) {
var sid = opts.sid || session.sid || Date.now();
var time = opts.time || Date.now();

var type = (session.type && 'type: ' + session.type + ', ') || '';

var sdp = [
'v=0',
type + 'sdp: v=0',
'o=- ' + sid + ' ' + time + ' IN IP4 0.0.0.0',
's=-',
't=0 0'
Expand Down Expand Up @@ -54,16 +56,17 @@ exports.toMediaSDP = function (content, opts) {
var mline = [];
if (desc.applicationType == 'datachannel') {
mline.push('application');
mline.push('1');
mline.push('DTLS/SCTP');
mline.push(desc.port);
mline.push('UDP/DTLS/SCTP');
mline.push('webrtc-datachannel');
if (transport.sctp) {
transport.sctp.forEach(function (map) {
mline.push(map.number);
});
}
} else {
mline.push(desc.media);
mline.push('1');
mline.push(desc.port);
if (fingerprints.length > 0) {
mline.push('UDP/TLS/RTP/SAVPF');
} else if (desc.encryption && desc.encryption.length > 0) {
Expand All @@ -76,15 +79,22 @@ exports.toMediaSDP = function (content, opts) {
});
}


sdp.push('m=' + mline.join(' '));

sdp.push('c=IN IP4 0.0.0.0');
if (desc.bandwidth && desc.bandwidth.type && desc.bandwidth.bandwidth) {
sdp.push('b=' + desc.bandwidth.type + ':' + desc.bandwidth.bandwidth);
}
if (desc.applicationType == 'rtp') {
sdp.push('a=rtcp:1 IN IP4 0.0.0.0');
sdp.push('a=rtcp:' + desc.port + ' IN IP4 0.0.0.0');
}

if (desc.maxMessageSize) {
sdp.push('a=max-message-size:' + desc.maxMessageSize);
}

if (desc.sctpPort) {
sdp.push('a=sctp-port:' + desc.sctpPort);
}

if (transport) {
Expand All @@ -94,6 +104,9 @@ exports.toMediaSDP = function (content, opts) {
if (transport.pwd) {
sdp.push('a=ice-pwd:' + transport.pwd);
}
if (transport.trickleIce) {
sdp.push('a=ice-options:trickle');
}

var pushedSetup = false;
fingerprints.forEach(function (fingerprint) {
Expand Down
Loading

0 comments on commit 8e4913a

Please sign in to comment.