You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

strophe.jingle.sdp.js 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. /* jshint -W117 */
  2. // SDP STUFF
  3. function SDP(sdp) {
  4. this.media = sdp.split('\r\nm=');
  5. for (var i = 1; i < this.media.length; i++) {
  6. this.media[i] = 'm=' + this.media[i];
  7. if (i != this.media.length - 1) {
  8. this.media[i] += '\r\n';
  9. }
  10. }
  11. this.session = this.media.shift() + '\r\n';
  12. this.raw = this.session + this.media.join('');
  13. }
  14. /**
  15. * Returns map of MediaChannel mapped per channel idx.
  16. */
  17. SDP.prototype.getMediaSsrcMap = function() {
  18. var self = this;
  19. var media_ssrcs = {};
  20. for (channelNum = 0; channelNum < self.media.length; channelNum++) {
  21. modified = true;
  22. tmp = SDPUtil.find_lines(self.media[channelNum], 'a=ssrc:');
  23. var type = SDPUtil.parse_mid(SDPUtil.find_line(self.media[channelNum], 'a=mid:'));
  24. var channel = new MediaChannel(channelNum, type);
  25. media_ssrcs[channelNum] = channel;
  26. tmp.forEach(function (line) {
  27. var linessrc = line.substring(7).split(' ')[0];
  28. // allocate new ChannelSsrc
  29. if(!channel.ssrcs[linessrc]) {
  30. channel.ssrcs[linessrc] = new ChannelSsrc(linessrc, type);
  31. }
  32. channel.ssrcs[linessrc].lines.push(line);
  33. });
  34. }
  35. return media_ssrcs;
  36. }
  37. /**
  38. * Returns <tt>true</tt> if this SDP contains given SSRC.
  39. * @param ssrc the ssrc to check.
  40. * @returns {boolean} <tt>true</tt> if this SDP contains given SSRC.
  41. */
  42. SDP.prototype.containsSSRC = function(ssrc) {
  43. var channels = this.getMediaSsrcMap();
  44. var contains = false;
  45. Object.keys(channels).forEach(function(chNumber){
  46. var channel = channels[chNumber];
  47. //console.log("Check", channel, ssrc);
  48. if(Object.keys(channel.ssrcs).indexOf(ssrc) != -1){
  49. contains = true;
  50. }
  51. });
  52. return contains;
  53. }
  54. /**
  55. * Returns map of MediaChannel that contains only media not contained in <tt>otherSdp</tt>. Mapped by channel idx.
  56. * @param otherSdp the other SDP to check ssrc with.
  57. */
  58. SDP.prototype.getNewMedia = function(otherSdp) {
  59. var myMedia = this.getMediaSsrcMap();
  60. var othersMedia = otherSdp.getMediaSsrcMap();
  61. var newMedia = {};
  62. Object.keys(othersMedia).forEach(function(channelNum) {
  63. var myChannel = myMedia[channelNum];
  64. var othersChannel = othersMedia[channelNum];
  65. if(!myChannel && othersChannel) {
  66. // Add whole channel
  67. newMedia[channelNum] = othersChannel;
  68. return;
  69. }
  70. // Look for new ssrcs accross the channel
  71. Object.keys(othersChannel.ssrcs).forEach(function(ssrc) {
  72. if(Object.keys(myChannel.ssrcs).indexOf(ssrc) === -1) {
  73. // Allocate channel if we've found ssrc that doesn't exist in our channel
  74. if(!newMedia[channelNum]){
  75. newMedia[channelNum] = new MediaChannel(othersChannel.chNumber, othersChannel.mediaType);
  76. }
  77. newMedia[channelNum].ssrcs[ssrc] = othersChannel.ssrcs[ssrc];
  78. }
  79. })
  80. });
  81. return newMedia;
  82. }
  83. // remove iSAC and CN from SDP
  84. SDP.prototype.mangle = function () {
  85. var i, j, mline, lines, rtpmap, newdesc;
  86. for (i = 0; i < this.media.length; i++) {
  87. lines = this.media[i].split('\r\n');
  88. lines.pop(); // remove empty last element
  89. mline = SDPUtil.parse_mline(lines.shift());
  90. if (mline.media != 'audio')
  91. continue;
  92. newdesc = '';
  93. mline.fmt.length = 0;
  94. for (j = 0; j < lines.length; j++) {
  95. if (lines[j].substr(0, 9) == 'a=rtpmap:') {
  96. rtpmap = SDPUtil.parse_rtpmap(lines[j]);
  97. if (rtpmap.name == 'CN' || rtpmap.name == 'ISAC')
  98. continue;
  99. mline.fmt.push(rtpmap.id);
  100. newdesc += lines[j] + '\r\n';
  101. } else {
  102. newdesc += lines[j] + '\r\n';
  103. }
  104. }
  105. this.media[i] = SDPUtil.build_mline(mline) + '\r\n';
  106. this.media[i] += newdesc;
  107. }
  108. this.raw = this.session + this.media.join('');
  109. };
  110. // remove lines matching prefix from session section
  111. SDP.prototype.removeSessionLines = function(prefix) {
  112. var self = this;
  113. var lines = SDPUtil.find_lines(this.session, prefix);
  114. lines.forEach(function(line) {
  115. self.session = self.session.replace(line + '\r\n', '');
  116. });
  117. this.raw = this.session + this.media.join('');
  118. return lines;
  119. }
  120. // remove lines matching prefix from a media section specified by mediaindex
  121. // TODO: non-numeric mediaindex could match mid
  122. SDP.prototype.removeMediaLines = function(mediaindex, prefix) {
  123. var self = this;
  124. var lines = SDPUtil.find_lines(this.media[mediaindex], prefix);
  125. lines.forEach(function(line) {
  126. self.media[mediaindex] = self.media[mediaindex].replace(line + '\r\n', '');
  127. });
  128. this.raw = this.session + this.media.join('');
  129. return lines;
  130. }
  131. // add content's to a jingle element
  132. SDP.prototype.toJingle = function (elem, thecreator) {
  133. var i, j, k, mline, ssrc, rtpmap, tmp, line, lines;
  134. var self = this;
  135. // new bundle plan
  136. if (SDPUtil.find_line(this.session, 'a=group:')) {
  137. lines = SDPUtil.find_lines(this.session, 'a=group:');
  138. for (i = 0; i < lines.length; i++) {
  139. tmp = lines[i].split(' ');
  140. var semantics = tmp.shift().substr(8);
  141. elem.c('group', {xmlns: 'urn:xmpp:jingle:apps:grouping:0', semantics:semantics});
  142. for (j = 0; j < tmp.length; j++) {
  143. elem.c('content', {name: tmp[j]}).up();
  144. }
  145. elem.up();
  146. }
  147. }
  148. // old bundle plan, to be removed
  149. var bundle = [];
  150. if (SDPUtil.find_line(this.session, 'a=group:BUNDLE')) {
  151. bundle = SDPUtil.find_line(this.session, 'a=group:BUNDLE ').split(' ');
  152. bundle.shift();
  153. }
  154. for (i = 0; i < this.media.length; i++) {
  155. mline = SDPUtil.parse_mline(this.media[i].split('\r\n')[0]);
  156. if (!(mline.media == 'audio' || mline.media == 'video')) {
  157. continue;
  158. }
  159. if (SDPUtil.find_line(this.media[i], 'a=ssrc:')) {
  160. ssrc = SDPUtil.find_line(this.media[i], 'a=ssrc:').substring(7).split(' ')[0]; // take the first
  161. } else {
  162. ssrc = false;
  163. }
  164. elem.c('content', {creator: thecreator, name: mline.media});
  165. if (SDPUtil.find_line(this.media[i], 'a=mid:')) {
  166. // prefer identifier from a=mid if present
  167. var mid = SDPUtil.parse_mid(SDPUtil.find_line(this.media[i], 'a=mid:'));
  168. elem.attrs({ name: mid });
  169. // old BUNDLE plan, to be removed
  170. if (bundle.indexOf(mid) != -1) {
  171. elem.c('bundle', {xmlns: 'http://estos.de/ns/bundle'}).up();
  172. bundle.splice(bundle.indexOf(mid), 1);
  173. }
  174. }
  175. if (SDPUtil.find_line(this.media[i], 'a=rtpmap:').length) {
  176. elem.c('description',
  177. {xmlns: 'urn:xmpp:jingle:apps:rtp:1',
  178. media: mline.media });
  179. if (ssrc) {
  180. elem.attrs({ssrc: ssrc});
  181. }
  182. for (j = 0; j < mline.fmt.length; j++) {
  183. rtpmap = SDPUtil.find_line(this.media[i], 'a=rtpmap:' + mline.fmt[j]);
  184. elem.c('payload-type', SDPUtil.parse_rtpmap(rtpmap));
  185. // put any 'a=fmtp:' + mline.fmt[j] lines into <param name=foo value=bar/>
  186. if (SDPUtil.find_line(this.media[i], 'a=fmtp:' + mline.fmt[j])) {
  187. tmp = SDPUtil.parse_fmtp(SDPUtil.find_line(this.media[i], 'a=fmtp:' + mline.fmt[j]));
  188. for (k = 0; k < tmp.length; k++) {
  189. elem.c('parameter', tmp[k]).up();
  190. }
  191. }
  192. this.RtcpFbToJingle(i, elem, mline.fmt[j]); // XEP-0293 -- map a=rtcp-fb
  193. elem.up();
  194. }
  195. if (SDPUtil.find_line(this.media[i], 'a=crypto:', this.session)) {
  196. elem.c('encryption', {required: 1});
  197. var crypto = SDPUtil.find_lines(this.media[i], 'a=crypto:', this.session);
  198. crypto.forEach(function(line) {
  199. elem.c('crypto', SDPUtil.parse_crypto(line)).up();
  200. });
  201. elem.up(); // end of encryption
  202. }
  203. if (ssrc) {
  204. // new style mapping
  205. elem.c('source', { ssrc: ssrc, xmlns: 'urn:xmpp:jingle:apps:rtp:ssma:0' });
  206. // FIXME: group by ssrc and support multiple different ssrcs
  207. var ssrclines = SDPUtil.find_lines(this.media[i], 'a=ssrc:');
  208. ssrclines.forEach(function(line) {
  209. idx = line.indexOf(' ');
  210. var linessrc = line.substr(0, idx).substr(7);
  211. if (linessrc != ssrc) {
  212. elem.up();
  213. ssrc = linessrc;
  214. elem.c('source', { ssrc: ssrc, xmlns: 'urn:xmpp:jingle:apps:rtp:ssma:0' });
  215. }
  216. var kv = line.substr(idx + 1);
  217. elem.c('parameter');
  218. if (kv.indexOf(':') == -1) {
  219. elem.attrs({ name: kv });
  220. } else {
  221. elem.attrs({ name: kv.split(':', 2)[0] });
  222. elem.attrs({ value: kv.split(':', 2)[1] });
  223. }
  224. elem.up();
  225. });
  226. elem.up();
  227. // old proprietary mapping, to be removed at some point
  228. tmp = SDPUtil.parse_ssrc(this.media[i]);
  229. tmp.xmlns = 'http://estos.de/ns/ssrc';
  230. tmp.ssrc = ssrc;
  231. elem.c('ssrc', tmp).up(); // ssrc is part of description
  232. }
  233. if (SDPUtil.find_line(this.media[i], 'a=rtcp-mux')) {
  234. elem.c('rtcp-mux').up();
  235. }
  236. // XEP-0293 -- map a=rtcp-fb:*
  237. this.RtcpFbToJingle(i, elem, '*');
  238. // XEP-0294
  239. if (SDPUtil.find_line(this.media[i], 'a=extmap:')) {
  240. lines = SDPUtil.find_lines(this.media[i], 'a=extmap:');
  241. for (j = 0; j < lines.length; j++) {
  242. tmp = SDPUtil.parse_extmap(lines[j]);
  243. elem.c('rtp-hdrext', { xmlns: 'urn:xmpp:jingle:apps:rtp:rtp-hdrext:0',
  244. uri: tmp.uri,
  245. id: tmp.value });
  246. if (tmp.hasOwnProperty('direction')) {
  247. switch (tmp.direction) {
  248. case 'sendonly':
  249. elem.attrs({senders: 'responder'});
  250. break;
  251. case 'recvonly':
  252. elem.attrs({senders: 'initiator'});
  253. break;
  254. case 'sendrecv':
  255. elem.attrs({senders: 'both'});
  256. break;
  257. case 'inactive':
  258. elem.attrs({senders: 'none'});
  259. break;
  260. }
  261. }
  262. // TODO: handle params
  263. elem.up();
  264. }
  265. }
  266. elem.up(); // end of description
  267. }
  268. // map ice-ufrag/pwd, dtls fingerprint, candidates
  269. this.TransportToJingle(i, elem);
  270. if (SDPUtil.find_line(this.media[i], 'a=sendrecv', this.session)) {
  271. elem.attrs({senders: 'both'});
  272. } else if (SDPUtil.find_line(this.media[i], 'a=sendonly', this.session)) {
  273. elem.attrs({senders: 'initiator'});
  274. } else if (SDPUtil.find_line(this.media[i], 'a=recvonly', this.session)) {
  275. elem.attrs({senders: 'responder'});
  276. } else if (SDPUtil.find_line(this.media[i], 'a=inactive', this.session)) {
  277. elem.attrs({senders: 'none'});
  278. }
  279. if (mline.port == '0') {
  280. // estos hack to reject an m-line
  281. elem.attrs({senders: 'rejected'});
  282. }
  283. elem.up(); // end of content
  284. }
  285. elem.up();
  286. return elem;
  287. };
  288. SDP.prototype.TransportToJingle = function (mediaindex, elem) {
  289. var i = mediaindex;
  290. var tmp;
  291. var self = this;
  292. elem.c('transport');
  293. // XEP-0320
  294. var fingerprints = SDPUtil.find_lines(this.media[mediaindex], 'a=fingerprint:', this.session);
  295. fingerprints.forEach(function(line) {
  296. tmp = SDPUtil.parse_fingerprint(line);
  297. tmp.xmlns = 'urn:xmpp:tmp:jingle:apps:dtls:0';
  298. // tmp.xmlns = 'urn:xmpp:jingle:apps:dtls:0'; -- FIXME: update receivers first
  299. elem.c('fingerprint').t(tmp.fingerprint);
  300. delete tmp.fingerprint;
  301. line = SDPUtil.find_line(self.media[mediaindex], 'a=setup:', self.session);
  302. if (line) {
  303. tmp.setup = line.substr(8);
  304. }
  305. elem.attrs(tmp);
  306. elem.up(); // end of fingerprint
  307. });
  308. tmp = SDPUtil.iceparams(this.media[mediaindex], this.session);
  309. if (tmp) {
  310. tmp.xmlns = 'urn:xmpp:jingle:transports:ice-udp:1';
  311. elem.attrs(tmp);
  312. // XEP-0176
  313. if (SDPUtil.find_line(this.media[mediaindex], 'a=candidate:', this.session)) { // add any a=candidate lines
  314. var lines = SDPUtil.find_lines(this.media[mediaindex], 'a=candidate:', this.session);
  315. lines.forEach(function (line) {
  316. elem.c('candidate', SDPUtil.candidateToJingle(line)).up();
  317. });
  318. }
  319. }
  320. elem.up(); // end of transport
  321. }
  322. SDP.prototype.RtcpFbToJingle = function (mediaindex, elem, payloadtype) { // XEP-0293
  323. var lines = SDPUtil.find_lines(this.media[mediaindex], 'a=rtcp-fb:' + payloadtype);
  324. lines.forEach(function (line) {
  325. var tmp = SDPUtil.parse_rtcpfb(line);
  326. if (tmp.type == 'trr-int') {
  327. elem.c('rtcp-fb-trr-int', {xmlns: 'urn:xmpp:jingle:apps:rtp:rtcp-fb:0', value: tmp.params[0]});
  328. elem.up();
  329. } else {
  330. elem.c('rtcp-fb', {xmlns: 'urn:xmpp:jingle:apps:rtp:rtcp-fb:0', type: tmp.type});
  331. if (tmp.params.length > 0) {
  332. elem.attrs({'subtype': tmp.params[0]});
  333. }
  334. elem.up();
  335. }
  336. });
  337. };
  338. SDP.prototype.RtcpFbFromJingle = function (elem, payloadtype) { // XEP-0293
  339. var media = '';
  340. var tmp = elem.find('>rtcp-fb-trr-int[xmlns="urn:xmpp:jingle:apps:rtp:rtcp-fb:0"]');
  341. if (tmp.length) {
  342. media += 'a=rtcp-fb:' + '*' + ' ' + 'trr-int' + ' ';
  343. if (tmp.attr('value')) {
  344. media += tmp.attr('value');
  345. } else {
  346. media += '0';
  347. }
  348. media += '\r\n';
  349. }
  350. tmp = elem.find('>rtcp-fb[xmlns="urn:xmpp:jingle:apps:rtp:rtcp-fb:0"]');
  351. tmp.each(function () {
  352. media += 'a=rtcp-fb:' + payloadtype + ' ' + $(this).attr('type');
  353. if ($(this).attr('subtype')) {
  354. media += ' ' + $(this).attr('subtype');
  355. }
  356. media += '\r\n';
  357. });
  358. return media;
  359. };
  360. // construct an SDP from a jingle stanza
  361. SDP.prototype.fromJingle = function (jingle) {
  362. var self = this;
  363. this.raw = 'v=0\r\n' +
  364. 'o=- ' + '1923518516' + ' 2 IN IP4 0.0.0.0\r\n' +// FIXME
  365. 's=-\r\n' +
  366. 't=0 0\r\n';
  367. // http://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-04#section-8
  368. if ($(jingle).find('>group[xmlns="urn:xmpp:jingle:apps:grouping:0"]').length) {
  369. $(jingle).find('>group[xmlns="urn:xmpp:jingle:apps:grouping:0"]').each(function (idx, group) {
  370. var contents = $(group).find('>content').map(function (idx, content) {
  371. return content.getAttribute('name');
  372. }).get();
  373. if (contents.length > 0) {
  374. self.raw += 'a=group:' + (group.getAttribute('semantics') || group.getAttribute('type')) + ' ' + contents.join(' ') + '\r\n';
  375. }
  376. });
  377. } else if ($(jingle).find('>group[xmlns="urn:ietf:rfc:5888"]').length) {
  378. // temporary namespace, not to be used. to be removed soon.
  379. $(jingle).find('>group[xmlns="urn:ietf:rfc:5888"]').each(function (idx, group) {
  380. var contents = $(group).find('>content').map(function (idx, content) {
  381. return content.getAttribute('name');
  382. }).get();
  383. if (group.getAttribute('type') !== null && contents.length > 0) {
  384. self.raw += 'a=group:' + group.getAttribute('type') + ' ' + contents.join(' ') + '\r\n';
  385. }
  386. });
  387. } else {
  388. // for backward compability, to be removed soon
  389. // assume all contents are in the same bundle group, can be improved upon later
  390. var bundle = $(jingle).find('>content').filter(function (idx, content) {
  391. //elem.c('bundle', {xmlns:'http://estos.de/ns/bundle'});
  392. return $(content).find('>bundle').length > 0;
  393. }).map(function (idx, content) {
  394. return content.getAttribute('name');
  395. }).get();
  396. if (bundle.length) {
  397. this.raw += 'a=group:BUNDLE ' + bundle.join(' ') + '\r\n';
  398. }
  399. }
  400. this.session = this.raw;
  401. jingle.find('>content').each(function () {
  402. var m = self.jingle2media($(this));
  403. self.media.push(m);
  404. });
  405. // reconstruct msid-semantic -- apparently not necessary
  406. /*
  407. var msid = SDPUtil.parse_ssrc(this.raw);
  408. if (msid.hasOwnProperty('mslabel')) {
  409. this.session += "a=msid-semantic: WMS " + msid.mslabel + "\r\n";
  410. }
  411. */
  412. this.raw = this.session + this.media.join('');
  413. };
  414. // translate a jingle content element into an an SDP media part
  415. SDP.prototype.jingle2media = function (content) {
  416. var media = '',
  417. desc = content.find('description'),
  418. ssrc = desc.attr('ssrc'),
  419. self = this,
  420. tmp;
  421. tmp = { media: desc.attr('media') };
  422. tmp.port = '1';
  423. if (content.attr('senders') == 'rejected') {
  424. // estos hack to reject an m-line.
  425. tmp.port = '0';
  426. }
  427. if (content.find('>transport>fingerprint').length || desc.find('encryption').length) {
  428. tmp.proto = 'RTP/SAVPF';
  429. } else {
  430. tmp.proto = 'RTP/AVPF';
  431. }
  432. tmp.fmt = desc.find('payload-type').map(function () { return this.getAttribute('id'); }).get();
  433. media += SDPUtil.build_mline(tmp) + '\r\n';
  434. media += 'c=IN IP4 0.0.0.0\r\n';
  435. media += 'a=rtcp:1 IN IP4 0.0.0.0\r\n';
  436. tmp = content.find('>transport[xmlns="urn:xmpp:jingle:transports:ice-udp:1"]');
  437. if (tmp.length) {
  438. if (tmp.attr('ufrag')) {
  439. media += SDPUtil.build_iceufrag(tmp.attr('ufrag')) + '\r\n';
  440. }
  441. if (tmp.attr('pwd')) {
  442. media += SDPUtil.build_icepwd(tmp.attr('pwd')) + '\r\n';
  443. }
  444. tmp.find('>fingerprint').each(function () {
  445. // FIXME: check namespace at some point
  446. media += 'a=fingerprint:' + this.getAttribute('hash');
  447. media += ' ' + $(this).text();
  448. media += '\r\n';
  449. if (this.getAttribute('setup')) {
  450. media += 'a=setup:' + this.getAttribute('setup') + '\r\n';
  451. }
  452. });
  453. }
  454. switch (content.attr('senders')) {
  455. case 'initiator':
  456. media += 'a=sendonly\r\n';
  457. break;
  458. case 'responder':
  459. media += 'a=recvonly\r\n';
  460. break;
  461. case 'none':
  462. media += 'a=inactive\r\n';
  463. break;
  464. case 'both':
  465. media += 'a=sendrecv\r\n';
  466. break;
  467. }
  468. media += 'a=mid:' + content.attr('name') + '\r\n';
  469. // <description><rtcp-mux/></description>
  470. // see http://code.google.com/p/libjingle/issues/detail?id=309 -- no spec though
  471. // and http://mail.jabber.org/pipermail/jingle/2011-December/001761.html
  472. if (desc.find('rtcp-mux').length) {
  473. media += 'a=rtcp-mux\r\n';
  474. }
  475. if (desc.find('encryption').length) {
  476. desc.find('encryption>crypto').each(function () {
  477. media += 'a=crypto:' + this.getAttribute('tag');
  478. media += ' ' + this.getAttribute('crypto-suite');
  479. media += ' ' + this.getAttribute('key-params');
  480. if (this.getAttribute('session-params')) {
  481. media += ' ' + this.getAttribute('session-params');
  482. }
  483. media += '\r\n';
  484. });
  485. }
  486. desc.find('payload-type').each(function () {
  487. media += SDPUtil.build_rtpmap(this) + '\r\n';
  488. if ($(this).find('>parameter').length) {
  489. media += 'a=fmtp:' + this.getAttribute('id') + ' ';
  490. media += $(this).find('parameter').map(function () { return (this.getAttribute('name') ? (this.getAttribute('name') + '=') : '') + this.getAttribute('value'); }).get().join(';');
  491. media += '\r\n';
  492. }
  493. // xep-0293
  494. media += self.RtcpFbFromJingle($(this), this.getAttribute('id'));
  495. });
  496. // xep-0293
  497. media += self.RtcpFbFromJingle(desc, '*');
  498. // xep-0294
  499. tmp = desc.find('>rtp-hdrext[xmlns="urn:xmpp:jingle:apps:rtp:rtp-hdrext:0"]');
  500. tmp.each(function () {
  501. media += 'a=extmap:' + this.getAttribute('id') + ' ' + this.getAttribute('uri') + '\r\n';
  502. });
  503. content.find('>transport[xmlns="urn:xmpp:jingle:transports:ice-udp:1"]>candidate').each(function () {
  504. media += SDPUtil.candidateFromJingle(this);
  505. });
  506. tmp = content.find('description>source[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]');
  507. tmp.each(function () {
  508. var ssrc = this.getAttribute('ssrc');
  509. $(this).find('>parameter').each(function () {
  510. media += 'a=ssrc:' + ssrc + ' ' + this.getAttribute('name');
  511. if (this.getAttribute('value') && this.getAttribute('value').length)
  512. media += ':' + this.getAttribute('value');
  513. media += '\r\n';
  514. });
  515. });
  516. if (tmp.length === 0) {
  517. // fallback to proprietary mapping of a=ssrc lines
  518. tmp = content.find('description>ssrc[xmlns="http://estos.de/ns/ssrc"]');
  519. if (tmp.length) {
  520. media += 'a=ssrc:' + ssrc + ' cname:' + tmp.attr('cname') + '\r\n';
  521. media += 'a=ssrc:' + ssrc + ' msid:' + tmp.attr('msid') + '\r\n';
  522. media += 'a=ssrc:' + ssrc + ' mslabel:' + tmp.attr('mslabel') + '\r\n';
  523. media += 'a=ssrc:' + ssrc + ' label:' + tmp.attr('label') + '\r\n';
  524. }
  525. }
  526. return media;
  527. };