modified lib-jitsi-meet dev repo
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.

LocalSdpMunger.spec.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import * as transform from 'sdp-transform';
  2. import LocalSdpMunger from './LocalSdpMunger';
  3. import { default as SampleSdpStrings } from './SampleSdpStrings.js';
  4. /**
  5. * Returns the associated ssrc lines for a given media type.
  6. *
  7. * @param {RTCSessionDescription} desc
  8. * @param {string} mediaType
  9. * @returns
  10. */
  11. function getSsrcLines(desc, mediaType) {
  12. const mline = desc.media.find(m => m.type === mediaType);
  13. return mline.ssrcs ?? [];
  14. }
  15. describe('TransformRecvOnly', () => {
  16. let localSdpMunger;
  17. const tpc = { id: '1' };
  18. const localEndpointId = 'sRdpsdg';
  19. beforeEach(() => {
  20. localSdpMunger = new LocalSdpMunger(tpc, localEndpointId);
  21. });
  22. describe('stripSsrcs', () => {
  23. beforeEach(() => { }); // eslint-disable-line no-empty-function
  24. it('should strip ssrcs from an sdp with no msid', () => {
  25. localSdpMunger.tpc.isP2P = false;
  26. const sdpStr = transform.write(SampleSdpStrings.recvOnlySdp);
  27. const desc = new RTCSessionDescription({
  28. type: 'offer',
  29. sdp: sdpStr
  30. });
  31. const transformedDesc = localSdpMunger.transformStreamIdentifiers(desc);
  32. const newSdp = transform.parse(transformedDesc.sdp);
  33. const audioSsrcs = getSsrcLines(newSdp, 'audio');
  34. const videoSsrcs = getSsrcLines(newSdp, 'video');
  35. expect(audioSsrcs.length).toEqual(0);
  36. expect(videoSsrcs.length).toEqual(0);
  37. });
  38. it('should do nothing to an sdp with msid', () => {
  39. const sdpStr = transform.write(SampleSdpStrings.simulcastSdp);
  40. const desc = new RTCSessionDescription({
  41. type: 'offer',
  42. sdp: sdpStr
  43. });
  44. const transformedDesc = localSdpMunger.transformStreamIdentifiers(desc);
  45. const newSdp = transform.parse(transformedDesc.sdp);
  46. const audioSsrcs = getSsrcLines(newSdp, 'audio');
  47. const videoSsrcs = getSsrcLines(newSdp, 'video');
  48. expect(audioSsrcs.length).toEqual(4);
  49. expect(videoSsrcs.length).toEqual(6);
  50. });
  51. it('should add endpointId to msid', () => {
  52. const sdpStr = transform.write(SampleSdpStrings.firefoxSdp);
  53. const desc = new RTCSessionDescription({
  54. type: 'offer',
  55. sdp: sdpStr
  56. });
  57. const transformedDesc = localSdpMunger.transformStreamIdentifiers(desc);
  58. const newSdp = transform.parse(transformedDesc.sdp);
  59. const videoSsrcs = getSsrcLines(newSdp, 'video');
  60. for (const ssrcLine of videoSsrcs) {
  61. if (ssrcLine.attribute === 'msid') {
  62. const msid = ssrcLine.value.split(' ')[0];
  63. expect(msid).toBe(`${localEndpointId}-video-${tpc.id}`);
  64. }
  65. }
  66. });
  67. it('should add msid', () => {
  68. // P2P case only.
  69. localSdpMunger.tpc.isP2P = true;
  70. const sdpStr = transform.write(SampleSdpStrings.firefoxP2pSdp);
  71. const desc = new RTCSessionDescription({
  72. type: 'offer',
  73. sdp: sdpStr
  74. });
  75. const transformedDesc = localSdpMunger.transformStreamIdentifiers(desc);
  76. const newSdp = transform.parse(transformedDesc.sdp);
  77. const videoSsrcs = getSsrcLines(newSdp, 'video');
  78. const msidExists = videoSsrcs.find(s => s.attribute === 'msid');
  79. expect(msidExists).toBeDefined();
  80. });
  81. });
  82. });