|
@@ -8,22 +8,23 @@ import { connect } from 'react-redux';
|
8
|
8
|
import { Dialog, hideDialog } from '../../base/dialog';
|
9
|
9
|
import { translate } from '../../base/i18n';
|
10
|
10
|
|
11
|
|
-import { obtainDesktopSources, resetDesktopSources } from '../actions';
|
12
|
11
|
import DesktopPickerPane from './DesktopPickerPane';
|
|
12
|
+import { obtainDesktopSources } from '../functions';
|
13
|
13
|
|
14
|
14
|
const THUMBNAIL_SIZE = {
|
15
|
15
|
height: 300,
|
16
|
16
|
width: 300
|
17
|
17
|
};
|
18
|
|
-const UPDATE_INTERVAL = 1000;
|
|
18
|
+
|
|
19
|
+const UPDATE_INTERVAL = 2000;
|
19
|
20
|
|
20
|
21
|
type TabConfiguration = {
|
21
|
22
|
defaultSelected?: boolean,
|
22
|
|
- label: string,
|
23
|
|
- type: string
|
|
23
|
+ label: string
|
24
|
24
|
};
|
25
|
|
-const TAB_CONFIGURATIONS: Array<TabConfiguration> = [
|
26
|
|
- {
|
|
25
|
+
|
|
26
|
+const TAB_CONFIGURATIONS: { [type: string]: TabConfiguration} = {
|
|
27
|
+ screen: {
|
27
|
28
|
/**
|
28
|
29
|
* The indicator which determines whether this tab configuration is
|
29
|
30
|
* selected by default.
|
|
@@ -31,15 +32,14 @@ const TAB_CONFIGURATIONS: Array<TabConfiguration> = [
|
31
|
32
|
* @type {boolean}
|
32
|
33
|
*/
|
33
|
34
|
defaultSelected: true,
|
34
|
|
- label: 'dialog.yourEntireScreen',
|
35
|
|
- type: 'screen'
|
|
35
|
+ label: 'dialog.yourEntireScreen'
|
36
|
36
|
},
|
37
|
|
- {
|
38
|
|
- label: 'dialog.applicationWindow',
|
39
|
|
- type: 'window'
|
|
37
|
+ window: {
|
|
38
|
+ label: 'dialog.applicationWindow'
|
40
|
39
|
}
|
41
|
|
-];
|
42
|
|
-const VALID_TYPES = TAB_CONFIGURATIONS.map(c => c.type);
|
|
40
|
+};
|
|
41
|
+
|
|
42
|
+const VALID_TYPES = Object.keys(TAB_CONFIGURATIONS);
|
43
|
43
|
|
44
|
44
|
/**
|
45
|
45
|
* React component for DesktopPicker.
|
|
@@ -47,21 +47,18 @@ const VALID_TYPES = TAB_CONFIGURATIONS.map(c => c.type);
|
47
|
47
|
* @extends Component
|
48
|
48
|
*/
|
49
|
49
|
class DesktopPicker extends Component {
|
50
|
|
- /**
|
51
|
|
- * Default values for DesktopPicker component's properties.
|
52
|
|
- *
|
53
|
|
- * @static
|
54
|
|
- */
|
55
|
|
- static defaultProps = {
|
56
|
|
- options: {}
|
57
|
|
- };
|
58
|
|
-
|
59
|
50
|
/**
|
60
|
51
|
* DesktopPicker component's property types.
|
61
|
52
|
*
|
62
|
53
|
* @static
|
63
|
54
|
*/
|
64
|
55
|
static propTypes = {
|
|
56
|
+
|
|
57
|
+ /**
|
|
58
|
+ * An array with desktop sharing sources to be displayed.
|
|
59
|
+ */
|
|
60
|
+ desktopSharingSources: PropTypes.arrayOf(PropTypes.string),
|
|
61
|
+
|
65
|
62
|
/**
|
66
|
63
|
* Used to request DesktopCapturerSources.
|
67
|
64
|
*/
|
|
@@ -73,17 +70,6 @@ class DesktopPicker extends Component {
|
73
|
70
|
*/
|
74
|
71
|
onSourceChoose: PropTypes.func,
|
75
|
72
|
|
76
|
|
- /**
|
77
|
|
- * An object with options related to desktop sharing.
|
78
|
|
- */
|
79
|
|
- options: PropTypes.object,
|
80
|
|
-
|
81
|
|
- /**
|
82
|
|
- * An object with arrays of DesktopCapturerSources. The key should be
|
83
|
|
- * the source type.
|
84
|
|
- */
|
85
|
|
- sources: PropTypes.object,
|
86
|
|
-
|
87
|
73
|
/**
|
88
|
74
|
* Used to obtain translations.
|
89
|
75
|
*/
|
|
@@ -94,8 +80,8 @@ class DesktopPicker extends Component {
|
94
|
80
|
|
95
|
81
|
state = {
|
96
|
82
|
selectedSource: {},
|
97
|
|
- tabsToPopulate: [],
|
98
|
|
- typesToFetch: []
|
|
83
|
+ sources: {},
|
|
84
|
+ types: []
|
99
|
85
|
};
|
100
|
86
|
|
101
|
87
|
/**
|
|
@@ -112,20 +98,18 @@ class DesktopPicker extends Component {
|
112
|
98
|
this._onPreviewClick = this._onPreviewClick.bind(this);
|
113
|
99
|
this._onSubmit = this._onSubmit.bind(this);
|
114
|
100
|
this._updateSources = this._updateSources.bind(this);
|
|
101
|
+
|
|
102
|
+ this.state.types
|
|
103
|
+ = this._getValidTypes(this.props.desktopSharingSources);
|
115
|
104
|
}
|
116
|
105
|
|
117
|
106
|
/**
|
118
|
|
- * Perform an immediate update request for DesktopCapturerSources and begin
|
119
|
|
- * requesting updates at an interval.
|
|
107
|
+ * Starts polling.
|
120
|
108
|
*
|
121
|
109
|
* @inheritdoc
|
|
110
|
+ * @returns {void}
|
122
|
111
|
*/
|
123
|
|
- componentWillMount() {
|
124
|
|
- const { desktopSharingSources } = this.props.options;
|
125
|
|
-
|
126
|
|
- this._onSourceTypesConfigChanged(
|
127
|
|
- desktopSharingSources);
|
128
|
|
- this._updateSources();
|
|
112
|
+ componentDidMount() {
|
129
|
113
|
this._startPolling();
|
130
|
114
|
}
|
131
|
115
|
|
|
@@ -139,20 +123,19 @@ class DesktopPicker extends Component {
|
139
|
123
|
* @returns {void}
|
140
|
124
|
*/
|
141
|
125
|
componentWillReceiveProps(nextProps) {
|
142
|
|
- if (!this.state.selectedSource.id
|
143
|
|
- && nextProps.sources.screen.length) {
|
|
126
|
+ const { desktopSharingSources } = nextProps;
|
|
127
|
+
|
|
128
|
+ /**
|
|
129
|
+ * Do only reference check in order to not calculate the types on every
|
|
130
|
+ * update. This is enough for our use case and we don't need value
|
|
131
|
+ * checking because if the value is the same we won't change the
|
|
132
|
+ * reference for the desktopSharingSources array.
|
|
133
|
+ */
|
|
134
|
+ if (desktopSharingSources !== this.props.desktopSharingSources) {
|
144
|
135
|
this.setState({
|
145
|
|
- selectedSource: {
|
146
|
|
- id: nextProps.sources.screen[0].id,
|
147
|
|
- type: 'screen'
|
148
|
|
- }
|
|
136
|
+ types: this._getValidTypes(desktopSharingSources)
|
149
|
137
|
});
|
150
|
138
|
}
|
151
|
|
-
|
152
|
|
- const { desktopSharingSources } = this.props.options;
|
153
|
|
-
|
154
|
|
- this._onSourceTypesConfigChanged(
|
155
|
|
- desktopSharingSources);
|
156
|
139
|
}
|
157
|
140
|
|
158
|
141
|
/**
|
|
@@ -162,7 +145,6 @@ class DesktopPicker extends Component {
|
162
|
145
|
*/
|
163
|
146
|
componentWillUnmount() {
|
164
|
147
|
this._stopPolling();
|
165
|
|
- this.props.dispatch(resetDesktopSources());
|
166
|
148
|
}
|
167
|
149
|
|
168
|
150
|
/**
|
|
@@ -174,6 +156,7 @@ class DesktopPicker extends Component {
|
174
|
156
|
return (
|
175
|
157
|
<Dialog
|
176
|
158
|
isModal = { false }
|
|
159
|
+ okDisabled = { Boolean(!this.state.selectedSource.id) }
|
177
|
160
|
okTitleKey = 'dialog.Share'
|
178
|
161
|
onCancel = { this._onCloseModal }
|
179
|
162
|
onSubmit = { this._onSubmit }
|
|
@@ -220,22 +203,14 @@ class DesktopPicker extends Component {
|
220
|
203
|
}
|
221
|
204
|
|
222
|
205
|
/**
|
223
|
|
- * Handles changing of allowed desktop sharing source types.
|
|
206
|
+ * Extracts only the valid types from the passed {@code types}.
|
224
|
207
|
*
|
225
|
|
- * @param {Array<string>} desktopSharingSourceTypes - The types that will be
|
226
|
|
- * fetched and displayed.
|
227
|
|
- * @returns {void}
|
|
208
|
+ * @param {Array<string>} types - The types to filter.
|
|
209
|
+ * @returns {Array<string>} The filtered types.
|
228
|
210
|
*/
|
229
|
|
- _onSourceTypesConfigChanged(desktopSharingSourceTypes = []) {
|
230
|
|
- const tabsToPopulate
|
231
|
|
- = TAB_CONFIGURATIONS.filter(({ type }) =>
|
232
|
|
- desktopSharingSourceTypes.includes(type)
|
233
|
|
- && VALID_TYPES.includes(type));
|
234
|
|
-
|
235
|
|
- this.setState({
|
236
|
|
- tabsToPopulate,
|
237
|
|
- typesToFetch: tabsToPopulate.map(c => c.type)
|
238
|
|
- });
|
|
211
|
+ _getValidTypes(types = []) {
|
|
212
|
+ return types.filter(
|
|
213
|
+ type => VALID_TYPES.includes(type));
|
239
|
214
|
}
|
240
|
215
|
|
241
|
216
|
_onSubmit: () => void;
|
|
@@ -259,18 +234,20 @@ class DesktopPicker extends Component {
|
259
|
234
|
* @returns {ReactElement}
|
260
|
235
|
*/
|
261
|
236
|
_renderTabs() {
|
262
|
|
- const { selectedSource } = this.state;
|
263
|
|
- const { sources, t } = this.props;
|
|
237
|
+ const { selectedSource, sources, types } = this.state;
|
|
238
|
+ const { t } = this.props;
|
264
|
239
|
const tabs
|
265
|
|
- = this.state.tabsToPopulate.map(
|
266
|
|
- ({ defaultSelected, label, type }) => {
|
|
240
|
+ = types.map(
|
|
241
|
+ type => {
|
|
242
|
+ const { defaultSelected, label } = TAB_CONFIGURATIONS[type];
|
|
243
|
+
|
267
|
244
|
return {
|
268
|
245
|
content: <DesktopPickerPane
|
269
|
246
|
key = { type }
|
270
|
247
|
onClick = { this._onPreviewClick }
|
271
|
248
|
onDoubleClick = { this._onCloseModal }
|
272
|
249
|
selectedSourceId = { selectedSource.id }
|
273
|
|
- sources = { sources[type] || [] }
|
|
250
|
+ sources = { sources[type] }
|
274
|
251
|
type = { type } />,
|
275
|
252
|
defaultSelected,
|
276
|
253
|
label: t(label)
|
|
@@ -288,6 +265,7 @@ class DesktopPicker extends Component {
|
288
|
265
|
*/
|
289
|
266
|
_startPolling() {
|
290
|
267
|
this._stopPolling();
|
|
268
|
+ this._updateSources();
|
291
|
269
|
this._poller = window.setInterval(this._updateSources, UPDATE_INTERVAL);
|
292
|
270
|
}
|
293
|
271
|
|
|
@@ -311,28 +289,35 @@ class DesktopPicker extends Component {
|
311
|
289
|
* @returns {void}
|
312
|
290
|
*/
|
313
|
291
|
_updateSources() {
|
314
|
|
- this.props.dispatch(obtainDesktopSources(
|
315
|
|
- this.state.typesToFetch,
|
316
|
|
- {
|
317
|
|
- THUMBNAIL_SIZE
|
318
|
|
- }
|
319
|
|
- ));
|
320
|
|
- }
|
321
|
|
-}
|
|
292
|
+ const { types } = this.state;
|
|
293
|
+
|
|
294
|
+ if (types.length > 0) {
|
|
295
|
+ obtainDesktopSources(
|
|
296
|
+ this.state.types,
|
|
297
|
+ { thumbnailSize: THUMBNAIL_SIZE }
|
|
298
|
+ )
|
|
299
|
+ .then(sources => {
|
|
300
|
+ const nextState: Object = {
|
|
301
|
+ sources
|
|
302
|
+ };
|
|
303
|
+
|
|
304
|
+ // FIXME: selectedSource when screen is disabled, when the
|
|
305
|
+ // source has been removed or when the selectedTab is changed!!!
|
|
306
|
+ if (!this.state.selectedSource.id
|
|
307
|
+ && sources.screen.length > 0) {
|
|
308
|
+ nextState.selectedSource = {
|
|
309
|
+ id: sources.screen[0].id,
|
|
310
|
+ type: 'screen'
|
|
311
|
+ };
|
|
312
|
+ }
|
322
|
313
|
|
323
|
|
-/**
|
324
|
|
- * Maps (parts of) the Redux state to the associated DesktopPicker's props.
|
325
|
|
- *
|
326
|
|
- * @param {Object} state - Redux state.
|
327
|
|
- * @private
|
328
|
|
- * @returns {{
|
329
|
|
- * sources: Object
|
330
|
|
- * }}
|
331
|
|
- */
|
332
|
|
-function _mapStateToProps(state) {
|
333
|
|
- return {
|
334
|
|
- sources: state['features/desktop-picker']
|
335
|
|
- };
|
|
314
|
+ // TODO: Maybe check if we have stopped the timer and unmounted
|
|
315
|
+ // the component.
|
|
316
|
+ this.setState(nextState);
|
|
317
|
+ })
|
|
318
|
+ .catch(() => { /* ignore */ });
|
|
319
|
+ }
|
|
320
|
+ }
|
336
|
321
|
}
|
337
|
322
|
|
338
|
|
-export default translate(connect(_mapStateToProps)(DesktopPicker));
|
|
323
|
+export default translate(connect()(DesktopPicker));
|