reuse TransportToJingle

This commit is contained in:
Philipp Hancke 2013-12-29 18:11:33 +01:00 committed by Yana Stamcheva
parent 91c67c8a91
commit b2c6a91a60
2 changed files with 48 additions and 90 deletions

View File

@ -145,35 +145,8 @@ ColibriFocus.prototype._makeConference = function () {
elem.up(); elem.up();
} }
// FIXME: should reuse code from .toJingle localSDP.TransportToJingle(channel, elem);
elem.c('transport', {xmlns: 'urn:xmpp:jingle:transports:ice-udp:1'});
var tmp = SDPUtil.iceparams(media, localSDP.session);
if (tmp) {
elem.attrs(tmp);
var fingerprints = SDPUtil.find_lines(media, 'a=fingerprint:', localSDP.session);
fingerprints.forEach(function (line) {
tmp = SDPUtil.parse_fingerprint(line);
//tmp.xmlns = 'urn:xmpp:tmp:jingle:apps:dtls:0';
tmp.xmlns = 'urn:xmpp:jingle:apps:dtls:0';
elem.c('fingerprint').t(tmp.fingerprint);
delete tmp.fingerprint;
line = SDPUtil.find_line(media, 'a=setup:', ob.session);
if (line) {
tmp.setup = line.substr(8);
}
elem.attrs(tmp);
elem.up();
});
// XEP-0176
if (SDPUtil.find_line(media, 'a=candidate:', localSDP.session)) { // add any a=candidate lines
lines = SDPUtil.find_lines(media, 'a=candidate:', localSDP.session);
for (j = 0; j < lines.length; j++) {
tmp = SDPUtil.candidateToJingle(lines[j]);
elem.c('candidate', tmp).up();
}
}
elem.up(); // end of transport
}
elem.up(); // end of channel elem.up(); // end of channel
for (j = 0; j < ob.peers.length; j++) { for (j = 0; j < ob.peers.length; j++) {
elem.c('channel', {initiator: 'true', expire:'15' }).up(); elem.c('channel', {initiator: 'true', expire:'15' }).up();
@ -489,33 +462,9 @@ ColibriFocus.prototype.updateChannel = function (remoteSDP, participant) {
*/ */
change.up(); change.up();
}); });
// now add transport // now add transport
change.c('transport', {xmlns: 'urn:xmpp:jingle:transports:ice-udp:1'}); remoteSDP.TransportToJingle(channel, change);
var fingerprints = SDPUtil.find_lines(remoteSDP.media[channel], 'a=fingerprint:', remoteSDP.session);
fingerprints.forEach(function (line) {
tmp = SDPUtil.parse_fingerprint(line);
tmp.xmlns = 'urn:xmpp:jingle:apps:dtls:0';
change.c('fingerprint').t(tmp.fingerprint);
delete tmp.fingerprint;
line = SDPUtil.find_line(remoteSDP.media[channel], 'a=setup:', remoteSDP.session);
if (line) {
tmp.setup = line.substr(8);
}
change.attrs(tmp);
change.up();
});
var candidates = SDPUtil.find_lines(remoteSDP.media[channel], 'a=candidate:', remoteSDP.session);
candidates.forEach(function (line) {
var tmp = SDPUtil.candidateToJingle(line);
change.c('candidate', tmp).up();
});
tmp = SDPUtil.iceparams(remoteSDP.media[channel], remoteSDP.session);
if (tmp) {
change.attrs(tmp);
}
change.up(); // end of transport
change.up(); // end of channel change.up(); // end of channel
change.up(); // end of content change.up(); // end of content
} }

View File

@ -687,7 +687,7 @@ SDP.prototype.toJingle = function (elem, thecreator) {
elem.c('parameter', tmp[k]).up(); elem.c('parameter', tmp[k]).up();
} }
} }
this.RtcpFbToJingle(this.media[i], elem, mline.fmt[j]); // XEP-0293 -- map a=rtcp-fb this.RtcpFbToJingle(i, elem, mline.fmt[j]); // XEP-0293 -- map a=rtcp-fb
elem.up(); elem.up();
} }
@ -737,7 +737,7 @@ SDP.prototype.toJingle = function (elem, thecreator) {
} }
// XEP-0293 -- map a=rtcp-fb:* // XEP-0293 -- map a=rtcp-fb:*
this.RtcpFbToJingle(this.media[i], elem, '*'); this.RtcpFbToJingle(i, elem, '*');
// XEP-0294 // XEP-0294
if (SDPUtil.find_line(this.media[i], 'a=extmap:')) { if (SDPUtil.find_line(this.media[i], 'a=extmap:')) {
@ -770,35 +770,8 @@ SDP.prototype.toJingle = function (elem, thecreator) {
elem.up(); // end of description elem.up(); // end of description
} }
elem.c('transport', {xmlns: 'urn:xmpp:jingle:transports:ice-udp:1'}); // map ice-ufrag/pwd, dtls fingerprint, candidates
// XEP-0320 this.TransportToJingle(i, elem);
var fingerprints = SDPUtil.find_lines(this.media[i], 'a=fingerprint:', this.session);
fingerprints.forEach(function(line) {
tmp = SDPUtil.parse_fingerprint(line);
tmp.xmlns = 'urn:xmpp:tmp:jingle:apps:dtls:0';
// tmp.xmlns = 'urn:xmpp:jingle:apps:dtls:0'; -- FIXME: update receivers first
elem.c('fingerprint').t(tmp.fingerprint);
delete tmp.fingerprint;
line = SDPUtil.find_line(ob.media[i], 'a=setup:', ob.session);
if (line) {
tmp.setup = line.substr(8);
}
elem.attrs(tmp);
elem.up();
});
tmp = SDPUtil.iceparams(this.media[i], this.session);
if (tmp) {
elem.attrs(tmp);
// XEP-0176
if (SDPUtil.find_line(this.media[i], 'a=candidate:', this.session)) { // add any a=candidate lines
lines = SDPUtil.find_lines(this.media[i], 'a=candidate:', this.session);
for (j = 0; j < lines.length; j++) {
tmp = SDPUtil.candidateToJingle(lines[j]);
elem.c('candidate', tmp).up();
}
}
elem.up(); // end of transport
}
if (SDPUtil.find_line(this.media[i], 'a=sendrecv', this.session)) { if (SDPUtil.find_line(this.media[i], 'a=sendrecv', this.session)) {
elem.attrs({senders: 'both'}); elem.attrs({senders: 'both'});
@ -819,10 +792,46 @@ SDP.prototype.toJingle = function (elem, thecreator) {
return elem; return elem;
}; };
SDP.prototype.RtcpFbToJingle = function (sdp, elem, payloadtype) { // XEP-0293 SDP.prototype.TransportToJingle = function (mediaindex, elem) {
var lines = SDPUtil.find_lines(sdp, 'a=rtcp-fb:' + payloadtype); var i = mediaindex;
for (var i = 0; i < lines.length; i++) { var tmp;
var tmp = SDPUtil.parse_rtcpfb(lines[i]); var ob = this;
elem.c('transport');
// XEP-0320
var fingerprints = SDPUtil.find_lines(this.media[mediaindex], 'a=fingerprint:', this.session);
fingerprints.forEach(function(line) {
tmp = SDPUtil.parse_fingerprint(line);
tmp.xmlns = 'urn:xmpp:tmp:jingle:apps:dtls:0';
// tmp.xmlns = 'urn:xmpp:jingle:apps:dtls:0'; -- FIXME: update receivers first
elem.c('fingerprint').t(tmp.fingerprint);
delete tmp.fingerprint;
line = SDPUtil.find_line(ob.media[mediaindex], 'a=setup:', ob.session);
if (line) {
tmp.setup = line.substr(8);
}
elem.attrs(tmp);
elem.up(); // end of fingerprint
});
tmp = SDPUtil.iceparams(this.media[mediaindex], this.session);
if (tmp) {
tmp.xmlns = 'urn:xmpp:jingle:transports:ice-udp:1';
elem.attrs(tmp);
// XEP-0176
if (SDPUtil.find_line(this.media[mediaindex], 'a=candidate:', this.session)) { // add any a=candidate lines
var lines = SDPUtil.find_lines(this.media[mediaindex], 'a=candidate:', this.session);
lines.forEach(function (line) {
elem.c('candidate', SDPUtil.candidateToJingle(line)).up();
});
}
}
elem.up(); // end of transport
}
SDP.prototype.RtcpFbToJingle = function (mediaindex, elem, payloadtype) { // XEP-0293
var lines = SDPUtil.find_lines(this.media[mediaindex], 'a=rtcp-fb:' + payloadtype);
lines.forEach(function (line) {
var tmp = SDPUtil.parse_rtcpfb(line);
if (tmp.type == 'trr-int') { if (tmp.type == 'trr-int') {
elem.c('rtcp-fb-trr-int', {xmlns: 'urn:xmpp:jingle:apps:rtp:rtcp-fb:0', value: tmp.params[0]}); elem.c('rtcp-fb-trr-int', {xmlns: 'urn:xmpp:jingle:apps:rtp:rtcp-fb:0', value: tmp.params[0]});
elem.up(); elem.up();
@ -833,7 +842,7 @@ SDP.prototype.RtcpFbToJingle = function (sdp, elem, payloadtype) { // XEP-0293
} }
elem.up(); elem.up();
} }
} });
}; };
SDP.prototype.RtcpFbFromJingle = function (elem, payloadtype) { // XEP-0293 SDP.prototype.RtcpFbFromJingle = function (elem, payloadtype) { // XEP-0293