Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

LocalSdpMunger.spec.js 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. const sdpStr = transform.write(SampleSdpStrings.recvOnlySdp);
  26. const desc = new RTCSessionDescription({
  27. type: 'offer',
  28. sdp: sdpStr
  29. });
  30. const transformedDesc = localSdpMunger.transformStreamIdentifiers(desc);
  31. const newSdp = transform.parse(transformedDesc.sdp);
  32. const audioSsrcs = getSsrcLines(newSdp, 'audio');
  33. const videoSsrcs = getSsrcLines(newSdp, 'video');
  34. expect(audioSsrcs.length).toEqual(0);
  35. expect(videoSsrcs.length).toEqual(0);
  36. });
  37. it('should do nothing to an sdp with msid', () => {
  38. const sdpStr = transform.write(SampleSdpStrings.simulcastSdp);
  39. const desc = new RTCSessionDescription({
  40. type: 'offer',
  41. sdp: sdpStr
  42. });
  43. const transformedDesc = localSdpMunger.transformStreamIdentifiers(desc);
  44. const newSdp = transform.parse(transformedDesc.sdp);
  45. const audioSsrcs = getSsrcLines(newSdp, 'audio');
  46. const videoSsrcs = getSsrcLines(newSdp, 'video');
  47. expect(audioSsrcs.length).toEqual(4);
  48. expect(videoSsrcs.length).toEqual(6);
  49. });
  50. it('should add endpointId to msid', () => {
  51. const sdpStr = transform.write(SampleSdpStrings.firefoxSdp);
  52. const desc = new RTCSessionDescription({
  53. type: 'offer',
  54. sdp: sdpStr
  55. });
  56. const transformedDesc = localSdpMunger.transformStreamIdentifiers(desc);
  57. const newSdp = transform.parse(transformedDesc.sdp);
  58. const videoSsrcs = getSsrcLines(newSdp, 'video');
  59. for (const ssrcLine of videoSsrcs) {
  60. if (ssrcLine.attribute === 'msid') {
  61. const msid = ssrcLine.value.split(' ')[0];
  62. expect(msid).toBe(`${localEndpointId}-video-${tpc.id}`);
  63. }
  64. }
  65. });
  66. });
  67. });