Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

SendVideoController.spec.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. setSenderVideoConstraint(senderVideoConstraint) {
  24. this.senderVideoConstraint = senderVideoConstraint;
  25. }
  26. setRemoteRecvMaxFrameHeight(remoteRecvMaxFrameHeight) {
  27. this._remoteRecvMaxFrameHeight = remoteRecvMaxFrameHeight;
  28. if (this.isP2P) {
  29. this.eventEmitter.emit(
  30. MediaSessionEvents.REMOTE_VIDEO_CONSTRAINTS_CHANGED,
  31. this);
  32. } else {
  33. this.rtc.eventEmitter.emit(
  34. RTCEvents.SENDER_VIDEO_CONSTRAINTS_CHANGED,
  35. { idealHeight: remoteRecvMaxFrameHeight });
  36. }
  37. }
  38. }
  39. /**
  40. * Mock conference for the purpose of this test file.
  41. */
  42. class MockConference extends Listenable {
  43. /**
  44. * A constructor...
  45. */
  46. constructor() {
  47. super();
  48. this.options = {
  49. config: { enableLayerSuspension: true }
  50. };
  51. this.activeMediaSession = undefined;
  52. this.mediaSessions = [];
  53. }
  54. addMediaSession(mediaSession) {
  55. this.mediaSessions.push(mediaSession);
  56. this.eventEmitter.emit(JitsiConferenceEvents._MEDIA_SESSION_STARTED, mediaSession);
  57. }
  58. setActiveMediaSession(mediaSession) {
  59. if (this.mediaSessions.indexOf(mediaSession) === -1) {
  60. throw new Error('Given session is not part of this conference');
  61. }
  62. this.activeMediaSession = mediaSession;
  63. this.eventEmitter.emit(JitsiConferenceEvents._MEDIA_SESSION_ACTIVE_CHANGED, this.activeMediaSession);
  64. }
  65. getActiveMediaSession() {
  66. return this.activeMediaSession;
  67. }
  68. getMediaSessions() {
  69. return this.mediaSessions;
  70. }
  71. }
  72. /**
  73. * Mock {@link RTC} - add things as needed, but only things useful for all tests.
  74. */
  75. export class MockRTC extends Listenable {
  76. /**
  77. * constructor
  78. */
  79. /* eslint-disable no-useless-constructor */
  80. constructor() {
  81. super();
  82. }
  83. }
  84. /* eslint-enable require-jsdoc */
  85. describe('SendVideoController', () => {
  86. let conference;
  87. let rtc;
  88. let sendVideoController;
  89. let jvbConnection;
  90. let p2pConnection;
  91. beforeEach(() => {
  92. conference = new MockConference();
  93. rtc = new MockRTC();
  94. sendVideoController = new SendVideoController(conference, rtc);
  95. jvbConnection = new MockJingleSessionPC(rtc, false /* isP2P */);
  96. p2pConnection = new MockJingleSessionPC(rtc, true /* isP2P */);
  97. conference.addMediaSession(jvbConnection);
  98. conference.addMediaSession(p2pConnection);
  99. });
  100. describe('handles 0 as receiver/sender video constraint', () => {
  101. it('0 if it\'s the active sessions\'s remote recv constraint', () => {
  102. jvbConnection.setRemoteRecvMaxFrameHeight(0);
  103. p2pConnection.setRemoteRecvMaxFrameHeight(720);
  104. conference.setActiveMediaSession(jvbConnection);
  105. expect(jvbConnection.senderVideoConstraint).toBe(0);
  106. expect(p2pConnection.senderVideoConstraint).toBe(0);
  107. });
  108. it('720 if 0 is set on the non-active session', () => {
  109. jvbConnection.setRemoteRecvMaxFrameHeight(0);
  110. p2pConnection.setRemoteRecvMaxFrameHeight(720);
  111. conference.setActiveMediaSession(p2pConnection);
  112. expect(jvbConnection.senderVideoConstraint).toBe(720);
  113. expect(p2pConnection.senderVideoConstraint).toBe(720);
  114. });
  115. it('0 if it\'s the local send preference while remote are 720', () => {
  116. conference.setActiveMediaSession(p2pConnection);
  117. jvbConnection.setRemoteRecvMaxFrameHeight(720);
  118. p2pConnection.setRemoteRecvMaxFrameHeight(720);
  119. sendVideoController.setPreferredSendMaxFrameHeight(0);
  120. expect(jvbConnection.senderVideoConstraint).toBe(0);
  121. expect(p2pConnection.senderVideoConstraint).toBe(0);
  122. });
  123. });
  124. });