|
@@ -1,5 +1,3 @@
|
1
|
|
-/* global config */
|
2
|
|
-
|
3
|
1
|
import Tabs from '@atlaskit/tabs';
|
4
|
2
|
import React, { Component } from 'react';
|
5
|
3
|
import { connect } from 'react-redux';
|
|
@@ -33,12 +31,7 @@ const TAB_CONFIGURATIONS = [
|
33
|
31
|
type: 'window'
|
34
|
32
|
}
|
35
|
33
|
];
|
36
|
|
-const CONFIGURED_TYPES = config.desktopSharingChromeSources || [];
|
37
|
34
|
const VALID_TYPES = TAB_CONFIGURATIONS.map(c => c.type);
|
38
|
|
-const TABS_TO_POPULATE
|
39
|
|
- = TAB_CONFIGURATIONS.filter(
|
40
|
|
- c => CONFIGURED_TYPES.includes(c.type) && VALID_TYPES.includes(c.type));
|
41
|
|
-const TYPES_TO_FETCH = TABS_TO_POPULATE.map(c => c.type);
|
42
|
35
|
|
43
|
36
|
/**
|
44
|
37
|
* React component for DesktopPicker.
|
|
@@ -63,6 +56,11 @@ class DesktopPicker extends Component {
|
63
|
56
|
*/
|
64
|
57
|
onSourceChoose: React.PropTypes.func,
|
65
|
58
|
|
|
59
|
+ /**
|
|
60
|
+ * An object with options related to desktop sharing.
|
|
61
|
+ */
|
|
62
|
+ options: React.PropTypes.object,
|
|
63
|
+
|
66
|
64
|
/**
|
67
|
65
|
* An object with arrays of DesktopCapturerSources. The key should be
|
68
|
66
|
* the source type.
|
|
@@ -85,7 +83,9 @@ class DesktopPicker extends Component {
|
85
|
83
|
super(props);
|
86
|
84
|
|
87
|
85
|
this.state = {
|
88
|
|
- selectedSourceId: ''
|
|
86
|
+ selectedSource: {},
|
|
87
|
+ tabsToPopulate: [],
|
|
88
|
+ typesToFetch: []
|
89
|
89
|
};
|
90
|
90
|
|
91
|
91
|
this._poller = null;
|
|
@@ -102,6 +102,10 @@ class DesktopPicker extends Component {
|
102
|
102
|
* @inheritdoc
|
103
|
103
|
*/
|
104
|
104
|
componentWillMount() {
|
|
105
|
+ const options = this.props.options || {};
|
|
106
|
+
|
|
107
|
+ this._onSourceTypesConfigChanged(
|
|
108
|
+ options.desktopSharingSources);
|
105
|
109
|
this._updateSources();
|
106
|
110
|
this._startPolling();
|
107
|
111
|
}
|
|
@@ -116,12 +120,20 @@ class DesktopPicker extends Component {
|
116
|
120
|
* @returns {void}
|
117
|
121
|
*/
|
118
|
122
|
componentWillReceiveProps(nextProps) {
|
119
|
|
- if (!this.state.selectedSourceId
|
|
123
|
+ if (!this.state.selectedSource.id
|
120
|
124
|
&& nextProps.sources.screen.length) {
|
121
|
125
|
this.setState({
|
122
|
|
- selectedSourceId: nextProps.sources.screen[0].id
|
|
126
|
+ selectedSource: {
|
|
127
|
+ id: nextProps.sources.screen[0].id,
|
|
128
|
+ type: 'screen'
|
|
129
|
+ }
|
123
|
130
|
});
|
124
|
131
|
}
|
|
132
|
+
|
|
133
|
+ const options = this.props.options || {};
|
|
134
|
+
|
|
135
|
+ this._onSourceTypesConfigChanged(
|
|
136
|
+ options.desktopSharingSources);
|
125
|
137
|
}
|
126
|
138
|
|
127
|
139
|
/**
|
|
@@ -155,14 +167,16 @@ class DesktopPicker extends Component {
|
155
|
167
|
|
156
|
168
|
/**
|
157
|
169
|
* Dispatches an action to hide the DesktopPicker and invokes the passed in
|
158
|
|
- * callback with a selectedSourceId, if any.
|
|
170
|
+ * callback with a selectedSource, if any.
|
159
|
171
|
*
|
160
|
172
|
* @param {string} id - The id of the DesktopCapturerSource to pass into the
|
161
|
173
|
* onSourceChoose callback.
|
|
174
|
+ * @param {string} type - The type of the DesktopCapturerSource to pass into
|
|
175
|
+ * the onSourceChoose callback.
|
162
|
176
|
* @returns {void}
|
163
|
177
|
*/
|
164
|
|
- _onCloseModal(id = '') {
|
165
|
|
- this.props.onSourceChoose(id);
|
|
178
|
+ _onCloseModal(id = '', type) {
|
|
179
|
+ this.props.onSourceChoose(id, type);
|
166
|
180
|
this.props.dispatch(hideDialog());
|
167
|
181
|
}
|
168
|
182
|
|
|
@@ -170,10 +184,16 @@ class DesktopPicker extends Component {
|
170
|
184
|
* Sets the currently selected DesktopCapturerSource.
|
171
|
185
|
*
|
172
|
186
|
* @param {string} id - The id of DesktopCapturerSource.
|
|
187
|
+ * @param {string} type - The type of DesktopCapturerSource.
|
173
|
188
|
* @returns {void}
|
174
|
189
|
*/
|
175
|
|
- _onPreviewClick(id) {
|
176
|
|
- this.setState({ selectedSourceId: id });
|
|
190
|
+ _onPreviewClick(id, type) {
|
|
191
|
+ this.setState({
|
|
192
|
+ selectedSource: {
|
|
193
|
+ id,
|
|
194
|
+ type
|
|
195
|
+ }
|
|
196
|
+ });
|
177
|
197
|
}
|
178
|
198
|
|
179
|
199
|
/**
|
|
@@ -183,7 +203,9 @@ class DesktopPicker extends Component {
|
183
|
203
|
* @returns {void}
|
184
|
204
|
*/
|
185
|
205
|
_onSubmit() {
|
186
|
|
- this._onCloseModal(this.state.selectedSourceId);
|
|
206
|
+ const { id, type } = this.state.selectedSource;
|
|
207
|
+
|
|
208
|
+ this._onCloseModal(id, type);
|
187
|
209
|
}
|
188
|
210
|
|
189
|
211
|
/**
|
|
@@ -193,22 +215,23 @@ class DesktopPicker extends Component {
|
193
|
215
|
* @returns {ReactElement}
|
194
|
216
|
*/
|
195
|
217
|
_renderTabs() {
|
196
|
|
- const { selectedSourceId } = this.state;
|
|
218
|
+ const { selectedSource } = this.state;
|
197
|
219
|
const { sources, t } = this.props;
|
198
|
220
|
const tabs
|
199
|
|
- = TABS_TO_POPULATE.map(({ defaultSelected, label, type }) => {
|
200
|
|
- return {
|
201
|
|
- content: <DesktopPickerPane
|
202
|
|
- key = { type }
|
203
|
|
- onClick = { this._onPreviewClick }
|
204
|
|
- onDoubleClick = { this._onCloseModal }
|
205
|
|
- selectedSourceId = { selectedSourceId }
|
206
|
|
- sources = { sources[type] || [] }
|
207
|
|
- type = { type } />,
|
208
|
|
- defaultSelected,
|
209
|
|
- label: t(label)
|
210
|
|
- };
|
211
|
|
- });
|
|
221
|
+ = this.state.tabsToPopulate.map(
|
|
222
|
+ ({ defaultSelected, label, type }) => {
|
|
223
|
+ return {
|
|
224
|
+ content: <DesktopPickerPane
|
|
225
|
+ key = { type }
|
|
226
|
+ onClick = { this._onPreviewClick }
|
|
227
|
+ onDoubleClick = { this._onCloseModal }
|
|
228
|
+ selectedSourceId = { selectedSource.id }
|
|
229
|
+ sources = { sources[type] || [] }
|
|
230
|
+ type = { type } />,
|
|
231
|
+ defaultSelected,
|
|
232
|
+ label: t(label)
|
|
233
|
+ };
|
|
234
|
+ });
|
212
|
235
|
|
213
|
236
|
return <Tabs tabs = { tabs } />;
|
214
|
237
|
}
|
|
@@ -235,6 +258,25 @@ class DesktopPicker extends Component {
|
235
|
258
|
this._poller = null;
|
236
|
259
|
}
|
237
|
260
|
|
|
261
|
+ /**
|
|
262
|
+ * Handles changing of allowed desktop sharing source types.
|
|
263
|
+ *
|
|
264
|
+ * @param {Array<string>} desktopSharingSourceTypes - The types that will be
|
|
265
|
+ * fetched and displayed.
|
|
266
|
+ * @returns {void}
|
|
267
|
+ */
|
|
268
|
+ _onSourceTypesConfigChanged(desktopSharingSourceTypes = []) {
|
|
269
|
+ const tabsToPopulate = TAB_CONFIGURATIONS.filter(
|
|
270
|
+ c => desktopSharingSourceTypes.includes(c.type)
|
|
271
|
+ && VALID_TYPES.includes(c.type)
|
|
272
|
+ );
|
|
273
|
+
|
|
274
|
+ this.setState({
|
|
275
|
+ tabsToPopulate,
|
|
276
|
+ typesToFetch: tabsToPopulate.map(c => c.type)
|
|
277
|
+ });
|
|
278
|
+ }
|
|
279
|
+
|
238
|
280
|
/**
|
239
|
281
|
* Dispatches an action to get currently available DesktopCapturerSources.
|
240
|
282
|
*
|
|
@@ -243,7 +285,7 @@ class DesktopPicker extends Component {
|
243
|
285
|
*/
|
244
|
286
|
_updateSources() {
|
245
|
287
|
this.props.dispatch(obtainDesktopSources(
|
246
|
|
- TYPES_TO_FETCH,
|
|
288
|
+ this.state.typesToFetch,
|
247
|
289
|
{
|
248
|
290
|
THUMBNAIL_SIZE
|
249
|
291
|
}
|