|
@@ -6,37 +6,39 @@ import { connect } from 'react-redux';
|
6
|
6
|
|
7
|
7
|
import { Dialog, hideDialog } from '../../base/dialog';
|
8
|
8
|
import { translate } from '../../base/i18n';
|
9
|
|
-import {
|
10
|
|
- resetDesktopSources,
|
11
|
|
- obtainDesktopSources
|
12
|
|
-} from '../actions';
|
|
9
|
+
|
|
10
|
+import { obtainDesktopSources, resetDesktopSources } from '../actions';
|
13
|
11
|
import DesktopPickerPane from './DesktopPickerPane';
|
14
|
12
|
|
15
|
|
-const updateInterval = 1000;
|
16
|
|
-const thumbnailSize = {
|
|
13
|
+const THUMBNAIL_SIZE = {
|
17
|
14
|
height: 300,
|
18
|
15
|
width: 300
|
19
|
16
|
};
|
20
|
|
-const tabConfigurations = [
|
|
17
|
+const UPDATE_INTERVAL = 1000;
|
|
18
|
+
|
|
19
|
+const TAB_CONFIGURATIONS = [
|
21
|
20
|
{
|
|
21
|
+ /**
|
|
22
|
+ * The indicator which determines whether this tab configuration is
|
|
23
|
+ * selected by default.
|
|
24
|
+ *
|
|
25
|
+ * @type {boolean}
|
|
26
|
+ */
|
|
27
|
+ defaultSelected: true,
|
22
|
28
|
label: 'dialog.yourEntireScreen',
|
23
|
|
- type: 'screen',
|
24
|
|
- isDefault: true
|
|
29
|
+ type: 'screen'
|
25
|
30
|
},
|
26
|
31
|
{
|
27
|
32
|
label: 'dialog.applicationWindow',
|
28
|
33
|
type: 'window'
|
29
|
34
|
}
|
30
|
35
|
];
|
31
|
|
-
|
32
|
|
-const validTypes = tabConfigurations.map(configuration => configuration.type);
|
33
|
|
-const configuredTypes = config.desktopSharingChromeSources || [];
|
34
|
|
-
|
35
|
|
-const tabsToPopulate = tabConfigurations.filter(configuration =>
|
36
|
|
- configuredTypes.includes(configuration.type)
|
37
|
|
- && validTypes.includes(configuration.type)
|
38
|
|
-);
|
39
|
|
-const typesToFetch = tabsToPopulate.map(configuration => configuration.type);
|
|
36
|
+const CONFIGURED_TYPES = config.desktopSharingChromeSources || [];
|
|
37
|
+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);
|
40
|
42
|
|
41
|
43
|
/**
|
42
|
44
|
* React component for DesktopPicker.
|
|
@@ -56,14 +58,14 @@ class DesktopPicker extends Component {
|
56
|
58
|
dispatch: React.PropTypes.func,
|
57
|
59
|
|
58
|
60
|
/**
|
59
|
|
- * The callback to be invoked when the component is closed or
|
60
|
|
- * when a DesktopCapturerSource has been chosen.
|
|
61
|
+ * The callback to be invoked when the component is closed or when
|
|
62
|
+ * a DesktopCapturerSource has been chosen.
|
61
|
63
|
*/
|
62
|
64
|
onSourceChoose: React.PropTypes.func,
|
63
|
65
|
|
64
|
66
|
/**
|
65
|
|
- * An object with arrays of DesktopCapturerSources. The key
|
66
|
|
- * should be the source type.
|
|
67
|
+ * An object with arrays of DesktopCapturerSources. The key should be
|
|
68
|
+ * the source type.
|
67
|
69
|
*/
|
68
|
70
|
sources: React.PropTypes.object,
|
69
|
71
|
|
|
@@ -94,8 +96,8 @@ class DesktopPicker extends Component {
|
94
|
96
|
}
|
95
|
97
|
|
96
|
98
|
/**
|
97
|
|
- * Perform an immediate update request for DesktopCapturerSources and
|
98
|
|
- * begin requesting updates at an interval.
|
|
99
|
+ * Perform an immediate update request for DesktopCapturerSources and begin
|
|
100
|
+ * requesting updates at an interval.
|
99
|
101
|
*
|
100
|
102
|
* @inheritdoc
|
101
|
103
|
*/
|
|
@@ -104,16 +106,6 @@ class DesktopPicker extends Component {
|
104
|
106
|
this._startPolling();
|
105
|
107
|
}
|
106
|
108
|
|
107
|
|
- /**
|
108
|
|
- * Clean up component and DesktopCapturerSource store state.
|
109
|
|
- *
|
110
|
|
- * @inheritdoc
|
111
|
|
- */
|
112
|
|
- componentWillUnmount() {
|
113
|
|
- this._stopPolling();
|
114
|
|
- this.props.dispatch(resetDesktopSources());
|
115
|
|
- }
|
116
|
|
-
|
117
|
109
|
/**
|
118
|
110
|
* Notifies this mounted React Component that it will receive new props.
|
119
|
111
|
* Sets a default selected source if one is not already set.
|
|
@@ -125,11 +117,23 @@ class DesktopPicker extends Component {
|
125
|
117
|
*/
|
126
|
118
|
componentWillReceiveProps(nextProps) {
|
127
|
119
|
if (!this.state.selectedSourceId
|
128
|
|
- && nextProps.sources.screen.length) {
|
129
|
|
- this.setState({ selectedSourceId: nextProps.sources.screen[0].id });
|
|
120
|
+ && nextProps.sources.screen.length) {
|
|
121
|
+ this.setState({
|
|
122
|
+ selectedSourceId: nextProps.sources.screen[0].id
|
|
123
|
+ });
|
130
|
124
|
}
|
131
|
125
|
}
|
132
|
126
|
|
|
127
|
+ /**
|
|
128
|
+ * Clean up component and DesktopCapturerSource store state.
|
|
129
|
+ *
|
|
130
|
+ * @inheritdoc
|
|
131
|
+ */
|
|
132
|
+ componentWillUnmount() {
|
|
133
|
+ this._stopPolling();
|
|
134
|
+ this.props.dispatch(resetDesktopSources());
|
|
135
|
+ }
|
|
136
|
+
|
133
|
137
|
/**
|
134
|
138
|
* Implements React's {@link Component#render()}.
|
135
|
139
|
*
|
|
@@ -145,104 +149,105 @@ class DesktopPicker extends Component {
|
145
|
149
|
titleKey = 'dialog.shareYourScreen'
|
146
|
150
|
width = 'medium' >
|
147
|
151
|
{ this._renderTabs() }
|
148
|
|
- </Dialog>);
|
|
152
|
+ </Dialog>
|
|
153
|
+ );
|
149
|
154
|
}
|
150
|
155
|
|
151
|
156
|
/**
|
152
|
|
- * Dispatches an action to get currently available DesktopCapturerSources.
|
|
157
|
+ * Dispatches an action to hide the DesktopPicker and invokes the passed in
|
|
158
|
+ * callback with a selectedSourceId, if any.
|
153
|
159
|
*
|
154
|
|
- * @private
|
|
160
|
+ * @param {string} id - The id of the DesktopCapturerSource to pass into the
|
|
161
|
+ * onSourceChoose callback.
|
155
|
162
|
* @returns {void}
|
156
|
163
|
*/
|
157
|
|
- _updateSources() {
|
158
|
|
- this.props.dispatch(obtainDesktopSources(
|
159
|
|
- typesToFetch,
|
160
|
|
- {
|
161
|
|
- thumbnailSize
|
162
|
|
- }
|
163
|
|
- ));
|
|
164
|
+ _onCloseModal(id = '') {
|
|
165
|
+ this.props.onSourceChoose(id);
|
|
166
|
+ this.props.dispatch(hideDialog());
|
164
|
167
|
}
|
165
|
168
|
|
166
|
169
|
/**
|
167
|
|
- * Create an interval to update knwon available DesktopCapturerSources.
|
|
170
|
+ * Sets the currently selected DesktopCapturerSource.
|
168
|
171
|
*
|
169
|
|
- * @private
|
|
172
|
+ * @param {string} id - The id of DesktopCapturerSource.
|
170
|
173
|
* @returns {void}
|
171
|
174
|
*/
|
172
|
|
- _startPolling() {
|
173
|
|
- this._stopPolling();
|
174
|
|
- this._poller = window.setInterval(this._updateSources,
|
175
|
|
- updateInterval);
|
|
175
|
+ _onPreviewClick(id) {
|
|
176
|
+ this.setState({ selectedSourceId: id });
|
176
|
177
|
}
|
177
|
178
|
|
178
|
179
|
/**
|
179
|
|
- * Cancels the interval to update DesktopCapturerSources.
|
|
180
|
+ * Request to close the modal and execute callbacks with the selected source
|
|
181
|
+ * id.
|
180
|
182
|
*
|
181
|
|
- * @private
|
182
|
183
|
* @returns {void}
|
183
|
184
|
*/
|
184
|
|
- _stopPolling() {
|
185
|
|
- window.clearInterval(this._poller);
|
186
|
|
- this._poller = null;
|
|
185
|
+ _onSubmit() {
|
|
186
|
+ this._onCloseModal(this.state.selectedSourceId);
|
187
|
187
|
}
|
188
|
188
|
|
189
|
189
|
/**
|
190
|
|
- * Sets the currently selected DesktopCapturerSource.
|
|
190
|
+ * Configures and renders the tabs for display.
|
191
|
191
|
*
|
192
|
|
- * @param {string} id - The id of DesktopCapturerSource.
|
193
|
|
- * @returns {void}
|
|
192
|
+ * @private
|
|
193
|
+ * @returns {ReactElement}
|
194
|
194
|
*/
|
195
|
|
- _onPreviewClick(id) {
|
196
|
|
- this.setState({ selectedSourceId: id });
|
|
195
|
+ _renderTabs() {
|
|
196
|
+ const { selectedSourceId } = this.state;
|
|
197
|
+ const { sources, t } = this.props;
|
|
198
|
+ 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
|
+ });
|
|
212
|
+
|
|
213
|
+ return <Tabs tabs = { tabs } />;
|
197
|
214
|
}
|
198
|
215
|
|
199
|
216
|
/**
|
200
|
|
- * Request to close the modal and execute callbacks
|
201
|
|
- * with the selected source id.
|
|
217
|
+ * Create an interval to update knwon available DesktopCapturerSources.
|
202
|
218
|
*
|
|
219
|
+ * @private
|
203
|
220
|
* @returns {void}
|
204
|
221
|
*/
|
205
|
|
- _onSubmit() {
|
206
|
|
- this._onCloseModal(this.state.selectedSourceId);
|
|
222
|
+ _startPolling() {
|
|
223
|
+ this._stopPolling();
|
|
224
|
+ this._poller = window.setInterval(this._updateSources, UPDATE_INTERVAL);
|
207
|
225
|
}
|
208
|
226
|
|
209
|
227
|
/**
|
210
|
|
- * Dispatches an action to hide the DesktopPicker and invokes
|
211
|
|
- * the passed in callback with a selectedSourceId, if any.
|
|
228
|
+ * Cancels the interval to update DesktopCapturerSources.
|
212
|
229
|
*
|
213
|
|
- * @param {string} id - The id of the DesktopCapturerSource to pass into
|
214
|
|
- * the onSourceChoose callback.
|
|
230
|
+ * @private
|
215
|
231
|
* @returns {void}
|
216
|
232
|
*/
|
217
|
|
- _onCloseModal(id = '') {
|
218
|
|
- this.props.onSourceChoose(id);
|
219
|
|
- this.props.dispatch(hideDialog());
|
|
233
|
+ _stopPolling() {
|
|
234
|
+ window.clearInterval(this._poller);
|
|
235
|
+ this._poller = null;
|
220
|
236
|
}
|
221
|
237
|
|
222
|
238
|
/**
|
223
|
|
- * Configures and renders the tabs for display.
|
|
239
|
+ * Dispatches an action to get currently available DesktopCapturerSources.
|
224
|
240
|
*
|
225
|
|
- * @returns {ReactElement}
|
226
|
241
|
* @private
|
|
242
|
+ * @returns {void}
|
227
|
243
|
*/
|
228
|
|
- _renderTabs() {
|
229
|
|
- const tabs = tabsToPopulate.map(tabConfig => {
|
230
|
|
- const type = tabConfig.type;
|
231
|
|
-
|
232
|
|
- return {
|
233
|
|
- label: this.props.t(tabConfig.label),
|
234
|
|
- defaultSelected: tabConfig.isDefault,
|
235
|
|
- content: <DesktopPickerPane
|
236
|
|
- key = { type }
|
237
|
|
- onClick = { this._onPreviewClick }
|
238
|
|
- onDoubleClick = { this._onCloseModal }
|
239
|
|
- selectedSourceId = { this.state.selectedSourceId }
|
240
|
|
- sources = { this.props.sources[type] || [] }
|
241
|
|
- type = { type } />
|
242
|
|
- };
|
243
|
|
- });
|
244
|
|
-
|
245
|
|
- return <Tabs tabs = { tabs } />;
|
|
244
|
+ _updateSources() {
|
|
245
|
+ this.props.dispatch(obtainDesktopSources(
|
|
246
|
+ TYPES_TO_FETCH,
|
|
247
|
+ {
|
|
248
|
+ THUMBNAIL_SIZE
|
|
249
|
+ }
|
|
250
|
+ ));
|
246
|
251
|
}
|
247
|
252
|
}
|
248
|
253
|
|
|
@@ -250,15 +255,15 @@ class DesktopPicker extends Component {
|
250
|
255
|
* Maps (parts of) the Redux state to the associated DesktopPicker's props.
|
251
|
256
|
*
|
252
|
257
|
* @param {Object} state - Redux state.
|
253
|
|
- * @protected
|
|
258
|
+ * @private
|
254
|
259
|
* @returns {{
|
255
|
260
|
* sources: Object
|
256
|
261
|
* }}
|
257
|
262
|
*/
|
258
|
|
-function mapStateToProps(state) {
|
|
263
|
+function _mapStateToProps(state) {
|
259
|
264
|
return {
|
260
|
|
- sources: state['features/desktop-picker/sources']
|
|
265
|
+ sources: state['features/desktop-picker']
|
261
|
266
|
};
|
262
|
267
|
}
|
263
|
268
|
|
264
|
|
-export default translate(connect(mapStateToProps)(DesktopPicker));
|
|
269
|
+export default translate(connect(_mapStateToProps)(DesktopPicker));
|