浏览代码

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 年前
父节点
当前提交
733cc2862e
没有帐户链接到提交者的电子邮件
共有 3 个文件被更改,包括 141 次插入3 次删除
  1. 1
    3
      JitsiMeetJS.js
  2. 15
    0
      modules/qualitycontrol/ReceiveVideoController.js
  3. 125
    0
      modules/qualitycontrol/ReceiveVideoController.spec.js

+ 1
- 3
JitsiMeetJS.js 查看文件

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

+ 15
- 0
modules/qualitycontrol/ReceiveVideoController.js 查看文件

2
 import isEqual from 'lodash.isequal';
2
 import isEqual from 'lodash.isequal';
3
 
3
 
4
 import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
4
 import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
5
+import FeatureFlags from '../flags/FeatureFlags';
5
 
6
 
6
 const logger = getLogger(__filename);
7
 const logger = getLogger(__filename);
7
 const MAX_HEIGHT_ONSTAGE = 2160;
8
 const MAX_HEIGHT_ONSTAGE = 2160;
306
             this._receiverVideoConstraints = new ReceiverVideoConstraints();
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
         const constraintsChanged = this._receiverVideoConstraints.updateReceiverVideoConstraints(constraints);
324
         const constraintsChanged = this._receiverVideoConstraints.updateReceiverVideoConstraints(constraints);
310
 
325
 
311
         if (constraintsChanged) {
326
         if (constraintsChanged) {

+ 125
- 0
modules/qualitycontrol/ReceiveVideoController.spec.js 查看文件

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
+});

正在加载...
取消
保存