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.

ReceiveVideoController.spec.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import FeatureFlags from '../flags/FeatureFlags';
  2. import Listenable from '../util/Listenable';
  3. import { ReceiveVideoController } from './ReceiveVideoController';
  4. // JSDocs disabled for Mock classes to avoid duplication - check on the original classes for info.
  5. /* eslint-disable require-jsdoc */
  6. /**
  7. * Mock conference for the purpose of this test file.
  8. */
  9. class MockConference extends Listenable {
  10. /**
  11. * A constructor...
  12. */
  13. constructor() {
  14. super();
  15. this.options = {
  16. config: {}
  17. };
  18. this.activeMediaSession = undefined;
  19. this.mediaSessions = [];
  20. }
  21. getMediaSessions() {
  22. return this.mediaSessions;
  23. }
  24. }
  25. /**
  26. * Mock {@link RTC} - add things as needed, but only things useful for all tests.
  27. */
  28. export class MockRTC extends Listenable {
  29. /**
  30. * constructor
  31. */
  32. /* eslint-disable no-useless-constructor */
  33. constructor() {
  34. super();
  35. }
  36. // eslint-disable-next-line no-empty-function
  37. setNewReceiverVideoConstraints() {
  38. }
  39. }
  40. /* eslint-enable require-jsdoc */
  41. describe('ReceiveVideoController', () => {
  42. let conference;
  43. let rtc;
  44. let receiveVideoController;
  45. beforeEach(() => {
  46. conference = new MockConference();
  47. rtc = new MockRTC();
  48. receiveVideoController = new ReceiveVideoController(conference, rtc);
  49. });
  50. describe('when sourceNameSignaling is enabled', () => {
  51. beforeEach(() => {
  52. FeatureFlags.init({ sourceNameSignaling: true });
  53. });
  54. it('should call setNewReceiverVideoConstraints with the source names format.', () => {
  55. const rtcSpy = spyOn(rtc, 'setNewReceiverVideoConstraints');
  56. const constraints = {
  57. onStageSources: [ 'A_camera_1', 'B_screen_2', 'C_camera_1' ],
  58. selectedSources: [ 'A_camera_1' ]
  59. };
  60. receiveVideoController.setReceiverConstraints(constraints);
  61. expect(rtcSpy).toHaveBeenCalledWith(constraints);
  62. });
  63. it('should not allow the endpoints format.', () => {
  64. const constraints = {
  65. onStageEndpoints: [ 'A', 'B', 'C' ],
  66. selectedEndpoints: [ 'A' ]
  67. };
  68. try {
  69. receiveVideoController.setReceiverConstraints(constraints);
  70. fail();
  71. } catch (error) {
  72. expect(error).toEqual(new Error(
  73. '"onStageEndpoints" and "selectedEndpoints" are not supported when sourceNameSignaling is enabled.'
  74. ));
  75. }
  76. });
  77. });
  78. describe('when sourceNameSignaling is disabled', () => {
  79. beforeEach(() => {
  80. FeatureFlags.init({ sourceNameSignaling: false });
  81. });
  82. it('should call setNewReceiverVideoConstraints with the endpoints format.', () => {
  83. const rtcSpy = spyOn(rtc, 'setNewReceiverVideoConstraints');
  84. const constraints = {
  85. onStageEndpoints: [ 'A', 'B', 'C' ],
  86. selectedEndpoints: [ 'A' ]
  87. };
  88. receiveVideoController.setReceiverConstraints(constraints);
  89. expect(rtcSpy).toHaveBeenCalledWith(constraints);
  90. });
  91. it('should not allow the source names format.', () => {
  92. const constraints = {
  93. onStageSources: [ 'A_camera_1', 'B_screen_2', 'C_camera_1' ],
  94. selectedSources: [ 'A_camera_1' ]
  95. };
  96. try {
  97. receiveVideoController.setReceiverConstraints(constraints);
  98. fail();
  99. } catch (error) {
  100. expect(error).toEqual(new Error(
  101. '"onStageSources" and "selectedSources" are not supported when sourceNameSignaling is disabled.'
  102. ));
  103. }
  104. });
  105. });
  106. });