|
@@ -1,299 +0,0 @@
|
1
|
|
-/* global JitsiMeetJS */
|
2
|
|
-
|
3
|
|
-import { AtlasKitThemeProvider } from '@atlaskit/theme';
|
4
|
|
-import React from 'react';
|
5
|
|
-import ReactDOM from 'react-dom';
|
6
|
|
-import { I18nextProvider } from 'react-i18next';
|
7
|
|
-
|
8
|
|
-import {
|
9
|
|
- getAvailableDevices,
|
10
|
|
- getCurrentDevices,
|
11
|
|
- isDeviceChangeAvailable,
|
12
|
|
- isDeviceListAvailable,
|
13
|
|
- isMultipleAudioInputSupported,
|
14
|
|
- setAudioInputDevice,
|
15
|
|
- setAudioOutputDevice,
|
16
|
|
- setVideoInputDevice
|
17
|
|
-} from '../../../../../modules/API/external/functions';
|
18
|
|
-import {
|
19
|
|
- PostMessageTransportBackend,
|
20
|
|
- Transport
|
21
|
|
-} from '../../../../../modules/transport';
|
22
|
|
-import DialogWithTabs from '../../../base/dialog/components/web/DialogWithTabs';
|
23
|
|
-import { parseURLParams } from '../../../base/util/parseURLParams';
|
24
|
|
-import DeviceSelection from '../../../device-selection/components/DeviceSelection';
|
25
|
|
-
|
26
|
|
-/**
|
27
|
|
- * Implements a class that renders the React components for the device selection
|
28
|
|
- * popup page and handles the communication between the components and Jitsi
|
29
|
|
- * Meet.
|
30
|
|
- */
|
31
|
|
-export default class DeviceSelectionPopup {
|
32
|
|
- /**
|
33
|
|
- * Initializes a new DeviceSelectionPopup instance.
|
34
|
|
- *
|
35
|
|
- * @param {Object} i18next - The i18next instance used for translation.
|
36
|
|
- */
|
37
|
|
- constructor(i18next) {
|
38
|
|
- this.close = this.close.bind(this);
|
39
|
|
- this._i18next = i18next;
|
40
|
|
- this._onSubmit = this._onSubmit.bind(this);
|
41
|
|
-
|
42
|
|
- const { scope } = parseURLParams(window.location);
|
43
|
|
-
|
44
|
|
- this._transport = new Transport({
|
45
|
|
- backend: new PostMessageTransportBackend({
|
46
|
|
- postisOptions: {
|
47
|
|
- scope,
|
48
|
|
- window: window.opener
|
49
|
|
- }
|
50
|
|
- })
|
51
|
|
- });
|
52
|
|
-
|
53
|
|
- this._transport.on('event', event => {
|
54
|
|
- if (event.name === 'deviceListChanged') {
|
55
|
|
- this._updateAvailableDevices();
|
56
|
|
-
|
57
|
|
- return true;
|
58
|
|
- }
|
59
|
|
-
|
60
|
|
- return false;
|
61
|
|
- });
|
62
|
|
-
|
63
|
|
- this._dialogProps = {
|
64
|
|
- availableDevices: {},
|
65
|
|
- selectedAudioInputId: '',
|
66
|
|
- selectedAudioOutputId: '',
|
67
|
|
- selectedVideoInputId: '',
|
68
|
|
- disableAudioInputChange: true,
|
69
|
|
- disableBlanketClickDismiss: true,
|
70
|
|
- disableDeviceChange: true,
|
71
|
|
- hideAudioInputPreview: !JitsiMeetJS.isCollectingLocalStats(),
|
72
|
|
- hideAudioOutputSelect: true
|
73
|
|
-
|
74
|
|
- };
|
75
|
|
- this._initState();
|
76
|
|
- }
|
77
|
|
-
|
78
|
|
- /**
|
79
|
|
- * Sends event to Jitsi Meet to close the popup dialog.
|
80
|
|
- *
|
81
|
|
- * @returns {void}
|
82
|
|
- */
|
83
|
|
- close() {
|
84
|
|
- this._transport.sendEvent({
|
85
|
|
- type: 'devices-dialog',
|
86
|
|
- name: 'close'
|
87
|
|
- });
|
88
|
|
- }
|
89
|
|
-
|
90
|
|
- /**
|
91
|
|
- * Changes the properties of the react component and re-renders it.
|
92
|
|
- *
|
93
|
|
- * @param {Object} newProps - The new properties that will be assigned to
|
94
|
|
- * the current ones.
|
95
|
|
- * @returns {void}
|
96
|
|
- */
|
97
|
|
- _changeDialogProps(newProps) {
|
98
|
|
- this._dialogProps = {
|
99
|
|
- ...this._dialogProps,
|
100
|
|
- ...newProps
|
101
|
|
- };
|
102
|
|
- this._render();
|
103
|
|
- }
|
104
|
|
-
|
105
|
|
- /**
|
106
|
|
- * Returns Promise that resolves with result an list of available devices.
|
107
|
|
- *
|
108
|
|
- * @returns {Promise}
|
109
|
|
- */
|
110
|
|
- _getAvailableDevices() {
|
111
|
|
- return getAvailableDevices(this._transport);
|
112
|
|
- }
|
113
|
|
-
|
114
|
|
- /**
|
115
|
|
- * Returns Promise that resolves with current selected devices.
|
116
|
|
- *
|
117
|
|
- * @returns {Promise}
|
118
|
|
- */
|
119
|
|
- _getCurrentDevices() {
|
120
|
|
- return getCurrentDevices(this._transport).then(currentDevices => {
|
121
|
|
- const {
|
122
|
|
- audioInput = {},
|
123
|
|
- audioOutput = {},
|
124
|
|
- videoInput = {}
|
125
|
|
- } = currentDevices;
|
126
|
|
-
|
127
|
|
- return {
|
128
|
|
- audioInput: audioInput.deviceId,
|
129
|
|
- audioOutput: audioOutput.deviceId,
|
130
|
|
- videoInput: videoInput.deviceId
|
131
|
|
- };
|
132
|
|
- });
|
133
|
|
- }
|
134
|
|
-
|
135
|
|
- /**
|
136
|
|
- * Initializes the state.
|
137
|
|
- *
|
138
|
|
- * @returns {void}
|
139
|
|
- */
|
140
|
|
- _initState() {
|
141
|
|
- return Promise.all([
|
142
|
|
- this._getAvailableDevices(),
|
143
|
|
- this._isDeviceListAvailable(),
|
144
|
|
- this._isDeviceChangeAvailable(),
|
145
|
|
- this._isDeviceChangeAvailable('output'),
|
146
|
|
- this._getCurrentDevices(),
|
147
|
|
- this._isMultipleAudioInputSupported()
|
148
|
|
- ]).then(([
|
149
|
|
- availableDevices,
|
150
|
|
- listAvailable,
|
151
|
|
- changeAvailable,
|
152
|
|
- changeOutputAvailable,
|
153
|
|
- currentDevices,
|
154
|
|
- multiAudioInputSupported
|
155
|
|
- ]) => {
|
156
|
|
- this._changeDialogProps({
|
157
|
|
- availableDevices,
|
158
|
|
- selectedAudioInputId: currentDevices.audioInput,
|
159
|
|
- selectedAudioOutputId: currentDevices.audioOutput,
|
160
|
|
- selectedVideoInputId: currentDevices.videoInput,
|
161
|
|
- disableAudioInputChange: !multiAudioInputSupported,
|
162
|
|
- disableDeviceChange: !listAvailable || !changeAvailable,
|
163
|
|
- hideAudioOutputSelect: !changeOutputAvailable
|
164
|
|
- });
|
165
|
|
- });
|
166
|
|
- }
|
167
|
|
-
|
168
|
|
- /**
|
169
|
|
- * Returns Promise that resolves with true if the device change is available
|
170
|
|
- * and with false if not.
|
171
|
|
- *
|
172
|
|
- * @param {string} [deviceType] - Values - 'output', 'input' or undefined.
|
173
|
|
- * Default - 'input'.
|
174
|
|
- * @returns {Promise}
|
175
|
|
- */
|
176
|
|
- _isDeviceChangeAvailable(deviceType) {
|
177
|
|
- return isDeviceChangeAvailable(this._transport, deviceType).catch(() => false);
|
178
|
|
- }
|
179
|
|
-
|
180
|
|
- /**
|
181
|
|
- * Returns Promise that resolves with true if the device list is available
|
182
|
|
- * and with false if not.
|
183
|
|
- *
|
184
|
|
- * @returns {Promise}
|
185
|
|
- */
|
186
|
|
- _isDeviceListAvailable() {
|
187
|
|
- return isDeviceListAvailable(this._transport).catch(() => false);
|
188
|
|
- }
|
189
|
|
-
|
190
|
|
- /**
|
191
|
|
- * Returns Promise that resolves with true if multiple audio input is supported
|
192
|
|
- * and with false if not.
|
193
|
|
- *
|
194
|
|
- * @returns {Promise}
|
195
|
|
- */
|
196
|
|
- _isMultipleAudioInputSupported() {
|
197
|
|
- return isMultipleAudioInputSupported(this._transport).catch(() => false);
|
198
|
|
- }
|
199
|
|
-
|
200
|
|
- /**
|
201
|
|
- * Callback invoked to save changes to selected devices and close the
|
202
|
|
- * dialog.
|
203
|
|
- *
|
204
|
|
- * @param {Object} newSettings - The chosen device IDs.
|
205
|
|
- * @private
|
206
|
|
- * @returns {void}
|
207
|
|
- */
|
208
|
|
- _onSubmit(newSettings) {
|
209
|
|
- const promises = [];
|
210
|
|
-
|
211
|
|
- if (newSettings.selectedVideoInputId
|
212
|
|
- !== this._dialogProps.selectedVideoInputId) {
|
213
|
|
- promises.push(
|
214
|
|
- this._setVideoInputDevice(newSettings.selectedVideoInputId));
|
215
|
|
- }
|
216
|
|
-
|
217
|
|
- if (newSettings.selectedAudioInputId
|
218
|
|
- !== this._dialogProps.selectedAudioInputId) {
|
219
|
|
- promises.push(
|
220
|
|
- this._setAudioInputDevice(newSettings.selectedAudioInputId));
|
221
|
|
- }
|
222
|
|
-
|
223
|
|
- if (newSettings.selectedAudioOutputId
|
224
|
|
- !== this._dialogProps.selectedAudioOutputId) {
|
225
|
|
- promises.push(
|
226
|
|
- this._setAudioOutputDevice(newSettings.selectedAudioOutputId));
|
227
|
|
- }
|
228
|
|
-
|
229
|
|
- Promise.all(promises).then(this.close, this.close);
|
230
|
|
- }
|
231
|
|
-
|
232
|
|
- /**
|
233
|
|
- * Renders the React components for the popup page.
|
234
|
|
- *
|
235
|
|
- * @returns {void}
|
236
|
|
- */
|
237
|
|
- _render() {
|
238
|
|
- const onSubmit = this.close;
|
239
|
|
-
|
240
|
|
- ReactDOM.render(
|
241
|
|
- <I18nextProvider i18n = { this._i18next }>
|
242
|
|
- <AtlasKitThemeProvider mode = 'dark'>
|
243
|
|
- <DialogWithTabs
|
244
|
|
- closeDialog = { this.close }
|
245
|
|
- cssClassName = 'settings-dialog'
|
246
|
|
- onSubmit = { onSubmit }
|
247
|
|
- tabs = { [ {
|
248
|
|
- component: DeviceSelection,
|
249
|
|
- label: 'settings.devices',
|
250
|
|
- props: this._dialogProps,
|
251
|
|
- submit: this._onSubmit
|
252
|
|
- } ] }
|
253
|
|
- titleKey = 'settings.title' />
|
254
|
|
- </AtlasKitThemeProvider>
|
255
|
|
- </I18nextProvider>,
|
256
|
|
- document.getElementById('react'));
|
257
|
|
- }
|
258
|
|
-
|
259
|
|
- /**
|
260
|
|
- * Sets the audio input device to the one with the id that is passed.
|
261
|
|
- *
|
262
|
|
- * @param {string} id - The id of the new device.
|
263
|
|
- * @returns {Promise}
|
264
|
|
- */
|
265
|
|
- _setAudioInputDevice(id) {
|
266
|
|
- return setAudioInputDevice(this._transport, undefined, id);
|
267
|
|
- }
|
268
|
|
-
|
269
|
|
- /**
|
270
|
|
- * Sets the audio output device to the one with the id that is passed.
|
271
|
|
- *
|
272
|
|
- * @param {string} id - The id of the new device.
|
273
|
|
- * @returns {Promise}
|
274
|
|
- */
|
275
|
|
- _setAudioOutputDevice(id) {
|
276
|
|
- return setAudioOutputDevice(this._transport, undefined, id);
|
277
|
|
- }
|
278
|
|
-
|
279
|
|
- /**
|
280
|
|
- * Sets the video input device to the one with the id that is passed.
|
281
|
|
- *
|
282
|
|
- * @param {string} id - The id of the new device.
|
283
|
|
- * @returns {Promise}
|
284
|
|
- */
|
285
|
|
- _setVideoInputDevice(id) {
|
286
|
|
- return setVideoInputDevice(this._transport, undefined, id);
|
287
|
|
- }
|
288
|
|
-
|
289
|
|
- /**
|
290
|
|
- * Updates the available devices.
|
291
|
|
- *
|
292
|
|
- * @returns {void}
|
293
|
|
- */
|
294
|
|
- _updateAvailableDevices() {
|
295
|
|
- this._getAvailableDevices().then(devices =>
|
296
|
|
- this._changeDialogProps({ availableDevices: devices })
|
297
|
|
- );
|
298
|
|
- }
|
299
|
|
-}
|