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.

SDP.js 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. /* global $ */
  2. import browser from '../browser';
  3. import SDPUtil from './SDPUtil';
  4. /**
  5. *
  6. * @param sdp
  7. */
  8. export default function SDP(sdp) {
  9. const media = sdp.split('\r\nm=');
  10. for (let i = 1, length = media.length; i < length; i++) {
  11. let mediaI = `m=${media[i]}`;
  12. if (i !== length - 1) {
  13. mediaI += '\r\n';
  14. }
  15. media[i] = mediaI;
  16. }
  17. const session = `${media.shift()}\r\n`;
  18. this.media = media;
  19. this.raw = session + media.join('');
  20. this.session = session;
  21. }
  22. /**
  23. * A flag will make {@link transportToJingle} and {@link jingle2media} replace
  24. * ICE candidates IPs with invalid value of '1.1.1.1' which will cause ICE
  25. * failure. The flag is used in the automated testing.
  26. * @type {boolean}
  27. */
  28. SDP.prototype.failICE = false;
  29. /**
  30. * Whether or not to remove TCP ice candidates when translating from/to jingle.
  31. * @type {boolean}
  32. */
  33. SDP.prototype.removeTcpCandidates = false;
  34. /**
  35. * Whether or not to remove UDP ice candidates when translating from/to jingle.
  36. * @type {boolean}
  37. */
  38. SDP.prototype.removeUdpCandidates = false;
  39. /**
  40. * Returns map of MediaChannel mapped per channel idx.
  41. */
  42. SDP.prototype.getMediaSsrcMap = function() {
  43. const mediaSSRCs = {};
  44. let tmp;
  45. for (let mediaindex = 0; mediaindex < this.media.length; mediaindex++) {
  46. tmp = SDPUtil.findLines(this.media[mediaindex], 'a=ssrc:');
  47. const mid
  48. = SDPUtil.parseMID(
  49. SDPUtil.findLine(this.media[mediaindex], 'a=mid:'));
  50. const media = {
  51. mediaindex,
  52. mid,
  53. ssrcs: {},
  54. ssrcGroups: []
  55. };
  56. mediaSSRCs[mediaindex] = media;
  57. tmp.forEach(line => {
  58. const linessrc = line.substring(7).split(' ')[0];
  59. // allocate new ChannelSsrc
  60. if (!media.ssrcs[linessrc]) {
  61. media.ssrcs[linessrc] = {
  62. ssrc: linessrc,
  63. lines: []
  64. };
  65. }
  66. media.ssrcs[linessrc].lines.push(line);
  67. });
  68. tmp = SDPUtil.findLines(this.media[mediaindex], 'a=ssrc-group:');
  69. tmp.forEach(line => {
  70. const idx = line.indexOf(' ');
  71. const semantics = line.substr(0, idx).substr(13);
  72. const ssrcs = line.substr(14 + semantics.length).split(' ');
  73. if (ssrcs.length) {
  74. media.ssrcGroups.push({
  75. semantics,
  76. ssrcs
  77. });
  78. }
  79. });
  80. }
  81. return mediaSSRCs;
  82. };
  83. /**
  84. * Returns <tt>true</tt> if this SDP contains given SSRC.
  85. * @param ssrc the ssrc to check.
  86. * @returns {boolean} <tt>true</tt> if this SDP contains given SSRC.
  87. */
  88. SDP.prototype.containsSSRC = function(ssrc) {
  89. // FIXME this code is really strange - improve it if you can
  90. const medias = this.getMediaSsrcMap();
  91. let result = false;
  92. Object.keys(medias).forEach(mediaindex => {
  93. if (result) {
  94. return;
  95. }
  96. if (medias[mediaindex].ssrcs[ssrc]) {
  97. result = true;
  98. }
  99. });
  100. return result;
  101. };
  102. // add content's to a jingle element
  103. SDP.prototype.toJingle = function(elem, thecreator) {
  104. let i, j, k, lines, mline, rtpmap, ssrc, tmp;
  105. // new bundle plan
  106. lines = SDPUtil.findLines(this.session, 'a=group:');
  107. if (lines.length) {
  108. for (i = 0; i < lines.length; i++) {
  109. tmp = lines[i].split(' ');
  110. const semantics = tmp.shift().substr(8);
  111. elem.c('group', { xmlns: 'urn:xmpp:jingle:apps:grouping:0',
  112. semantics });
  113. for (j = 0; j < tmp.length; j++) {
  114. elem.c('content', { name: tmp[j] }).up();
  115. }
  116. elem.up();
  117. }
  118. }
  119. for (i = 0; i < this.media.length; i++) {
  120. mline = SDPUtil.parseMLine(this.media[i].split('\r\n')[0]);
  121. if (!(mline.media === 'audio'
  122. || mline.media === 'video'
  123. || mline.media === 'application')) {
  124. continue; // eslint-disable-line no-continue
  125. }
  126. const assrcline = SDPUtil.findLine(this.media[i], 'a=ssrc:');
  127. if (assrcline) {
  128. ssrc = assrcline.substring(7).split(' ')[0]; // take the first
  129. } else {
  130. ssrc = false;
  131. }
  132. elem.c('content', { creator: thecreator,
  133. name: mline.media });
  134. const amidline = SDPUtil.findLine(this.media[i], 'a=mid:');
  135. if (amidline) {
  136. // prefer identifier from a=mid if present
  137. const mid = SDPUtil.parseMID(amidline);
  138. elem.attrs({ name: mid });
  139. }
  140. if (SDPUtil.findLine(this.media[i], 'a=rtpmap:').length) {
  141. elem.c('description',
  142. { xmlns: 'urn:xmpp:jingle:apps:rtp:1',
  143. media: mline.media });
  144. if (ssrc) {
  145. elem.attrs({ ssrc });
  146. }
  147. for (j = 0; j < mline.fmt.length; j++) {
  148. rtpmap
  149. = SDPUtil.findLine(
  150. this.media[i],
  151. `a=rtpmap:${mline.fmt[j]}`);
  152. elem.c('payload-type', SDPUtil.parseRTPMap(rtpmap));
  153. // put any 'a=fmtp:' + mline.fmt[j] lines into <param name=foo
  154. // value=bar/>
  155. const afmtpline
  156. = SDPUtil.findLine(
  157. this.media[i],
  158. `a=fmtp:${mline.fmt[j]}`);
  159. if (afmtpline) {
  160. tmp = SDPUtil.parseFmtp(afmtpline);
  161. // eslint-disable-next-line max-depth
  162. for (k = 0; k < tmp.length; k++) {
  163. elem.c('parameter', tmp[k]).up();
  164. }
  165. }
  166. // XEP-0293 -- map a=rtcp-fb
  167. this.rtcpFbToJingle(i, elem, mline.fmt[j]);
  168. elem.up();
  169. }
  170. if (ssrc) {
  171. const ssrcMap = SDPUtil.parseSSRC(this.media[i]);
  172. for (const [ availableSsrc, ssrcParameters ] of ssrcMap) {
  173. elem.c('source', {
  174. ssrc: availableSsrc,
  175. xmlns: 'urn:xmpp:jingle:apps:rtp:ssma:0'
  176. });
  177. ssrcParameters.forEach(ssrcSdpLine => {
  178. // get everything after first space
  179. const idx = ssrcSdpLine.indexOf(' ');
  180. const kv = ssrcSdpLine.substr(idx + 1);
  181. elem.c('parameter');
  182. if (kv.indexOf(':') === -1) {
  183. elem.attrs({ name: kv });
  184. } else {
  185. const name = kv.split(':', 2)[0];
  186. elem.attrs({ name });
  187. let v = kv.split(':', 2)[1];
  188. v = SDPUtil.filterSpecialChars(v);
  189. elem.attrs({ value: v });
  190. }
  191. elem.up();
  192. });
  193. elem.up();
  194. }
  195. // XEP-0339 handle ssrc-group attributes
  196. const ssrcGroupLines
  197. = SDPUtil.findLines(this.media[i], 'a=ssrc-group:');
  198. ssrcGroupLines.forEach(line => {
  199. const idx = line.indexOf(' ');
  200. const semantics = line.substr(0, idx).substr(13);
  201. const ssrcs = line.substr(14 + semantics.length).split(' ');
  202. if (ssrcs.length) {
  203. elem.c('ssrc-group', { semantics,
  204. xmlns: 'urn:xmpp:jingle:apps:rtp:ssma:0' });
  205. ssrcs.forEach(s => elem.c('source', { ssrc: s }).up());
  206. elem.up();
  207. }
  208. });
  209. }
  210. const ridLines = SDPUtil.findLines(this.media[i], 'a=rid');
  211. if (ridLines.length && browser.usesRidsForSimulcast()) {
  212. // Map a line which looks like "a=rid:2 send" to just
  213. // the rid ("2")
  214. const rids = ridLines
  215. .map(ridLine => ridLine.split(':')[1])
  216. .map(ridInfo => ridInfo.split(' ')[0]);
  217. rids.forEach(rid => {
  218. elem.c('source', {
  219. rid,
  220. xmlns: 'urn:xmpp:jingle:apps:rtp:ssma:0'
  221. });
  222. elem.up();
  223. });
  224. const unifiedSimulcast
  225. = SDPUtil.findLine(this.media[i], 'a=simulcast');
  226. if (unifiedSimulcast) {
  227. elem.c('rid-group', {
  228. semantics: 'SIM',
  229. xmlns: 'urn:xmpp:jingle:apps:rtp:ssma:0'
  230. });
  231. rids.forEach(rid => {
  232. elem.c('source', { rid }).up();
  233. });
  234. elem.up();
  235. }
  236. }
  237. if (SDPUtil.findLine(this.media[i], 'a=rtcp-mux')) {
  238. elem.c('rtcp-mux').up();
  239. }
  240. // XEP-0293 -- map a=rtcp-fb:*
  241. this.rtcpFbToJingle(i, elem, '*');
  242. // XEP-0294
  243. lines = SDPUtil.findLines(this.media[i], 'a=extmap:');
  244. if (lines.length) {
  245. for (j = 0; j < lines.length; j++) {
  246. tmp = SDPUtil.parseExtmap(lines[j]);
  247. elem.c('rtp-hdrext', {
  248. xmlns: 'urn:xmpp:jingle:apps:rtp:rtp-hdrext:0',
  249. uri: tmp.uri,
  250. id: tmp.value
  251. });
  252. // eslint-disable-next-line max-depth
  253. if (tmp.hasOwnProperty('direction')) {
  254. // eslint-disable-next-line max-depth
  255. switch (tmp.direction) {
  256. case 'sendonly':
  257. elem.attrs({ senders: 'responder' });
  258. break;
  259. case 'recvonly':
  260. elem.attrs({ senders: 'initiator' });
  261. break;
  262. case 'sendrecv':
  263. elem.attrs({ senders: 'both' });
  264. break;
  265. case 'inactive':
  266. elem.attrs({ senders: 'none' });
  267. break;
  268. }
  269. }
  270. // TODO: handle params
  271. elem.up();
  272. }
  273. }
  274. elem.up(); // end of description
  275. }
  276. // map ice-ufrag/pwd, dtls fingerprint, candidates
  277. this.transportToJingle(i, elem);
  278. const m = this.media[i];
  279. if (SDPUtil.findLine(m, 'a=sendrecv', this.session)) {
  280. elem.attrs({ senders: 'both' });
  281. } else if (SDPUtil.findLine(m, 'a=sendonly', this.session)) {
  282. elem.attrs({ senders: 'initiator' });
  283. } else if (SDPUtil.findLine(m, 'a=recvonly', this.session)) {
  284. elem.attrs({ senders: 'responder' });
  285. } else if (SDPUtil.findLine(m, 'a=inactive', this.session)) {
  286. elem.attrs({ senders: 'none' });
  287. }
  288. // Reject an m-line only when port is 0 and a=bundle-only is not present in the section.
  289. // The port is automatically set to 0 when bundle-only is used.
  290. if (mline.port === '0' && !SDPUtil.findLine(m, 'a=bundle-only', this.session)) {
  291. // estos hack to reject an m-line
  292. elem.attrs({ senders: 'rejected' });
  293. }
  294. elem.up(); // end of content
  295. }
  296. elem.up();
  297. return elem;
  298. };
  299. SDP.prototype.transportToJingle = function(mediaindex, elem) {
  300. let tmp;
  301. elem.c('transport');
  302. // XEP-0343 DTLS/SCTP
  303. const sctpmap
  304. = SDPUtil.findLine(this.media[mediaindex], 'a=sctpmap:', this.session);
  305. if (sctpmap) {
  306. const sctpAttrs = SDPUtil.parseSCTPMap(sctpmap);
  307. elem.c('sctpmap', {
  308. xmlns: 'urn:xmpp:jingle:transports:dtls-sctp:1',
  309. number: sctpAttrs[0], /* SCTP port */
  310. protocol: sctpAttrs[1] /* protocol */
  311. });
  312. // Optional stream count attribute
  313. if (sctpAttrs.length > 2) {
  314. elem.attrs({ streams: sctpAttrs[2] });
  315. }
  316. elem.up();
  317. }
  318. // XEP-0320
  319. const fingerprints
  320. = SDPUtil.findLines(
  321. this.media[mediaindex],
  322. 'a=fingerprint:',
  323. this.session);
  324. fingerprints.forEach(line => {
  325. tmp = SDPUtil.parseFingerprint(line);
  326. tmp.xmlns = 'urn:xmpp:jingle:apps:dtls:0';
  327. elem.c('fingerprint').t(tmp.fingerprint);
  328. delete tmp.fingerprint;
  329. // eslint-disable-next-line no-param-reassign
  330. line
  331. = SDPUtil.findLine(
  332. this.media[mediaindex],
  333. 'a=setup:',
  334. this.session);
  335. if (line) {
  336. tmp.setup = line.substr(8);
  337. }
  338. elem.attrs(tmp);
  339. elem.up(); // end of fingerprint
  340. });
  341. tmp = SDPUtil.iceparams(this.media[mediaindex], this.session);
  342. if (tmp) {
  343. tmp.xmlns = 'urn:xmpp:jingle:transports:ice-udp:1';
  344. elem.attrs(tmp);
  345. // XEP-0176
  346. const lines
  347. = SDPUtil.findLines(
  348. this.media[mediaindex],
  349. 'a=candidate:',
  350. this.session);
  351. if (lines.length) { // add any a=candidate lines
  352. lines.forEach(line => {
  353. const candidate = SDPUtil.candidateToJingle(line);
  354. if (this.failICE) {
  355. candidate.ip = '1.1.1.1';
  356. }
  357. const protocol
  358. = candidate && typeof candidate.protocol === 'string'
  359. ? candidate.protocol.toLowerCase()
  360. : '';
  361. if ((this.removeTcpCandidates
  362. && (protocol === 'tcp' || protocol === 'ssltcp'))
  363. || (this.removeUdpCandidates && protocol === 'udp')) {
  364. return;
  365. }
  366. elem.c('candidate', candidate).up();
  367. });
  368. }
  369. }
  370. elem.up(); // end of transport
  371. };
  372. // XEP-0293
  373. SDP.prototype.rtcpFbToJingle = function(mediaindex, elem, payloadtype) {
  374. const lines
  375. = SDPUtil.findLines(
  376. this.media[mediaindex],
  377. `a=rtcp-fb:${payloadtype}`);
  378. lines.forEach(line => {
  379. const tmp = SDPUtil.parseRTCPFB(line);
  380. if (tmp.type === 'trr-int') {
  381. elem.c('rtcp-fb-trr-int', {
  382. xmlns: 'urn:xmpp:jingle:apps:rtp:rtcp-fb:0',
  383. value: tmp.params[0]
  384. });
  385. elem.up();
  386. } else {
  387. elem.c('rtcp-fb', {
  388. xmlns: 'urn:xmpp:jingle:apps:rtp:rtcp-fb:0',
  389. type: tmp.type
  390. });
  391. if (tmp.params.length > 0) {
  392. elem.attrs({ 'subtype': tmp.params[0] });
  393. }
  394. elem.up();
  395. }
  396. });
  397. };
  398. SDP.prototype.rtcpFbFromJingle = function(elem, payloadtype) { // XEP-0293
  399. let media = '';
  400. let tmp
  401. = elem.find(
  402. '>rtcp-fb-trr-int[xmlns="urn:xmpp:jingle:apps:rtp:rtcp-fb:0"]');
  403. if (tmp.length) {
  404. media += 'a=rtcp-fb:* trr-int ';
  405. if (tmp.attr('value')) {
  406. media += tmp.attr('value');
  407. } else {
  408. media += '0';
  409. }
  410. media += '\r\n';
  411. }
  412. tmp = elem.find('>rtcp-fb[xmlns="urn:xmpp:jingle:apps:rtp:rtcp-fb:0"]');
  413. tmp.each((_, fb) => {
  414. media += `a=rtcp-fb:${payloadtype} ${fb.getAttribute('type')}`;
  415. if (fb.hasAttribute('subtype')) {
  416. media += ` ${fb.getAttribute('subtype')}`;
  417. }
  418. media += '\r\n';
  419. });
  420. return media;
  421. };
  422. // construct an SDP from a jingle stanza
  423. SDP.prototype.fromJingle = function(jingle) {
  424. const sessionId = Date.now();
  425. // Use a unique session id for every TPC.
  426. this.raw = 'v=0\r\n'
  427. + `o=- ${sessionId} 2 IN IP4 0.0.0.0\r\n`
  428. + 's=-\r\n'
  429. + 't=0 0\r\n';
  430. // http://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-04
  431. // #section-8
  432. const groups
  433. = $(jingle).find('>group[xmlns="urn:xmpp:jingle:apps:grouping:0"]');
  434. if (groups.length) {
  435. groups.each((idx, group) => {
  436. const contents
  437. = $(group)
  438. .find('>content')
  439. .map((_, content) => content.getAttribute('name'))
  440. .get();
  441. if (contents.length > 0) {
  442. this.raw
  443. += `a=group:${
  444. group.getAttribute('semantics')
  445. || group.getAttribute('type')} ${
  446. contents.join(' ')}\r\n`;
  447. }
  448. });
  449. }
  450. this.session = this.raw;
  451. jingle.find('>content').each((_, content) => {
  452. const m = this.jingle2media($(content));
  453. this.media.push(m);
  454. });
  455. // reconstruct msid-semantic -- apparently not necessary
  456. /*
  457. var msid = SDPUtil.parseSSRC(this.raw);
  458. if (msid.hasOwnProperty('mslabel')) {
  459. this.session += "a=msid-semantic: WMS " + msid.mslabel + "\r\n";
  460. }
  461. */
  462. this.raw = this.session + this.media.join('');
  463. };
  464. // translate a jingle content element into an an SDP media part
  465. SDP.prototype.jingle2media = function(content) {
  466. const desc = content.find('>description');
  467. const transport = content.find('>transport[xmlns="urn:xmpp:jingle:transports:ice-udp:1"]');
  468. let media = '';
  469. const sctp = transport.find(
  470. '>sctpmap[xmlns="urn:xmpp:jingle:transports:dtls-sctp:1"]');
  471. let tmp = { media: desc.attr('media') };
  472. tmp.port = '1';
  473. if (content.attr('senders') === 'rejected') {
  474. // estos hack to reject an m-line.
  475. tmp.port = '0';
  476. }
  477. if (transport.find('>fingerprint[xmlns="urn:xmpp:jingle:apps:dtls:0"]').length) {
  478. tmp.proto = sctp.length ? 'DTLS/SCTP' : 'RTP/SAVPF';
  479. } else {
  480. tmp.proto = 'RTP/AVPF';
  481. }
  482. if (sctp.length) {
  483. media += `m=application ${tmp.port} DTLS/SCTP ${
  484. sctp.attr('number')}\r\n`;
  485. media += `a=sctpmap:${sctp.attr('number')} ${sctp.attr('protocol')}`;
  486. const streamCount = sctp.attr('streams');
  487. if (streamCount) {
  488. media += ` ${streamCount}\r\n`;
  489. } else {
  490. media += '\r\n';
  491. }
  492. } else {
  493. tmp.fmt
  494. = desc
  495. .find('>payload-type')
  496. .map((_, payloadType) => payloadType.getAttribute('id'))
  497. .get();
  498. media += `${SDPUtil.buildMLine(tmp)}\r\n`;
  499. }
  500. media += 'c=IN IP4 0.0.0.0\r\n';
  501. if (!sctp.length) {
  502. media += 'a=rtcp:1 IN IP4 0.0.0.0\r\n';
  503. }
  504. // XEP-0176 ICE parameters
  505. if (transport.length) {
  506. if (transport.attr('ufrag')) {
  507. media += `${SDPUtil.buildICEUfrag(transport.attr('ufrag'))}\r\n`;
  508. }
  509. if (transport.attr('pwd')) {
  510. media += `${SDPUtil.buildICEPwd(transport.attr('pwd'))}\r\n`;
  511. }
  512. transport.find('>fingerprint[xmlns="urn:xmpp:jingle:apps:dtls:0"]').each((_, fingerprint) => {
  513. media += `a=fingerprint:${fingerprint.getAttribute('hash')}`;
  514. media += ` ${$(fingerprint).text()}`;
  515. media += '\r\n';
  516. if (fingerprint.hasAttribute('setup')) {
  517. media += `a=setup:${fingerprint.getAttribute('setup')}\r\n`;
  518. }
  519. });
  520. }
  521. // XEP-0176 ICE candidates
  522. transport.find('>candidate')
  523. .each((_, candidate) => {
  524. let protocol = candidate.getAttribute('protocol');
  525. protocol
  526. = typeof protocol === 'string' ? protocol.toLowerCase() : '';
  527. if ((this.removeTcpCandidates
  528. && (protocol === 'tcp' || protocol === 'ssltcp'))
  529. || (this.removeUdpCandidates && protocol === 'udp')) {
  530. return;
  531. } else if (this.failICE) {
  532. candidate.setAttribute('ip', '1.1.1.1');
  533. }
  534. media += SDPUtil.candidateFromJingle(candidate);
  535. });
  536. switch (content.attr('senders')) {
  537. case 'initiator':
  538. media += 'a=sendonly\r\n';
  539. break;
  540. case 'responder':
  541. media += 'a=recvonly\r\n';
  542. break;
  543. case 'none':
  544. media += 'a=inactive\r\n';
  545. break;
  546. case 'both':
  547. media += 'a=sendrecv\r\n';
  548. break;
  549. }
  550. media += `a=mid:${content.attr('name')}\r\n`;
  551. // <description><rtcp-mux/></description>
  552. // see http://code.google.com/p/libjingle/issues/detail?id=309 -- no spec
  553. // though
  554. // and http://mail.jabber.org/pipermail/jingle/2011-December/001761.html
  555. if (desc.find('>rtcp-mux').length) {
  556. media += 'a=rtcp-mux\r\n';
  557. }
  558. desc.find('>payload-type').each((_, payloadType) => {
  559. media += `${SDPUtil.buildRTPMap(payloadType)}\r\n`;
  560. if ($(payloadType).find('>parameter').length) {
  561. media += `a=fmtp:${payloadType.getAttribute('id')} `;
  562. media
  563. += $(payloadType)
  564. .find('>parameter')
  565. .map((__, parameter) => {
  566. const name = parameter.getAttribute('name');
  567. return (
  568. (name ? `${name}=` : '')
  569. + parameter.getAttribute('value'));
  570. })
  571. .get()
  572. .join('; ');
  573. media += '\r\n';
  574. }
  575. // xep-0293
  576. media += this.rtcpFbFromJingle($(payloadType), payloadType.getAttribute('id'));
  577. });
  578. // xep-0293
  579. media += this.rtcpFbFromJingle(desc, '*');
  580. // xep-0294
  581. tmp
  582. = desc.find(
  583. '>rtp-hdrext[xmlns="urn:xmpp:jingle:apps:rtp:rtp-hdrext:0"]');
  584. tmp.each((_, hdrExt) => {
  585. media
  586. += `a=extmap:${hdrExt.getAttribute('id')} ${
  587. hdrExt.getAttribute('uri')}\r\n`;
  588. });
  589. // XEP-0339 handle ssrc-group attributes
  590. desc
  591. .find('>ssrc-group[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]')
  592. .each((_, ssrcGroup) => {
  593. const semantics = ssrcGroup.getAttribute('semantics');
  594. const ssrcs
  595. = $(ssrcGroup)
  596. .find('>source')
  597. .map((__, source) => source.getAttribute('ssrc'))
  598. .get();
  599. if (ssrcs.length) {
  600. media += `a=ssrc-group:${semantics} ${ssrcs.join(' ')}\r\n`;
  601. }
  602. });
  603. tmp
  604. = desc.find(
  605. '>source[xmlns="urn:xmpp:jingle:apps:rtp:ssma:0"]');
  606. tmp.each((_, source) => {
  607. const ssrc = source.getAttribute('ssrc');
  608. $(source)
  609. .find('>parameter')
  610. .each((__, parameter) => {
  611. const name = parameter.getAttribute('name');
  612. let value = parameter.getAttribute('value');
  613. value = SDPUtil.filterSpecialChars(value);
  614. media += `a=ssrc:${ssrc} ${name}`;
  615. if (value && value.length) {
  616. media += `:${value}`;
  617. }
  618. media += '\r\n';
  619. });
  620. });
  621. return media;
  622. };