|
@@ -1,21 +1,13 @@
|
1
|
1
|
// @flow
|
2
|
2
|
|
3
|
|
-import {
|
4
|
|
- CONFERENCE_JOINED,
|
5
|
|
- DATA_CHANNEL_OPENED
|
6
|
|
-} from '../base/conference';
|
|
3
|
+import { CONFERENCE_JOINED } from '../base/conference';
|
7
|
4
|
import { SET_CONFIG } from '../base/config';
|
8
|
|
-import { getParticipantCount } from '../base/participants';
|
9
|
|
-import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
|
10
|
|
-import { shouldDisplayTileView } from '../video-layout';
|
|
5
|
+import { MiddlewareRegistry } from '../base/redux';
|
11
|
6
|
|
12
|
|
-import { setPreferredVideoQuality, setMaxReceiverVideoQuality } from './actions';
|
13
|
|
-import { VIDEO_QUALITY_LEVELS } from './constants';
|
14
|
|
-import { getReceiverVideoQualityLevel } from './functions';
|
|
7
|
+import { setPreferredVideoQuality } from './actions';
|
15
|
8
|
import logger from './logger';
|
16
|
|
-import { getMinHeightForQualityLvlMap } from './selector';
|
17
|
9
|
|
18
|
|
-declare var APP: Object;
|
|
10
|
+import './subscriber';
|
19
|
11
|
|
20
|
12
|
/**
|
21
|
13
|
* Implements the middleware of the feature video-quality.
|
|
@@ -24,10 +16,6 @@ declare var APP: Object;
|
24
|
16
|
* @returns {Function}
|
25
|
17
|
*/
|
26
|
18
|
MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
|
27
|
|
- if (action.type === DATA_CHANNEL_OPENED) {
|
28
|
|
- return _syncReceiveVideoQuality(getState, next, action);
|
29
|
|
- }
|
30
|
|
-
|
31
|
19
|
const result = next(action);
|
32
|
20
|
|
33
|
21
|
switch (action.type) {
|
|
@@ -57,165 +45,3 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
|
57
|
45
|
|
58
|
46
|
return result;
|
59
|
47
|
});
|
60
|
|
-
|
61
|
|
-/**
|
62
|
|
- * Implements a state listener in order to calculate max receiver video quality.
|
63
|
|
- */
|
64
|
|
-StateListenerRegistry.register(
|
65
|
|
- /* selector */ state => {
|
66
|
|
- const { reducedUI } = state['features/base/responsive-ui'];
|
67
|
|
- const _shouldDisplayTileView = shouldDisplayTileView(state);
|
68
|
|
- const thumbnailSize = state['features/filmstrip']?.tileViewDimensions?.thumbnailSize;
|
69
|
|
- const participantCount = getParticipantCount(state);
|
70
|
|
-
|
71
|
|
- return {
|
72
|
|
- displayTileView: _shouldDisplayTileView,
|
73
|
|
- participantCount,
|
74
|
|
- reducedUI,
|
75
|
|
- thumbnailHeight: thumbnailSize?.height
|
76
|
|
- };
|
77
|
|
- },
|
78
|
|
- /* listener */ ({ displayTileView, participantCount, reducedUI, thumbnailHeight }, { dispatch, getState }) => {
|
79
|
|
- const state = getState();
|
80
|
|
- const { maxReceiverVideoQuality } = state['features/video-quality'];
|
81
|
|
- const { maxFullResolutionParticipants = 2 } = state['features/base/config'];
|
82
|
|
-
|
83
|
|
- let newMaxRecvVideoQuality = VIDEO_QUALITY_LEVELS.ULTRA;
|
84
|
|
-
|
85
|
|
- if (reducedUI) {
|
86
|
|
- newMaxRecvVideoQuality = VIDEO_QUALITY_LEVELS.LOW;
|
87
|
|
- } else if (displayTileView && !Number.isNaN(thumbnailHeight)) {
|
88
|
|
- newMaxRecvVideoQuality = getReceiverVideoQualityLevel(thumbnailHeight, getMinHeightForQualityLvlMap(state));
|
89
|
|
-
|
90
|
|
- // Override HD level calculated for the thumbnail height when # of participants threshold is exceeded
|
91
|
|
- if (maxReceiverVideoQuality !== newMaxRecvVideoQuality && maxFullResolutionParticipants !== -1) {
|
92
|
|
- const override
|
93
|
|
- = participantCount > maxFullResolutionParticipants
|
94
|
|
- && newMaxRecvVideoQuality > VIDEO_QUALITY_LEVELS.STANDARD;
|
95
|
|
-
|
96
|
|
- logger.info(`Video quality level for thumbnail height: ${thumbnailHeight}, `
|
97
|
|
- + `is: ${newMaxRecvVideoQuality}, `
|
98
|
|
- + `override: ${String(override)}, `
|
99
|
|
- + `max full res N: ${maxFullResolutionParticipants}`);
|
100
|
|
-
|
101
|
|
- if (override) {
|
102
|
|
- newMaxRecvVideoQuality = VIDEO_QUALITY_LEVELS.STANDARD;
|
103
|
|
- }
|
104
|
|
- }
|
105
|
|
- }
|
106
|
|
-
|
107
|
|
- if (maxReceiverVideoQuality !== newMaxRecvVideoQuality) {
|
108
|
|
- dispatch(setMaxReceiverVideoQuality(newMaxRecvVideoQuality));
|
109
|
|
- }
|
110
|
|
- }, {
|
111
|
|
- deepEquals: true
|
112
|
|
- });
|
113
|
|
-
|
114
|
|
-/**
|
115
|
|
- * Helper function for updating the preferred receiver video constraint, based
|
116
|
|
- * on the user preference and the internal maximum.
|
117
|
|
- *
|
118
|
|
- * @param {JitsiConference} conference - The JitsiConference instance for the
|
119
|
|
- * current call.
|
120
|
|
- * @param {number} preferred - The user preferred max frame height.
|
121
|
|
- * @param {number} max - The maximum frame height the application should
|
122
|
|
- * receive.
|
123
|
|
- * @returns {void}
|
124
|
|
- */
|
125
|
|
-function _setReceiverVideoConstraint(conference, preferred, max) {
|
126
|
|
- if (conference) {
|
127
|
|
- const value = Math.min(preferred, max);
|
128
|
|
-
|
129
|
|
- conference.setReceiverVideoConstraint(value);
|
130
|
|
- logger.info(`setReceiverVideoConstraint: ${value}`);
|
131
|
|
- }
|
132
|
|
-}
|
133
|
|
-
|
134
|
|
-/**
|
135
|
|
- * Helper function for updating the preferred sender video constraint, based
|
136
|
|
- * on the user preference.
|
137
|
|
- *
|
138
|
|
- * @param {JitsiConference} conference - The JitsiConference instance for the
|
139
|
|
- * current call.
|
140
|
|
- * @param {number} preferred - The user preferred max frame height.
|
141
|
|
- * @returns {void}
|
142
|
|
- */
|
143
|
|
-function _setSenderVideoConstraint(conference, preferred) {
|
144
|
|
- if (conference) {
|
145
|
|
- conference.setSenderVideoConstraint(preferred)
|
146
|
|
- .catch(err => {
|
147
|
|
- logger.error(`Changing sender resolution to ${preferred} failed - ${err} `);
|
148
|
|
- });
|
149
|
|
- }
|
150
|
|
-}
|
151
|
|
-
|
152
|
|
-/**
|
153
|
|
- * Sets the maximum receive video quality.
|
154
|
|
- *
|
155
|
|
- * @param {Function} getState - The redux function which returns the current redux state.
|
156
|
|
- * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
157
|
|
- * specified {@code action} to the specified {@code store}.
|
158
|
|
- * @param {Action} action - The redux action {@code DATA_CHANNEL_STATUS_CHANGED}
|
159
|
|
- * which is being dispatched in the specified {@code store}.
|
160
|
|
- * @private
|
161
|
|
- * @returns {Object} The value returned by {@code next(action)}.
|
162
|
|
- */
|
163
|
|
-function _syncReceiveVideoQuality(getState, next, action) {
|
164
|
|
- const state = getState();
|
165
|
|
- const {
|
166
|
|
- conference
|
167
|
|
- } = state['features/base/conference'];
|
168
|
|
- const {
|
169
|
|
- maxReceiverVideoQuality,
|
170
|
|
- preferredVideoQuality
|
171
|
|
- } = state['features/video-quality'];
|
172
|
|
-
|
173
|
|
- _setReceiverVideoConstraint(
|
174
|
|
- conference,
|
175
|
|
- preferredVideoQuality,
|
176
|
|
- maxReceiverVideoQuality);
|
177
|
|
-
|
178
|
|
- return next(action);
|
179
|
|
-}
|
180
|
|
-
|
181
|
|
-
|
182
|
|
-/**
|
183
|
|
- * Registers a change handler for state['features/base/conference'] to update
|
184
|
|
- * the preferred video quality levels based on user preferred and internal
|
185
|
|
- * settings.
|
186
|
|
- */
|
187
|
|
-StateListenerRegistry.register(
|
188
|
|
- /* selector */ state => {
|
189
|
|
- const { conference } = state['features/base/conference'];
|
190
|
|
- const {
|
191
|
|
- maxReceiverVideoQuality,
|
192
|
|
- preferredVideoQuality
|
193
|
|
- } = state['features/video-quality'];
|
194
|
|
-
|
195
|
|
- return {
|
196
|
|
- conference,
|
197
|
|
- maxReceiverVideoQuality,
|
198
|
|
- preferredVideoQuality
|
199
|
|
- };
|
200
|
|
- },
|
201
|
|
- /* listener */ (currentState, store, previousState = {}) => {
|
202
|
|
- const {
|
203
|
|
- conference,
|
204
|
|
- maxReceiverVideoQuality,
|
205
|
|
- preferredVideoQuality
|
206
|
|
- } = currentState;
|
207
|
|
- const changedConference = conference !== previousState.conference;
|
208
|
|
- const changedPreferredVideoQuality = preferredVideoQuality !== previousState.preferredVideoQuality;
|
209
|
|
- const changedMaxVideoQuality = maxReceiverVideoQuality !== previousState.maxReceiverVideoQuality;
|
210
|
|
-
|
211
|
|
- if (changedConference || changedPreferredVideoQuality || changedMaxVideoQuality) {
|
212
|
|
- _setReceiverVideoConstraint(conference, preferredVideoQuality, maxReceiverVideoQuality);
|
213
|
|
- }
|
214
|
|
- if (changedConference || changedPreferredVideoQuality) {
|
215
|
|
- _setSenderVideoConstraint(conference, preferredVideoQuality);
|
216
|
|
- }
|
217
|
|
-
|
218
|
|
- if (typeof APP !== 'undefined' && changedPreferredVideoQuality) {
|
219
|
|
- APP.API.notifyVideoQualityChanged(preferredVideoQuality);
|
220
|
|
- }
|
221
|
|
- });
|