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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. it('should strip ssrcs from an sdp with no msid (i.e., recvonly transceivers)', () => {
  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. describe('should strip cname, label and mslabel from an sdp with msid', () => {
  39. let audioSsrcs, videoSsrcs;
  40. const transformStreamIdentifiers = () => {
  41. const sdpStr = transform.write(SampleSdpStrings.simulcastSdp);
  42. const desc = new RTCSessionDescription({
  43. type: 'offer',
  44. sdp: sdpStr
  45. });
  46. const ssrcMap = new Map();
  47. ssrcMap.set('sRdpsdg-v0', {
  48. ssrcs: [ 1757014965, 1479742055, 1089111804 ],
  49. msid: 'sRdpsdg-video-0',
  50. groups: [ {
  51. semantics: 'SIM',
  52. ssrcs: [ 1757014965, 1479742055, 1089111804 ] } ]
  53. });
  54. ssrcMap.set('sRdpsdg-a0', {
  55. ssrcs: [ 124723944 ],
  56. msid: 'sRdpsdg-audio-0'
  57. });
  58. const transformedDesc = localSdpMunger.transformStreamIdentifiers(desc, ssrcMap);
  59. const newSdp = transform.parse(transformedDesc.sdp);
  60. audioSsrcs = getSsrcLines(newSdp, 'audio');
  61. videoSsrcs = getSsrcLines(newSdp, 'video');
  62. };
  63. it('with source name signaling enabled (injected source name)', () => {
  64. transformStreamIdentifiers();
  65. expect(audioSsrcs.length).toEqual(1 + 1 /* injected source name */);
  66. expect(videoSsrcs.length).toEqual(3 + 3 /* injected source name into each ssrc */);
  67. });
  68. });
  69. });
  70. describe('addMsids', () => {
  71. it('should add endpointId to msid', () => {
  72. const sdpStr = transform.write(SampleSdpStrings.firefoxSdp);
  73. const desc = new RTCSessionDescription({
  74. type: 'offer',
  75. sdp: sdpStr
  76. });
  77. const ssrcMap = new Map();
  78. ssrcMap.set('sRdpsdg-v0', {
  79. ssrcs: [ 984899560 ],
  80. msid: 'sRdpsdg-video-0'
  81. });
  82. ssrcMap.set('sRdpsdg-a0', {
  83. ssrcs: [ 124723944 ],
  84. msid: 'sRdpsdg-audio-0'
  85. });
  86. const transformedDesc = localSdpMunger.transformStreamIdentifiers(desc, ssrcMap);
  87. const newSdp = transform.parse(transformedDesc.sdp);
  88. const videoSsrcs = getSsrcLines(newSdp, 'video');
  89. for (const ssrcLine of videoSsrcs) {
  90. if (ssrcLine.attribute === 'msid') {
  91. const msid = ssrcLine.value;
  92. expect(msid).toBe(`${localEndpointId}-video-0-${tpc.id}`);
  93. }
  94. }
  95. });
  96. it('should add missing msid', () => {
  97. // P2P case only.
  98. localSdpMunger.tpc.isP2P = true;
  99. const sdpStr = transform.write(SampleSdpStrings.firefoxP2pSdp);
  100. const desc = new RTCSessionDescription({
  101. type: 'offer',
  102. sdp: sdpStr
  103. });
  104. const ssrcMap = new Map();
  105. ssrcMap.set('sRdpsdg-v0', {
  106. ssrcs: [ 984899560 ],
  107. msid: 'sRdpsdg-video-0'
  108. });
  109. ssrcMap.set('sRdpsdg-a0', {
  110. ssrcs: [ 124723944 ],
  111. msid: 'sRdpsdg-audio-0'
  112. });
  113. const transformedDesc = localSdpMunger.transformStreamIdentifiers(desc, ssrcMap);
  114. const newSdp = transform.parse(transformedDesc.sdp);
  115. const videoSsrcs = getSsrcLines(newSdp, 'video');
  116. const msidExists = videoSsrcs.find(s => s.attribute === 'msid');
  117. expect(msidExists).toBeDefined();
  118. });
  119. });
  120. });
  121. describe('Transform msids for source-name signaling', () => {
  122. const tpc = new MockPeerConnection('1', false);
  123. const localEndpointId = 'sRdpsdg';
  124. const localSdpMunger = new LocalSdpMunger(tpc, localEndpointId);
  125. let audioMsid, audioMsidLine, videoMsid, videoMsidLine;
  126. const transformStreamIdentifiers = () => {
  127. const sdpStr = transform.write(SampleSdpStrings.simulcastRtxSdp);
  128. const desc = new RTCSessionDescription({
  129. type: 'offer',
  130. sdp: sdpStr
  131. });
  132. const ssrcMap = new Map();
  133. ssrcMap.set('sRdpsdg-v0', {
  134. ssrcs: [ 1757014965, 984899560, 1479742055, 855213044, 1089111804, 2963867077 ],
  135. msid: 'sRdpsdg-video-0'
  136. });
  137. ssrcMap.set('sRdpsdg-a0', {
  138. ssrcs: [ 124723944 ],
  139. msid: 'sRdpsdg-audio-0'
  140. });
  141. const transformedDesc = localSdpMunger.transformStreamIdentifiers(desc, ssrcMap);
  142. const newSdp = transform.parse(transformedDesc.sdp);
  143. audioMsidLine = getSsrcLines(newSdp, 'audio').find(ssrc => ssrc.attribute === 'msid')?.value;
  144. audioMsid = audioMsidLine.split(' ')[0];
  145. videoMsidLine = getSsrcLines(newSdp, 'video').find(ssrc => ssrc.attribute === 'msid')?.value;
  146. videoMsid = videoMsidLine.split(' ')[0];
  147. };
  148. it('should transform', () => {
  149. transformStreamIdentifiers();
  150. expect(audioMsid).toBe('sRdpsdg-audio-0-1');
  151. expect(videoMsid).toBe('sRdpsdg-video-0-1');
  152. });
  153. });