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

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