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

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