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 4.7KB

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