Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

SendVideoController.spec.js 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
  2. import RTCEvents from '../../service/RTC/RTCEvents';
  3. import FeatureFlags from '../flags/FeatureFlags';
  4. import Listenable from '../util/Listenable';
  5. import MediaSessionEvents from '../xmpp/MediaSessionEvents';
  6. import SendVideoController from './SendVideoController';
  7. // JSDocs disabled for Mock classes to avoid duplication - check on the original classes for info.
  8. /* eslint-disable require-jsdoc */
  9. /**
  10. * A mock JingleSessionPC impl that fit the needs of the SendVideoController module.
  11. * Should a generic, shared one exist in the future this test file should switch to use it too.
  12. */
  13. class MockJingleSessionPC extends Listenable {
  14. constructor(rtc, isP2P) {
  15. super();
  16. this.rtc = rtc;
  17. this.isP2P = isP2P;
  18. this._remoteRecvMaxFrameHeight = undefined;
  19. this.senderVideoConstraint = undefined;
  20. }
  21. getRemoteRecvMaxFrameHeight() {
  22. return this._remoteRecvMaxFrameHeight;
  23. }
  24. setSenderVideoConstraint(senderVideoConstraint) {
  25. this.senderVideoConstraint = senderVideoConstraint;
  26. }
  27. setRemoteRecvMaxFrameHeight(remoteRecvMaxFrameHeight) {
  28. this._remoteRecvMaxFrameHeight = remoteRecvMaxFrameHeight;
  29. if (this.isP2P) {
  30. this.eventEmitter.emit(
  31. MediaSessionEvents.REMOTE_VIDEO_CONSTRAINTS_CHANGED,
  32. this);
  33. } else {
  34. this.rtc.eventEmitter.emit(
  35. RTCEvents.SENDER_VIDEO_CONSTRAINTS_CHANGED,
  36. { idealHeight: remoteRecvMaxFrameHeight });
  37. }
  38. }
  39. }
  40. /**
  41. * Mock conference for the purpose of this test file.
  42. */
  43. class MockConference extends Listenable {
  44. /**
  45. * A constructor...
  46. */
  47. constructor() {
  48. super();
  49. this.options = {};
  50. this.activeMediaSession = undefined;
  51. this.mediaSessions = [];
  52. }
  53. addMediaSession(mediaSession) {
  54. this.mediaSessions.push(mediaSession);
  55. this.eventEmitter.emit(JitsiConferenceEvents._MEDIA_SESSION_STARTED, mediaSession);
  56. }
  57. setActiveMediaSession(mediaSession) {
  58. if (this.mediaSessions.indexOf(mediaSession) === -1) {
  59. throw new Error('Given session is not part of this conference');
  60. }
  61. this.activeMediaSession = mediaSession;
  62. this.eventEmitter.emit(JitsiConferenceEvents._MEDIA_SESSION_ACTIVE_CHANGED, this.activeMediaSession);
  63. }
  64. getActiveMediaSession() {
  65. return this.activeMediaSession;
  66. }
  67. getLocalVideoTracks() {
  68. return [];
  69. }
  70. getMediaSessions() {
  71. return this.mediaSessions;
  72. }
  73. }
  74. /**
  75. * Mock {@link RTC} - add things as needed, but only things useful for all tests.
  76. */
  77. export class MockRTC extends Listenable {
  78. /**
  79. * constructor
  80. */
  81. /* eslint-disable no-useless-constructor */
  82. constructor() {
  83. super();
  84. }
  85. }
  86. /* eslint-enable require-jsdoc */
  87. describe('SendVideoController', () => {
  88. let conference;
  89. let rtc;
  90. let sendVideoController;
  91. let jvbConnection;
  92. let p2pConnection;
  93. beforeEach(() => {
  94. conference = new MockConference();
  95. rtc = new MockRTC();
  96. FeatureFlags.init({ sourceNameSignaling: false });
  97. sendVideoController = new SendVideoController(conference, rtc);
  98. jvbConnection = new MockJingleSessionPC(rtc, false /* isP2P */);
  99. p2pConnection = new MockJingleSessionPC(rtc, true /* isP2P */);
  100. conference.addMediaSession(jvbConnection);
  101. conference.addMediaSession(p2pConnection);
  102. });
  103. describe('handles 0 as receiver/sender video constraint', () => {
  104. it('0 if it\'s the active sessions\'s remote recv constraint', () => {
  105. jvbConnection.setRemoteRecvMaxFrameHeight(0);
  106. p2pConnection.setRemoteRecvMaxFrameHeight(720);
  107. conference.setActiveMediaSession(jvbConnection);
  108. expect(jvbConnection.senderVideoConstraint).toBe(0);
  109. expect(p2pConnection.senderVideoConstraint).toBe(0);
  110. });
  111. it('720 if 0 is set on the non-active session', () => {
  112. jvbConnection.setRemoteRecvMaxFrameHeight(0);
  113. p2pConnection.setRemoteRecvMaxFrameHeight(720);
  114. conference.setActiveMediaSession(p2pConnection);
  115. expect(jvbConnection.senderVideoConstraint).toBe(720);
  116. expect(p2pConnection.senderVideoConstraint).toBe(720);
  117. });
  118. it('0 if it\'s the local send preference while remote are 720', () => {
  119. conference.setActiveMediaSession(p2pConnection);
  120. jvbConnection.setRemoteRecvMaxFrameHeight(720);
  121. p2pConnection.setRemoteRecvMaxFrameHeight(720);
  122. sendVideoController.setPreferredSendMaxFrameHeight(0);
  123. expect(jvbConnection.senderVideoConstraint).toBe(0);
  124. expect(p2pConnection.senderVideoConstraint).toBe(0);
  125. });
  126. });
  127. });