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.

SendVideoController.spec.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. config: { enableLayerSuspension: true }
  51. };
  52. this.activeMediaSession = undefined;
  53. this.mediaSessions = [];
  54. }
  55. addMediaSession(mediaSession) {
  56. this.mediaSessions.push(mediaSession);
  57. this.eventEmitter.emit(JitsiConferenceEvents._MEDIA_SESSION_STARTED, mediaSession);
  58. }
  59. setActiveMediaSession(mediaSession) {
  60. if (this.mediaSessions.indexOf(mediaSession) === -1) {
  61. throw new Error('Given session is not part of this conference');
  62. }
  63. this.activeMediaSession = mediaSession;
  64. this.eventEmitter.emit(JitsiConferenceEvents._MEDIA_SESSION_ACTIVE_CHANGED, this.activeMediaSession);
  65. }
  66. getActiveMediaSession() {
  67. return this.activeMediaSession;
  68. }
  69. getLocalVideoTracks() {
  70. return [];
  71. }
  72. getMediaSessions() {
  73. return this.mediaSessions;
  74. }
  75. }
  76. /**
  77. * Mock {@link RTC} - add things as needed, but only things useful for all tests.
  78. */
  79. export class MockRTC extends Listenable {
  80. /**
  81. * constructor
  82. */
  83. /* eslint-disable no-useless-constructor */
  84. constructor() {
  85. super();
  86. }
  87. }
  88. /* eslint-enable require-jsdoc */
  89. describe('SendVideoController', () => {
  90. let conference;
  91. let rtc;
  92. let sendVideoController;
  93. let jvbConnection;
  94. let p2pConnection;
  95. beforeEach(() => {
  96. conference = new MockConference();
  97. rtc = new MockRTC();
  98. FeatureFlags.init({ sourceNameSignaling: false });
  99. sendVideoController = new SendVideoController(conference, rtc);
  100. jvbConnection = new MockJingleSessionPC(rtc, false /* isP2P */);
  101. p2pConnection = new MockJingleSessionPC(rtc, true /* isP2P */);
  102. conference.addMediaSession(jvbConnection);
  103. conference.addMediaSession(p2pConnection);
  104. });
  105. describe('handles 0 as receiver/sender video constraint', () => {
  106. it('0 if it\'s the active sessions\'s remote recv constraint', () => {
  107. jvbConnection.setRemoteRecvMaxFrameHeight(0);
  108. p2pConnection.setRemoteRecvMaxFrameHeight(720);
  109. conference.setActiveMediaSession(jvbConnection);
  110. expect(jvbConnection.senderVideoConstraint).toBe(0);
  111. expect(p2pConnection.senderVideoConstraint).toBe(0);
  112. });
  113. it('720 if 0 is set on the non-active session', () => {
  114. jvbConnection.setRemoteRecvMaxFrameHeight(0);
  115. p2pConnection.setRemoteRecvMaxFrameHeight(720);
  116. conference.setActiveMediaSession(p2pConnection);
  117. expect(jvbConnection.senderVideoConstraint).toBe(720);
  118. expect(p2pConnection.senderVideoConstraint).toBe(720);
  119. });
  120. it('0 if it\'s the local send preference while remote are 720', () => {
  121. conference.setActiveMediaSession(p2pConnection);
  122. jvbConnection.setRemoteRecvMaxFrameHeight(720);
  123. p2pConnection.setRemoteRecvMaxFrameHeight(720);
  124. sendVideoController.setPreferredSendMaxFrameHeight(0);
  125. expect(jvbConnection.senderVideoConstraint).toBe(0);
  126. expect(p2pConnection.senderVideoConstraint).toBe(0);
  127. });
  128. });
  129. });