Debian Codegraph @

test/sdp.js

raw
1 'use strict';
2
3 const SDPUtils = require('../sdp.js');
4
5 const chai = require('chai');
6 const expect = chai.expect;
7 require('sinon');
8 chai.use(require('sinon-chai'));
9
10 const videoSDP =
11 'v=0\r\no=- 1376706046264470145 3 IN IP4 127.0.0.1\r\ns=-\r\n' +
12 't=0 0\r\na=group:BUNDLE video\r\n' +
13 'a=msid-semantic: WMS EZVtYL50wdbfttMdmVFITVoKc4XgA0KBZXzd\r\n' +
14 'm=video 9 UDP/TLS/RTP/SAVPF 100 101 107 116 117 96 97 99 98\r\n' +
15 'c=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\n' +
16 'a=ice-ufrag:npaLWmWDg3Yp6vJt\r\na=ice-pwd:pdfQZAiFbcsFmUKWw55g4TD5\r\n' +
17 'a=fingerprint:sha-256 3D:05:43:01:66:AC:57:DC:17:55:08:5C:D4:25:D7:CA:FD' +
18 ':E1:0E:C1:F4:F8:43:3E:10:CE:3E:E7:6E:20:B9:90\r\n' +
19 'a=setup:actpass\r\na=mid:video\r\n' +
20 'a=extmap:2 urn:ietf:params:rtp-hdrext:toffset\r\n' +
21 'a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\n' +
22 'a=extmap:4 urn:3gpp:video-orientation\r\na=sendrecv\r\na=rtcp-mux\r\n' +
23 'a=rtcp-rsize\r\na=rtpmap:100 VP8/90000\r\n' +
24 'a=rtcp-fb:100 ccm fir\r\na=rtcp-fb:100 nack\r\na=rtcp-fb:100 nack pli\r\n' +
25 'a=rtcp-fb:100 goog-remb\r\na=rtcp-fb:100 transport-cc\r\n' +
26 'a=rtpmap:101 VP9/90000\r\na=rtcp-fb:101 ccm fir\r\na=rtcp-fb:101 nack\r\n' +
27 'a=rtcp-fb:101 nack pli\r\na=rtcp-fb:101 goog-remb\r\n' +
28 'a=rtcp-fb:101 transport-cc\r\na=rtpmap:107 H264/90000\r\n' +
29 'a=rtcp-fb:107 ccm fir\r\na=rtcp-fb:107 nack\r\na=rtcp-fb:107 nack pli\r\n' +
30 'a=rtcp-fb:107 goog-remb\r\na=rtcp-fb:107 transport-cc\r\n' +
31 'a=rtpmap:116 red/90000\r\na=rtpmap:117 ulpfec/90000\r\n' +
32 'a=rtpmap:96 rtx/90000\r\na=fmtp:96 apt=100\r\na=rtpmap:97 rtx/90000\r\n' +
33 'a=fmtp:97 apt=101\r\na=rtpmap:99 rtx/90000\r\na=fmtp:99 apt=107\r\n' +
34 'a=rtpmap:98 rtx/90000\r\na=fmtp:98 apt=116\r\n' +
35 'a=ssrc-group:FID 1734522595 2715962409\r\n' +
36 'a=ssrc:1734522595 cname:VrveQctHgkwqDKj6\r\n' +
37 'a=ssrc:1734522595 msid:EZVtYL50wdbfttMdmVFITVoKc4XgA0KBZXzd ' +
38 '63238d63-9a20-4afc-832c-48678926afce\r\na=ssrc:1734522595 ' +
39 'mslabel:EZVtYL50wdbfttMdmVFITVoKc4XgA0KBZXzd\r\n' +
40 'a=ssrc:1734522595 label:63238d63-9a20-4afc-832c-48678926afce\r\n' +
41 'a=ssrc:2715962409 cname:VrveQctHgkwqDKj6\r\n' +
42 'a=ssrc:2715962409 msid:EZVtYL50wdbfttMdmVFITVoKc4XgA0KBZXzd ' +
43 '63238d63-9a20-4afc-832c-48678926afce\r\n' +
44 'a=ssrc:2715962409 mslabel:EZVtYL50wdbfttMdmVFITVoKc4XgA0KBZXzd\r\n' +
45 'a=ssrc:2715962409 label:63238d63-9a20-4afc-832c-48678926afce\r\n';
46
47 // Firefox offer
48 const videoSDP2 =
49 'v=0\r\n' +
50 'o=mozilla...THIS_IS_SDPARTA-45.0 5508396880163053452 0 IN IP4 0.0.0.0\r\n' +
51 's=-\r\nt=0 0\r\n' +
52 'a=fingerprint:sha-256 CC:0D:FB:A8:9F:59:36:57:69:F6:2C:0E:A3:EA:19:5A:E0' +
53 ':D4:37:82:D4:7B:FB:94:3D:F6:0E:F8:29:A7:9E:9C\r\n' +
54 'a=ice-options:trickle\r\na=msid-semantic:WMS *\r\n' +
55 'm=video 9 UDP/TLS/RTP/SAVPF 120 126 97\r\n' +
56 'c=IN IP4 0.0.0.0\r\na=sendrecv\r\n' +
57 'a=fmtp:126 profile-level-id=42e01f;level-asymmetry-allowed=1;' +
58 'packetization-mode=1\r\n' +
59 'a=fmtp:97 profile-level-id=42e01f;level-asymmetry-allowed=1\r\n' +
60 'a=fmtp:120 max-fs=12288;max-fr=60\r\n' +
61 'a=ice-pwd:e81aeca45422c37aeb669274d8959200\r\n' +
62 'a=ice-ufrag:30607a5c\r\na=mid:sdparta_0\r\n' +
63 'a=msid:{782ddf65-d10e-4dad-80b9-27e9f3928d82} ' +
64 '{37802bbd-01e2-481e-a2e8-acb5423b7a55}\r\n' +
65 'a=rtcp-fb:120 nack\r\na=rtcp-fb:120 nack pli\r\na=rtcp-fb:120 ccm fir\r\n' +
66 'a=rtcp-fb:126 nack\r\na=rtcp-fb:126 nack pli\r\na=rtcp-fb:126 ccm fir\r\n' +
67 'a=rtcp-fb:97 nack\r\na=rtcp-fb:97 nack pli\r\na=rtcp-fb:97 ccm fir\r\n' +
68 'a=rtcp-mux\r\na=rtpmap:120 VP8/90000\r\na=rtpmap:126 H264/90000\r\n' +
69 'a=rtpmap:97 H264/90000\r\na=setup:actpass\r\n' +
70 'a=ssrc:98927270 cname:{0817e909-53be-4a3f-ac45-b5a0e5edc3a7}\r\n';
71
72 describe('splitSections', () => {
73 let parsed;
74 it('returns an array', () => {
75 parsed = SDPUtils.splitSections(videoSDP);
76 expect(parsed).to.be.an('Array');
77 });
78
79 it('splits video-only SDP with only LF into two sections', () => {
80 parsed = SDPUtils.splitSections(videoSDP.replace(/\r\n/g, '\n'));
81 expect(parsed.length).to.equal(2);
82 });
83
84 it('splits video-only SDP into two sections', () => {
85 parsed = SDPUtils.splitSections(videoSDP);
86 expect(parsed.length).to.equal(2);
87 });
88
89 it('every section ends with CRLF', () => {
90 expect(parsed.every(function(section) {
91 return section.substr(-2) === '\r\n';
92 })).to.equal(true);
93 });
94
95 it('joining sections without separator recreates SDP', () => {
96 expect(parsed.join('')).to.equal(videoSDP);
97 });
98 });
99
100 describe('getDescription', () => {
101 let parsed;
102 it('returns a string with the session description part', () => {
103 parsed = SDPUtils.getDescription(videoSDP);
104 expect(parsed).to.be.an('String');
105 });
106
107 it('ends with a CRLF', () => {
108 parsed = SDPUtils.getDescription(videoSDP);
109 expect(parsed.substr(-2)).to.equal('\r\n');
110 });
111 });
112
113 describe('getMediaSections', () => {
114 let parsed;
115 it('returns an array', () => {
116 parsed = SDPUtils.getMediaSections(videoSDP);
117 expect(parsed).to.be.an('Array');
118 });
119
120 it('splits video-only SDP into one section', () => {
121 parsed = SDPUtils.getMediaSections(videoSDP);
122 expect(parsed.length).to.equal(1);
123 });
124 });
125
126 describe('parseRtpParameters', () => {
127 describe('with the video sdp example', () => {
128 let parsed;
129 beforeEach(() => {
130 const sections = SDPUtils.splitSections(videoSDP);
131 parsed = SDPUtils.parseRtpParameters(sections[1]);
132 });
133
134 it('parse the profile', () => {
135 expect(parsed.profile).to.equal('UDP/TLS/RTP/SAVPF');
136 });
137
138 it('parses 9 codecs', () => {
139 expect(parsed.codecs.length).to.equal(9);
140 });
141
142 describe('fecMechanisms', () => {
143 it('parses 2 fecMechanisms', () => {
144 expect(parsed.fecMechanisms.length).to.equal(2);
145 });
146
147 it('parses RED as FEC mechanism', () => {
148 expect(parsed.fecMechanisms).to.contain('RED');
149 });
150
151 it('parses ULPFEC as FEC mechanism', () => {
152 expect(parsed.fecMechanisms).to.contain('ULPFEC');
153 });
154 });
155
156 it('parses 3 headerExtensions', () => {
157 expect(parsed.headerExtensions.length).to.equal(3);
158 });
159 });
160
161 it('applies the wildcard * rtcp-fb to all codecs', () => {
162 const sdpWithoutFeedback = SDPUtils.splitLines(videoSDP)
163 .filter(l => !l.startsWith('a=rtcp-fb:'))
164 .join('\r\n') + '\r\n';
165 const sdpWithWildcard = sdpWithoutFeedback +
166 'a=rtcp-fb:100 nack pli\r\n' +
167 'a=rtcp-fb:* nack pli\r\n';
168 const sections = SDPUtils.splitSections(sdpWithWildcard);
169 const parsed = SDPUtils.parseRtpParameters(sections[1]);
170 const withFeedback = parsed.codecs.filter(c => c.rtcpFeedback.length === 1);
171 expect(parsed.codecs).to.deep.equal(withFeedback);
172 });
173 });
174
175 describe('fmtp', () => {
176 const line = 'a=fmtp:111 minptime=10; useinbandfec=1';
177 const parsed = SDPUtils.parseFmtp(line);
178
179 describe('parsing', () => {
180 it('parses 2 parameters', () => {
181 expect(Object.keys(parsed).length).to.equal(2);
182 });
183
184 it('parses minptime', () => {
185 expect(parsed.minptime).to.equal('10');
186 });
187
188 it('parses useinbandfec', () => {
189 expect(parsed.useinbandfec).to.equal('1');
190 });
191 });
192
193 describe('serialization', () => {
194 it('uses preferredPayloadType', () => {
195 let out = SDPUtils.writeFmtp({
196 preferredPayloadType: 111,
197 parameters: {minptime: '10'}
198 }).trim();
199 expect(out).to.equal('a=fmtp:111 minptime=10');
200 });
201
202 it('returns an empty string if there are no parameters', () => {
203 let out = SDPUtils.writeFmtp({
204 preferredPayloadType: 111,
205 parameters: {}
206 }).trim();
207 expect(out).to.equal('');
208 });
209
210 // TODO: is this safe or can the order change?
211 // serialization strings the extra whitespace after ';'
212 it('does not add extra spaces between parameters', () => {
213 let out = SDPUtils.writeFmtp({
214 payloadType: 111,
215 parameters: parsed
216 }).trim();
217 expect(out).to.equal(line.replace('; ', ';'));
218 });
219
220 it('serializes non-key-value telephone-event', () => {
221 const out = SDPUtils.writeFmtp({payloadType: 100,
222 parameters: {'0-15': undefined}});
223 expect(out).to.equal('a=fmtp:100 0-15\r\n');
224 });
225
226 it('serializes number 0 correctly', () => {
227 const out = SDPUtils.writeFmtp({payloadType: 100,
228 parameters: {'profile-id': 0}});
229 expect(out).to.equal('a=fmtp:100 profile-id=0\r\n');
230 });
231 });
232 });
233
234 describe('rtpmap', () => {
235 const line = 'a=rtpmap:111 opus/48000/2';
236 const parsed = SDPUtils.parseRtpMap(line);
237 describe('parsing', () => {
238 it('parses codec name', () => {
239 expect(parsed.name).to.equal('opus');
240 });
241
242 it('parses payloadType as integer', () => {
243 expect(parsed.payloadType).to.equal(111);
244 });
245
246 it('parses clockRate as an integer', () => {
247 expect(parsed.clockRate).to.equal(48000);
248 });
249
250 it('parses channels as an integer', () => {
251 expect(parsed.channels).to.equal(2);
252 });
253
254 it('parses numChannels (legacy) as an integer', () => {
255 expect(parsed.numChannels).to.equal(2);
256 });
257
258 it('parses numChannels and defaults to 1 if not present', () => {
259 expect(SDPUtils.parseRtpMap('a=rtpmap:0 PCMU/8000').numChannels)
260 .to.equal(1);
261 });
262 });
263
264 describe('serialization', () => {
265 it('generates the expected output', () => {
266 let out = SDPUtils.writeRtpMap({
267 payloadType: 111,
268 name: 'opus',
269 clockRate: 48000,
270 numChannels: 2
271 }).trim();
272 expect(out).to.equal(line);
273 });
274
275 it('uses preferredPayloadType', () => {
276 let out = SDPUtils.writeRtpMap({
277 preferredPayloadType: 111,
278 name: 'opus',
279 clockRate: 48000,
280 numChannels: 2
281 }).trim();
282 expect(out).to.equal(line);
283 });
284
285 it('does not append channels when there is only one channel', () => {
286 let out = SDPUtils.writeRtpMap({
287 payloadType: 0,
288 name: 'pcmu',
289 clockRate: 8000,
290 channels: 1
291 }).trim();
292 expect(out).to.equal('a=rtpmap:0 pcmu/8000');
293 });
294
295 it('does not append channels when channels is undefined', () => {
296 let out = SDPUtils.writeRtpMap({
297 payloadType: 0,
298 name: 'pcmu',
299 clockRate: 8000
300 }).trim();
301 expect(out).to.equal('a=rtpmap:0 pcmu/8000');
302 });
303 });
304 });
305
306 describe('parseRtpEncodingParameters', () => {
307 let sections = SDPUtils.splitSections(videoSDP);
308 let data = SDPUtils.parseRtpEncodingParameters(sections[1]);
309 it('parses 8 encoding parameters for four codecs with fec', () => {
310 expect(data.length).to.equal(8);
311 });
312
313 it('parses primary ssrc', () => {
314 expect(data[0].ssrc).to.equal(1734522595);
315 });
316
317 it('parses RTX encoding and ssrc', () => {
318 expect(data[0].rtx);
319 expect(data[0].rtx.ssrc).to.equal(2715962409);
320 });
321
322 it('parses ssrc from cname as a fallback', () => {
323 sections = SDPUtils.splitSections(videoSDP2);
324 data = SDPUtils.parseRtpEncodingParameters(sections[1]);
325
326 expect(data.length).to.equal(1);
327 expect(data[0].ssrc).to.equal(98927270);
328 });
329
330 describe('bandwidth modifier', () => {
331 it('of type AS is parsed', () => {
332 sections = SDPUtils.splitSections(
333 videoSDP.replace('c=IN IP4 0.0.0.0\r\n',
334 'c=IN IP4 0.0.0.0\r\nb=AS:512\r\n')
335 );
336 data = SDPUtils.parseRtpEncodingParameters(sections[1]);
337
338 // conversion formula from jsep.
339 expect(data[0].maxBitrate).to.equal(512 * 1000 * 0.95 - (50 * 40 * 8));
340 });
341
342 it('of type TIAS is parsed', () => {
343 sections = SDPUtils.splitSections(
344 videoSDP.replace('c=IN IP4 0.0.0.0\r\n',
345 'c=IN IP4 0.0.0.0\r\nb=TIAS:512000\r\n')
346 );
347 data = SDPUtils.parseRtpEncodingParameters(sections[1]);
348 expect(data[0].maxBitrate).to.equal(512000);
349 });
350
351 it('of unknown type is ignored', () => {
352 sections = SDPUtils.splitSections(
353 videoSDP.replace('c=IN IP4 0.0.0.0\r\n',
354 'c=IN IP4 0.0.0.0\r\nb=something:1\r\n')
355 );
356 data = SDPUtils.parseRtpEncodingParameters(sections[1]);
357 expect(data[0].maxBitrate).to.equal(undefined);
358 });
359 });
360 });
361
362 describe('rtcp feedback', () => {
363 describe('serialization', () => {
364 it('serializes', () => {
365 const codec = {payloadType: 100,
366 rtcpFeedback: [
367 {type: 'nack', parameter: 'pli'},
368 {type: 'nack'}
369 ]
370 };
371 const expected = 'a=rtcp-fb:100 nack pli\r\n' +
372 'a=rtcp-fb:100 nack\r\n';
373 expect(SDPUtils.writeRtcpFb(codec)).to.equal(expected);
374 });
375
376 it('serialized preferredPayloadType', () => {
377 const codec = {preferredPayloadType: 100,
378 rtcpFeedback: [
379 {type: 'nack'}
380 ]
381 };
382 const expected = 'a=rtcp-fb:100 nack\r\n';
383 expect(SDPUtils.writeRtcpFb(codec)).to.equal(expected);
384 });
385
386 it('does nothing if there is no rtcp feedback', () => {
387 const codec = {payloadType: 100,
388 rtcpFeedback: []
389 };
390 expect(SDPUtils.writeRtcpFb(codec)).to.equal('');
391 });
392 });
393 });
394
395 it('getKind', () => {
396 const mediaSection = 'm=video 9 UDP/TLS/RTP/SAVPF 120 126 97\r\n' +
397 'c=IN IP4 0.0.0.0\r\na=sendrecv\r\n';
398 expect(SDPUtils.getKind(mediaSection)).to.equal('video');
399 });
400
401 describe('getDirection', () => {
402 const mediaSection = 'm=video 9 UDP/TLS/RTP/SAVPF 120 126 97\r\n' +
403 'c=IN IP4 0.0.0.0\r\na=sendonly\r\n';
404 describe('parses the direction from the mediaSection', () => {
405 ['sendrecv', 'sendonly', 'recvonly', 'inactive'].forEach((direction) => {
406 const modifiedSection = mediaSection.replace('sendonly', direction);
407 expect(SDPUtils.getDirection(modifiedSection)).to.equal(direction);
408 });
409 });
410
411 it('falls back to sendrecv', () => {
412 expect(SDPUtils.getDirection('')).to.equal('sendrecv');
413 });
414
415 it('falls back to getting the direction from the session part', () => {
416 expect(SDPUtils.getDirection('', 'a=sendonly')).to.equal('sendonly');
417 });
418 });
419
420 describe('isRejected', () => {
421 it('returns true if the m-lines port is 0', () => {
422 const rej = 'm=video 0 UDP/TLS/RTP/SAVPF 120 126 97\r\n';
423 expect(SDPUtils.isRejected(rej)).to.equal(true);
424 });
425
426 it('returns false for a non-zero port', () => {
427 const ok = 'm=video 9 UDP/TLS/RTP/SAVPF 120 126 97\r\n';
428 expect(SDPUtils.isRejected(ok)).to.equal(false);
429 });
430 });
431
432 describe('parseMsid', () => {
433 const spec = 'a=msid:stream track\r\n';
434 const planB = 'a=ssrc:1 msid:stream track\r\n';
435
436 const parsed = SDPUtils.parseMsid(spec);
437
438 it('returns undefined if no msid is found', () => {
439 expect(SDPUtils.parseMsid('')).to.equal(undefined);
440 });
441
442 it('returns an object if a msid is found', () => {
443 expect(parsed).to.be.an('Object');
444 });
445
446 it('parses the stream id', () => {
447 expect(parsed.stream).to.equal('stream');
448 });
449
450 it('parses the track id', () => {
451 expect(parsed.track).to.equal('track');
452 });
453
454 it('parses legacy plan B stuff', () => {
455 let legacy = SDPUtils.parseMsid(planB);
456 expect(legacy).to.be.an('Object');
457 expect(legacy.stream).to.equal('stream');
458 expect(legacy.track).to.equal('track');
459 });
460 });
461
462 describe('parseSsrcGroup', () => {
463 const line = 'a=ssrc-group:FID 1 2';
464 const parsed = SDPUtils.parseSsrcGroup(line);
465 it('returns an object', () => {
466 expect(parsed).to.be.an('Object');
467 });
468
469 it('parses the semantics', () => {
470 expect(parsed.semantics).to.equal('FID');
471 });
472
473 it('parses the ssrcs', () => {
474 expect(parsed.ssrcs).to.deep.equal([1, 2]);
475 });
476 });
477
478 describe('parseRtcpParameters', () => {
479 const rtcp = SDPUtils.parseRtcpParameters(videoSDP);
480
481 it('parses cname', () => {
482 expect(rtcp.cname).to.equal('VrveQctHgkwqDKj6');
483 });
484
485 it('parses ssrc', () => {
486 expect(rtcp.ssrc).to.equal(1734522595);
487 });
488
489 it('parses reduced size', () => {
490 expect(rtcp.reducedSize).to.equal(true);
491 });
492
493 it('parses compoind', () => {
494 expect(rtcp.compound).to.equal(false);
495 });
496
497 it('parses mux', () => {
498 expect(rtcp.mux).to.equal(true);
499 });
500 });
501
502 describe('writeRtcpParameters', () => {
503 it('adds a rtcp-mux line if mux is true', () => {
504 const serialized = SDPUtils.writeRtcpParameters({mux: true});
505 expect(serialized).to.contain('a=rtcp-mux');
506 });
507
508 it('adds a rtcp-rsize line if reducedSize is true', () => {
509 const serialized = SDPUtils.writeRtcpParameters({reducedSize: true});
510 expect(serialized).to.contain('a=rtcp-rsize');
511 });
512
513 it('adds a a=ssrc line with cname if cname and ssrc are set', () => {
514 const serialized = SDPUtils.writeRtcpParameters({ssrc: 1, cname: 'foo'});
515 expect(serialized).to.contain('a=ssrc:1 cname:foo');
516 });
517 });
518
519
520 describe('parseFingerprint', () => {
521 const res = SDPUtils.parseFingerprint('a=fingerprint:ALG fp');
522 it('parses and lowercaseѕ the algorithm', () => {
523 expect(res.algorithm).to.equal('alg');
524 });
525 it('parses the fingerprint value', () => {
526 expect(res.value).to.equal('FP');
527 });
528 });
529
530 describe('getDtlsParameters', () => {
531 const fp = 'a=fingerprint:sha-256 so:me:th:in:g1\r\n' +
532 'a=fingerprint:SHA-1 SOMETHINGELSE';
533 const dtlsParameters = SDPUtils.getDtlsParameters(fp, '');
534
535 it('sets the role to auto', () => {
536 expect(dtlsParameters.role).to.equal('auto');
537 });
538
539 it('parses two fingerprints', () => {
540 expect(dtlsParameters.fingerprints.length).to.equal(2);
541 });
542
543 it('extracts the algorithm', () => {
544 expect(dtlsParameters.fingerprints[0].algorithm).to.equal('sha-256');
545 expect(dtlsParameters.fingerprints[1].algorithm).to.equal('sha-1');
546 });
547
548 it('extracts the fingerprints', () => {
549 expect(dtlsParameters.fingerprints[0].value).to.equal('SO:ME:TH:IN:G1');
550 expect(dtlsParameters.fingerprints[1].value).to.equal('SOMETHINGELSE');
551 });
552 });
553
554 describe('writeDtlsParameters', () => {
555 const type = 'actpass';
556 const parameters = {fingerprints: [
557 {algorithm: 'sha-256', value: 'so:me:th:in:g1'},
558 {algorithm: 'SHA-1', value: 'somethingelse'}
559 ]};
560
561 const serialized = SDPUtils.writeDtlsParameters(parameters, type);
562 it('serializes the fingerprints', () => {
563 expect(serialized).to.contain('a=fingerprint:sha-256 so:me:th:in:g1');
564 expect(serialized).to.contain('a=fingerprint:SHA-1 somethingelse');
565 });
566 it('serializes the type', () => {
567 expect(serialized).to.contain('a=setup:' + type);
568 });
569 });
570
571 describe('getIceParameters', () => {
572 const sections = SDPUtils.splitSections(videoSDP);
573 const ice = SDPUtils.getIceParameters(sections[1], sections[0]);
574 it('returns an object', () => {
575 expect(ice).to.be.an('Object');
576 });
577
578 it('returns null when there are no ice-ufrag and ice-pwd', () => {
579 expect(SDPUtils.getIceParameters('a=ice-ufrag:123', '')).to.equal(null);
580 expect(SDPUtils.getIceParameters('a=ice-pwd:123', '')).to.equal(null);
581 expect(SDPUtils.getIceParameters('', '')).to.equal(null);
582 });
583
584 it('parses the ufrag', () => {
585 expect(ice.usernameFragment).to.equal('npaLWmWDg3Yp6vJt');
586 });
587 it('parses the password', () => {
588 expect(ice.password).to.equal('pdfQZAiFbcsFmUKWw55g4TD5');
589 });
590 });
591
592 describe('writeIceParameters', () => {
593 const parameters = {
594 usernameFragment: 'foo',
595 password: 'bar'
596 };
597 const serialized = SDPUtils.writeIceParameters(parameters);
598
599 it('serializes the usernameFragment', () => {
600 expect(serialized).to.contain('a=ice-ufrag:foo');
601 });
602
603 it('serializes the password', () => {
604 expect(serialized).to.contain('a=ice-pwd:bar');
605 });
606
607 it('includes ice-lite when Ñ–ceLite is true', () => {
608 const lite = SDPUtils.writeIceParameters(Object.assign({}, parameters,
609 {iceLite: true}));
610 expect(lite).to.contain('a=ice-lite');
611 });
612 });
613
614 describe('getMid', () => {
615 const mediaSection = 'm=video 9 UDP/TLS/RTP/SAVPF 120 126 97\r\n' +
616 'c=IN IP4 0.0.0.0\r\na=sendrecv\r\n';
617 it('returns undefined if no mid attribute is found', () => {
618 expect(SDPUtils.getMid(mediaSection)).to.equal(undefined);
619 });
620
621 it('returns the mid attribute', () => {
622 expect(SDPUtils.getMid(mediaSection + 'a=mid:foo\r\n')).to.equal('foo');
623 });
624 });
625
626 describe('parseIceOptions', () => {
627 const result = SDPUtils.parseIceOptions('a=ice-options:trickle something');
628 it('returns an array of options', () => {
629 expect(result).to.be.an('Array');
630 expect(result.length).to.equal(2);
631
632 expect(result[0]).to.equal('trickle');
633 expect(result[1]).to.equal('something');
634 });
635 });
636
637 describe('extmap', () => {
638 describe('parseExtmap', () => {
639 let res = SDPUtils.parseExtmap('a=extmap:2 uri');
640
641 it('parses the extmap id', () => {
642 expect(res.id).to.equal(2);
643 });
644
645 it('parses the extmap uri', () => {
646 expect(res.uri).to.equal('uri');
647 });
648
649 it('parses the direction defaulting to sendrecv', () => {
650 expect(res.direction).to.equal('sendrecv');
651 });
652
653 it('parses id and direction when direction is present', () => {
654 res = SDPUtils.parseExtmap('a=extmap:2/sendonly uri');
655 expect(res.id === 2, 'parses extmap id when direction is present');
656 expect(res.direction === 'sendonly', 'parses extmap direction');
657 });
658
659 it('parses extension attributes', () => {
660 res = SDPUtils.parseExtmap('a=extmap:2 uri attri butes');
661 expect(res.attributes).to.equal('attri butes');
662 });
663 });
664
665 describe('writeExtmap', () => {
666 it('writes extmap without direction', () => {
667 expect(SDPUtils.writeExtmap({id: 1, uri: 'uri'}))
668 .to.equal('a=extmap:1 uri\r\n');
669 });
670
671 it('writes extmap without direction when direction is ' +
672 'sendrecv (default)', () => {
673 const result = SDPUtils.writeExtmap({id: 1, uri: 'uri',
674 direction: 'sendrecv'});
675 expect(result).to.equal('a=extmap:1 uri\r\n');
676 });
677
678 it('writes extmap with direction when direction is not sendrecv', () => {
679 expect(SDPUtils.writeExtmap({id: 1, uri: 'uri', direction: 'sendonly'}))
680 .to.equal('a=extmap:1/sendonly uri\r\n');
681 });
682
683 it('writes extmap with preferredId when id is not present', () => {
684 expect(SDPUtils.writeExtmap({preferredId: 1, uri: 'uri'}))
685 .to.equal('a=extmap:1 uri\r\n');
686 });
687
688 it('writes extmap with attributes', () => {
689 expect(SDPUtils.writeExtmap({id: 1, uri: 'uri', attributes: 'foo'}))
690 .to.equal('a=extmap:1 uri foo\r\n');
691 });
692 });
693 });
694
695 describe('ice candidate', () => {
696 describe('parsing', () => {
697 const candidateString = 'candidate:702786350 2 udp 41819902 8.8.8.8 ' +
698 '60769 typ relay raddr 8.8.8.8 rport 1234 ' +
699 'tcptype active ' +
700 'ufrag abc ' +
701 'generation 0';
702 const candidate = SDPUtils.parseCandidate(candidateString);
703
704 it('parses foundation', () => {
705 expect(candidate.foundation).to.equal('702786350');
706 });
707
708 it('parses component', () => {
709 expect(candidate.component).to.equal('rtcp');
710 });
711
712 it('parses priority', () => {
713 expect(candidate.priority).to.equal(41819902, 'parses priority');
714 });
715
716 it('parses ip', () => {
717 expect(candidate.ip).to.equal('8.8.8.8');
718 });
719
720 it('sets address as an alias for ip', () => {
721 expect(candidate.address).to.equal('8.8.8.8');
722 });
723
724 it('parses protocol', () => {
725 expect(candidate.protocol).to.equal('udp');
726 });
727
728 it('parses port', () => {
729 expect(candidate.port).to.equal(60769);
730 });
731
732 it('parses type', () => {
733 expect(candidate.type).to.equal('relay');
734 });
735
736 it('parses tcpType', () => {
737 expect(candidate.tcpType).to.equal('active');
738 });
739
740 it('parses relatedAddress', () => {
741 expect(candidate.relatedAddress).to.equal('8.8.8.8');
742 });
743
744 it('parses relatedPort', () => {
745 expect(candidate.relatedPort).to.equal(1234);
746 });
747
748 it('parses ufrag', () => {
749 expect(candidate.ufrag).to.equal('abc');
750 });
751
752 it('parses ufrag as usernameFragment', () => {
753 expect(candidate.usernameFragment).to.equal('abc');
754 });
755
756 it('parses an unknown key-value element like generation', () => {
757 expect(candidate.generation).to.equal('0');
758 });
759
760 it('does not overwrite main attributes with extension attribues', () => {
761 expect(SDPUtils.parseCandidate(candidateString + ' type newtype').type)
762 .to.equal('relay');
763 });
764
765 it('parses the candidate with the legacy a= prefix', () => {
766 expect(SDPUtils.parseCandidate('a=' + candidateString).foundation)
767 .to.equal('702786350');
768 });
769
770 it('parses unknown components', () => {
771 expect(SDPUtils.parseCandidate(candidateString.replace(' 2 ', ' 3 '))
772 .component).to.equal('3');
773 });
774 });
775
776 describe('serialization', () => {
777 let serialized;
778 let candidate;
779 beforeEach(() => {
780 candidate = {
781 foundation: '702786350',
782 component: 2,
783 protocol: 'udp',
784 priority: 4189902,
785 ip: '8.8.8.8',
786 port: 60769,
787 type: 'host'
788 };
789 });
790
791 it('serializes a candidate with everything', () => {
792 candidate.protocol = 'tcp';
793 candidate.tcpType = 'active';
794 candidate.type = 'relay';
795 candidate.relatedAddress = '8.8.8.8';
796 candidate.relatedPort = 1234;
797
798 serialized = SDPUtils.writeCandidate(candidate).trim();
799 expect(serialized).to.equal('candidate:702786350 2 TCP 4189902 8.8.8.8 ' +
800 '60769 typ relay raddr 8.8.8.8 rport 1234 tcptype active');
801 });
802
803 it('adds ufrag if present', () => {
804 candidate.ufrag = 'abc';
805 serialized = SDPUtils.writeCandidate(candidate).trim();
806 expect(serialized).to.equal('candidate:702786350 2 UDP 4189902 8.8.8.8 ' +
807 '60769 typ host ufrag abc');
808 });
809
810 it('adds ufrag if usernameFragment is present', () => {
811 candidate.usernameFragment = 'abc';
812 serialized = SDPUtils.writeCandidate(candidate).trim();
813 expect(serialized).to.equal('candidate:702786350 2 UDP 4189902 8.8.8.8 ' +
814 '60769 typ host ufrag abc');
815 });
816
817 it('does not add relatedAddress and relatedPort for host ' +
818 'candidates', () => {
819 candidate.relatedAddress = '8.8.8.8';
820 candidate.relatedPort = 1234;
821
822 serialized = SDPUtils.writeCandidate(candidate).trim();
823 expect(serialized).to.equal('candidate:702786350 2 UDP 4189902 8.8.8.8 ' +
824 '60769 typ host');
825 });
826
827 it('ignores tcpType for udp candidates', () => {
828 candidate.tcpType = 'active';
829 serialized = SDPUtils.writeCandidate(candidate).trim();
830 expect(serialized).to.equal('candidate:702786350 2 UDP 4189902 8.8.8.8 ' +
831 '60769 typ host');
832 });
833
834 it('translates component rtp to 1', () => {
835 candidate.component = 'rtp';
836 serialized = SDPUtils.writeCandidate(candidate).trim();
837 expect(serialized).to.equal('candidate:702786350 1 UDP 4189902 8.8.8.8 ' +
838 '60769 typ host');
839 });
840 it('translates component rtcp to 2', () => {
841 candidate.component = 'rtcp';
842 serialized = SDPUtils.writeCandidate(candidate).trim();
843 expect(serialized).to.equal('candidate:702786350 2 UDP 4189902 8.8.8.8 ' +
844 '60769 typ host');
845 });
846 });
847 });
848
849 describe('writeRtpDescription', () => {
850 const kind = 'audio';
851 let parameters;
852 beforeEach(() => {
853 parameters = {
854 codecs: [{
855 payloadType: 111,
856 name: 'opus',
857 clockRate: 48000,
858 numChannels: 2,
859 parameters: {
860 minptime: '10'
861 }
862 }],
863 headerExtensions: [{
864 id: 2,
865 uri: 'some:uri'
866 }]
867 };
868 });
869
870 it('generates a rejected m-line if the codecs are empty', () => {
871 parameters.codecs = [];
872 const serialized = SDPUtils.writeRtpDescription(kind, parameters);
873 expect(serialized).to.contain('m=' + kind + ' 0 ');
874 });
875
876 it('generates rtpmap lines', () => {
877 const serialized = SDPUtils.writeRtpDescription(kind, parameters);
878 expect(serialized).to.contain('a=rtpmap:111');
879 });
880
881 it('generates rtpmap lines using preferredPayloadType', () => {
882 delete parameters.codecs[0].payloadType;
883 parameters.codecs[0].preferredPayloadType = 111;
884 const serialized = SDPUtils.writeRtpDescription(kind, parameters);
885 expect(serialized).to.contain('a=rtpmap:111');
886 });
887
888
889 it('generates fmtp lines for codecs with parameters', () => {
890 const serialized = SDPUtils.writeRtpDescription(kind, parameters);
891 expect(serialized).to.contain('a=fmtp:');
892 });
893
894 it('does not generate fmtp lines for codecs with no parameters', () => {
895 delete parameters.codecs[0].parameters;
896 const serialized = SDPUtils.writeRtpDescription(kind, parameters);
897 expect(serialized).not.to.contain('a=fmtp:');
898 });
899
900 it('generates rtcp-fb lines for codecs with rtcp-feedback', () => {
901 parameters.codecs[0].rtcpFeedback = [{type: 'nack'}];
902 const serialized = SDPUtils.writeRtpDescription(kind, parameters);
903 expect(serialized).to.contain('a=rtcp-fb:');
904 });
905
906 it('does not generate rtcp-fb lines for codecs with no feedback', () => {
907 const serialized = SDPUtils.writeRtpDescription(kind, parameters);
908 expect(serialized).not.to.contain('a=rtcp-fb:');
909 });
910
911 it('generates extmap lines for headerExtensions', () => {
912 const serialized = SDPUtils.writeRtpDescription(kind, parameters);
913 expect(serialized).to.contain('a=extmap:2 some:uri\r\n');
914 });
915
916 it('does not generate extmap lines if headerExtensions is empty', () => {
917 parameters.headerExtensions = [];
918 const serialized = SDPUtils.writeRtpDescription(kind, parameters);
919 expect(serialized).not.to.contain('a=extmap:');
920 });
921
922 it('does not generate extmap lines if there are no headerExtensions', () => {
923 delete parameters.headerExtensions;
924 const serialized = SDPUtils.writeRtpDescription(kind, parameters);
925 expect(serialized).not.to.contain('a=extmap:');
926 });
927
928 it('writes the default profile if none is given', () => {
929 delete parameters.profile;
930 const serialized = SDPUtils.writeRtpDescription(kind, parameters);
931 expect(serialized).to.contain('m=' + kind + ' 9 UDP/TLS/RTP/SAVPF ');
932 });
933
934 it('writes the given profile', () => {
935 parameters.profile = 'BO/GU/S';
936 const serialized = SDPUtils.writeRtpDescription(kind, parameters);
937 expect(serialized).to.contain('m=' + kind + ' 9 BO/GU/S ');
938 });
939 });
940
941 describe('sctp', () => {
942 const oldSDP =
943 'm=application 63743 DTLS/SCTP 5000\r\n' +
944 'a=sctpmap:5000 webrtc-datachannel 256\r\n';
945
946 const parsedOld = SDPUtils.parseSctpDescription(oldSDP);
947 describe('parsing old form', () => {
948 it('parses port', () => {
949 expect(parsedOld.port).to.equal(5000);
950 });
951
952 it('parses protocol', () => {
953 expect(parsedOld.protocol).to.equal('webrtc-datachannel');
954 });
955
956 it('default max message size', () => {
957 expect(parsedOld.maxMessageSize).to.equal(65536);
958 });
959 });
960
961 const newSDP =
962 'm=application 54111 UDP/DTLS/SCTP webrtc-datachannel\r\n' +
963 'a=sctp-port:5000\r\n' +
964 'a=max-message-size:1024\r\n';
965 const parsedNew = SDPUtils.parseSctpDescription(newSDP);
966 describe('parsing new form', () => {
967 it('parses port', () => {
968 expect(parsedNew.port).to.equal(5000);
969 });
970
971 it('parsed protocol from m-line', () => {
972 expect(parsedNew.protocol).to.equal('webrtc-datachannel');
973 });
974
975 it('parsed max message size', () => {
976 expect(parsedNew.maxMessageSize).to.equal(1024);
977 });
978 });
979 });
980
981 describe('writeSctpDescription', () => {
982 let parameters;
983 let media = {
984 kind: 'application',
985 protocol: 'UDP/DTLS/SCTP'
986 };
987 beforeEach(() => {
988 parameters = {
989 protocol: 'webrtc-datachannel',
990 port: 5000,
991 maxMessageSize: 1024
992 };
993 });
994
995 it('generates correct m line', () => {
996 const serialized = SDPUtils.writeSctpDescription(media, parameters);
997 expect(serialized).to.contain(
998 'm=application 9 UDP/DTLS/SCTP webrtc-datachannel'
999 );
1000 });
1001
1002 it('generates sctp-port lines', () => {
1003 const serialized = SDPUtils.writeSctpDescription(media, parameters);
1004 expect(serialized).to.contain('a=sctp-port:5000');
1005 });
1006
1007 it('generates max-message-size lines', () => {
1008 const serialized = SDPUtils.writeSctpDescription(media, parameters);
1009 expect(serialized).to.contain('a=max-message-size:1024');
1010 });
1011 });
1012
1013 describe('writeSctpDescription (old format answer)', () => {
1014 let parameters;
1015 let media = {
1016 kind: 'application',
1017 protocol: 'DTLS/SCTP'
1018 };
1019 beforeEach(() => {
1020 parameters = {
1021 protocol: 'webrtc-datachannel',
1022 port: 5000,
1023 maxMessageSize: 1024
1024 };
1025 });
1026
1027 it('generates correct m line', () => {
1028 const serialized = SDPUtils.writeSctpDescription(media, parameters);
1029 expect(serialized).to.contain(
1030 'm=application 9 DTLS/SCTP 5000'
1031 );
1032 });
1033
1034 it('generates sctpmap lines', () => {
1035 const serialized = SDPUtils.writeSctpDescription(media, parameters);
1036 expect(serialized).to.contain('a=sctpmap:5000 webrtc-datachannel 65535');
1037 });
1038
1039 it('generates max-message-size lines', () => {
1040 const serialized = SDPUtils.writeSctpDescription(media, parameters);
1041 expect(serialized).to.contain('a=max-message-size:1024');
1042 });
1043 });
1044
1045 describe('writeBoilerPlate', () => {
1046 let sdp;
1047 beforeEach(() => {
1048 sdp = SDPUtils.writeSessionBoilerplate();
1049 });
1050
1051 it('returns a string', () => {
1052 expect(sdp).to.be.a('String');
1053 });
1054
1055 it('generates unique id', () => {
1056 expect(sdp).to.not.equal(SDPUtils.writeSessionBoilerplate());
1057 });
1058
1059 it('uses passed in session id', () => {
1060 let sessionId = 'uniqueTestSessionId1';
1061 let sdpWithSession = SDPUtils.writeSessionBoilerplate(sessionId);
1062 expect(sdpWithSession).to.include(' ' + sessionId + ' ');
1063 });
1064
1065 it('defaults to version 2', () => {
1066 let ver = 4404;
1067 let id = 123;
1068 let sdpWithSessionVersion = SDPUtils.writeSessionBoilerplate(id, ver);
1069 expect(sdpWithSessionVersion).to.include(id + ' ' + ver + ' ');
1070 });
1071
1072 it('uses passed session version', () => {
1073 let ver = 4404;
1074 let sdpWithSessionVersion =
1075 SDPUtils.writeSessionBoilerplate(undefined, ver);
1076 expect(sdpWithSessionVersion).to.include(' ' + ver + ' ');
1077 });
1078 });
1079
1080 describe('parseMLine', () => {
1081 const mLine = 'm=video 9 UDP/TLS/RTP/SAVPF 100 101 107 116 117 96 97 99 98';
1082 const result = SDPUtils.parseMLine(mLine);
1083 it('parses the kind', () => {
1084 expect(result.kind).to.equal('video');
1085 });
1086
1087 it('parses the port as an integer', () => {
1088 expect(result.port).to.equal(9);
1089 });
1090
1091 it('parses the protocol', () => {
1092 expect(result.protocol).to.equal('UDP/TLS/RTP/SAVPF');
1093 });
1094
1095 it('parses the format list', () => {
1096 expect(result.fmt).to.equal('100 101 107 116 117 96 97 99 98');
1097 });
1098 });
1099
1100 describe('parseOLine', () => {
1101 const result = SDPUtils.parseOLine('o=username someid 15 IN IP4 0.0.0.0');
1102 it('parses the username', () =>
1103 expect(result.username).to.equal('username'));
1104 it('parse the session id', () =>
1105 expect(result.sessionId).to.equal('someid'));
1106 it('parses the session version', () =>
1107 expect(result.sessionVersion).to.equal(15));
1108 it('parses the netType', () =>
1109 expect(result.netType).to.equal('IN'));
1110 it('parses the addressType', () =>
1111 expect(result.addressType).to.equal('IP4'));
1112 it('parses the address', () =>
1113 expect(result.address).to.equal('0.0.0.0'));
1114 });
1115
1116 describe('isValidSDP', () => {
1117 it('returns false for non-string input', () =>
1118 expect(SDPUtils.isValidSDP(1)).to.equal(false));
1119 it('returns false for the empty string', () =>
1120 expect(SDPUtils.isValidSDP('')).to.equal(false));
1121 it('returns false if there are empty lines', () =>
1122 expect(SDPUtils.isValidSDP('v=0\r\n\r\nm=...\r\n')).to.equal(false));
1123 it('returns false if the syntax is not key equals value', () =>
1124 expect(SDPUtils.isValidSDP('v?0\r\n')).to.equal(false));
1125 it('returns true for valid sdp', () =>
1126 expect(SDPUtils.isValidSDP(videoSDP)).to.equal(true));
1127 });
1128
1129 describe('crypto', () => {
1130 describe('parseCryptoKeyParams', () => {
1131 const result = SDPUtils.parseCryptoKeyParams(
1132 'inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:4');
1133 it('returns null if the key method is not `inline`', () => {
1134 expect(SDPUtils.parseCryptoKeyParams('foo')).to.equal(null);
1135 });
1136 it('keyMethod', () => {
1137 expect(result.keyMethod).to.equal('inline');
1138 });
1139 it('keySalt', () => {
1140 expect(result.keySalt).to.equal(
1141 'd0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj');
1142 });
1143 it('lifeTime', () => {
1144 expect(result.lifeTime).to.equal('2^20');
1145 });
1146 it('mkiValue', () => {
1147 expect(result.mkiValue).to.equal('1');
1148 });
1149 it('mkiLength', () => {
1150 expect(result.mkiLength).to.equal('4');
1151 });
1152 });
1153
1154 describe('writeCryptoKeyParams', () => {
1155 it('serializes keyMethod and keySalt', () => {
1156 expect(SDPUtils.writeCryptoKeyParams({
1157 keyMethod: 'inline',
1158 keySalt: 'ks',
1159 })).to.equal('inline:ks');
1160 });
1161 it('serializes lifeTime if present', () => {
1162 expect(SDPUtils.writeCryptoKeyParams({
1163 keyMethod: 'inline',
1164 keySalt: 'ks',
1165 lifeTime: '2^24',
1166 })).to.equal('inline:ks|2^24');
1167 });
1168 it('serializes mkiValue and mkiLength if present', () => {
1169 expect(SDPUtils.writeCryptoKeyParams({
1170 keyMethod: 'inline',
1171 keySalt: 'ks',
1172 lifeTime: '2^24',
1173 mkiValue: '1',
1174 mkiLength: '4',
1175 })).to.equal('inline:ks|2^24|1:4');
1176 });
1177 it('serializes mkiValue and mkiLength if lifeTime is not present', () => {
1178 expect(SDPUtils.writeCryptoKeyParams({
1179 keyMethod: 'inline',
1180 keySalt: 'ks',
1181 mkiValue: '1',
1182 mkiLength: '4',
1183 })).to.equal('inline:ks|1:4');
1184 });
1185 });
1186
1187 describe('parseCryptoLine', () => {
1188 const result = SDPUtils.parseCryptoLine('a=crypto:0 ' +
1189 'AES_CM_128_HMAC_SHA1_80 ' +
1190 'inline:gd0dcDM6tVrk2sqLuNYp9EFX0WYMNu7kQw/V0s23');
1191 it('parses the tag', () => {
1192 expect(result.tag).to.equal(0);
1193 });
1194 it('parses the cryptoSuite', () => {
1195 expect(result.cryptoSuite).to.equal('AES_CM_128_HMAC_SHA1_80');
1196 });
1197 it('parses the keyParams as string', () => {
1198 expect(result.keyParams).to.equal(
1199 'inline:gd0dcDM6tVrk2sqLuNYp9EFX0WYMNu7kQw/V0s23');
1200 });
1201 describe('parses sessionParams', () => {
1202 it('as empty array when there are no sessionParams', () => {
1203 expect(result.sessionParams).to.be.an('array');
1204 expect(result.sessionParams).to.have.length(0);
1205 });
1206 it('as array', () => {
1207 expect(SDPUtils.parseCryptoLine('a=crypto:0 ' +
1208 'cryptoSuite keyParams foo bar').sessionParams)
1209 .to.deep.equal(['foo', 'bar']);
1210 });
1211 });
1212 });
1213
1214 describe('writeCryptoLine', () => {
1215 it('generates the expected output', () => {
1216 const out = SDPUtils.writeCryptoLine({
1217 tag: 1,
1218 cryptoSuite: 'something',
1219 keyParams: 'params',
1220 sessionParams: undefined,
1221 });
1222 expect(out).to.equal('a=crypto:1 something params\r\n');
1223 });
1224
1225 it('serializes keyParams', () => {
1226 const out = SDPUtils.writeCryptoLine({
1227 tag: 1,
1228 cryptoSuite: 'something',
1229 keyParams: {
1230 keyMethod: 'inline',
1231 keySalt: 'ks',
1232 },
1233 });
1234 expect(out).to.equal('a=crypto:1 something inline:ks\r\n');
1235 });
1236
1237 it('serializes sessionParams', () => {
1238 const out = SDPUtils.writeCryptoLine({
1239 tag: 1,
1240 cryptoSuite: 'something',
1241 keyParams: 'params',
1242 sessionParams: ['foo', 'bar'],
1243 });
1244 expect(out).to.equal('a=crypto:1 something params foo bar\r\n');
1245 });
1246 });
1247
1248 describe('getCryptoParameters', () => {
1249 const result = SDPUtils.getCryptoParameters(
1250 'a=crypto:0 suite1 params1\r\n' +
1251 'a=crypto:1 suite2 params2\r\n'
1252 );
1253 it('returns an array', () => {
1254 expect(result).to.be.an('Array');
1255 });
1256 it('matches the number of input lines', () => {
1257 expect(result).to.have.length(2);
1258 });
1259 it('returns two SDESParameters entries with numeric tags', () => {
1260 expect(result.map(r => r.tag)).to.deep.equal([0, 1]);
1261 });
1262 });
1263 });