Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

QualityController.spec.js 4.2KB

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