Просмотр исходного кода

feat: Adjust setReceiverConstraints to use new format (#1813)

* feat: Adjust setReceiverConstraints to use new format

* add ReceiveVideoController spec

* rename prioritizedSources to onStageSources

* call FeatureFlags.init in specs and update description

* provide a default flags argument to FeatureFlags.init
dev1
William Liang 4 лет назад
Родитель
Сommit
733cc2862e
Аккаунт пользователя с таким Email не найден

+ 1
- 3
JitsiMeetJS.js Просмотреть файл

@@ -146,9 +146,7 @@ export default _mergeNamespaceAndModule({
146 146
         Statistics.init(options);
147 147
 
148 148
         // Configure the feature flags.
149
-        FeatureFlags.init({
150
-            sourceNameSignaling: options.sourceNameSignaling
151
-        });
149
+        FeatureFlags.init(options.flags || { });
152 150
 
153 151
         // Initialize global window.connectionTimes
154 152
         // FIXME do not use 'window'

+ 15
- 0
modules/qualitycontrol/ReceiveVideoController.js Просмотреть файл

@@ -2,6 +2,7 @@ import { getLogger } from '@jitsi/logger';
2 2
 import isEqual from 'lodash.isequal';
3 3
 
4 4
 import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
5
+import FeatureFlags from '../flags/FeatureFlags';
5 6
 
6 7
 const logger = getLogger(__filename);
7 8
 const MAX_HEIGHT_ONSTAGE = 2160;
@@ -306,6 +307,20 @@ export class ReceiveVideoController {
306 307
             this._receiverVideoConstraints = new ReceiverVideoConstraints();
307 308
         }
308 309
 
310
+        const isEndpointsFormat = Object.keys(constraints).includes('onStageEndpoints', 'selectedEndpoints');
311
+        const isSourcesFormat = Object.keys(constraints).includes('onStageSources', 'selectedSources');
312
+
313
+        if (!FeatureFlags.isSourceNameSignalingEnabled() && isSourcesFormat) {
314
+            throw new Error(
315
+                '"onStageSources" and "selectedSources" are not supported when sourceNameSignaling is disabled.'
316
+            );
317
+        }
318
+
319
+        if (FeatureFlags.isSourceNameSignalingEnabled() && isEndpointsFormat) {
320
+            throw new Error(
321
+                '"onStageEndpoints" and "selectedEndpoints" are not supported when sourceNameSignaling is enabled.'
322
+            );
323
+        }
309 324
         const constraintsChanged = this._receiverVideoConstraints.updateReceiverVideoConstraints(constraints);
310 325
 
311 326
         if (constraintsChanged) {

+ 125
- 0
modules/qualitycontrol/ReceiveVideoController.spec.js Просмотреть файл

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

Загрузка…
Отмена
Сохранить