|
@@ -0,0 +1,276 @@
|
|
1
|
+// @flow
|
|
2
|
+import React, { PureComponent } from 'react';
|
|
3
|
+import { connect } from '../../base/redux';
|
|
4
|
+import { Icon, IconClose } from '../../base/icons';
|
|
5
|
+import { translate } from '../../base/i18n';
|
|
6
|
+import { getCurrentConference } from '../../base/conference/functions';
|
|
7
|
+
|
|
8
|
+/**
|
|
9
|
+ * Local storage key name for flag telling if user checked 'Don't show again' checkbox on the banner
|
|
10
|
+ * If the user checks this before closing the banner, next time he will access a jitsi domain
|
|
11
|
+ * the banner will not be shown regardless of extensions being installed or not.
|
|
12
|
+ */
|
|
13
|
+const DONT_SHOW_AGAIN_CHECKED = 'hide_chrome_extension_banner';
|
|
14
|
+
|
|
15
|
+/**
|
|
16
|
+ * The type of the React {@code PureComponent} props of {@link ChromeExtensionBanner}.
|
|
17
|
+ */
|
|
18
|
+type Props = {
|
|
19
|
+
|
|
20
|
+ /**
|
|
21
|
+ * Conference data, if any
|
|
22
|
+ */
|
|
23
|
+ conference: Object,
|
|
24
|
+
|
|
25
|
+ /**
|
|
26
|
+ * The url of the chrome extension
|
|
27
|
+ */
|
|
28
|
+ chromeExtensionUrl: string,
|
|
29
|
+
|
|
30
|
+ /**
|
|
31
|
+ * An array containing info for identifying a chrome extension
|
|
32
|
+ */
|
|
33
|
+ chromeExtensionsInfo: Array<Object>,
|
|
34
|
+
|
|
35
|
+ /**
|
|
36
|
+ * Invoked to obtain translated strings.
|
|
37
|
+ */
|
|
38
|
+ t: Function,
|
|
39
|
+};
|
|
40
|
+
|
|
41
|
+/**
|
|
42
|
+ * The type of the React {@link PureComponent} state of {@link ChromeExtensionBanner}.
|
|
43
|
+ */
|
|
44
|
+type State = {
|
|
45
|
+
|
|
46
|
+ /**
|
|
47
|
+ * Keeps the current value of dont show again checkbox
|
|
48
|
+ */
|
|
49
|
+ dontShowAgainChecked: boolean,
|
|
50
|
+
|
|
51
|
+ /**
|
|
52
|
+ * Tells whether user pressed install extension or close button.
|
|
53
|
+ */
|
|
54
|
+ closePressed: boolean,
|
|
55
|
+
|
|
56
|
+ /**
|
|
57
|
+ * Tells whether should show the banner or not based on extension being installed or not.
|
|
58
|
+ */
|
|
59
|
+ shouldShow: boolean,
|
|
60
|
+};
|
|
61
|
+
|
|
62
|
+/**
|
|
63
|
+ * Implements a React {@link PureComponent} which displays a banner having a link to the chrome extension.
|
|
64
|
+ * @class ChromeExtensionBanner
|
|
65
|
+ * @extends PureComponent
|
|
66
|
+ */
|
|
67
|
+class ChromeExtensionBanner extends PureComponent<Props, State> {
|
|
68
|
+ /**
|
|
69
|
+ * Initializes a new {@code ChromeExtensionBanner} instance.
|
|
70
|
+ *
|
|
71
|
+ * @param {Object} props - The read-only React {@code PureComponent} props with
|
|
72
|
+ * which the new instance is to be initialized.
|
|
73
|
+ */
|
|
74
|
+ constructor(props: Props) {
|
|
75
|
+ super(props);
|
|
76
|
+ this.state = {
|
|
77
|
+ dontShowAgainChecked: false,
|
|
78
|
+ closePressed: false,
|
|
79
|
+ shouldShow: false
|
|
80
|
+ };
|
|
81
|
+
|
|
82
|
+ this._onClosePressed = this._onClosePressed.bind(this);
|
|
83
|
+ this._onInstallExtensionClick = this._onInstallExtensionClick.bind(this);
|
|
84
|
+ this._checkExtensionsInstalled = this._checkExtensionsInstalled.bind(this);
|
|
85
|
+ this._shouldNotRender = this._shouldNotRender.bind(this);
|
|
86
|
+ this._onDontShowAgainChange = this._onDontShowAgainChange.bind(this);
|
|
87
|
+ }
|
|
88
|
+
|
|
89
|
+ /**
|
|
90
|
+ * Executed on component update.
|
|
91
|
+ * Checks whether any chrome extension from the config is installed.
|
|
92
|
+ *
|
|
93
|
+ * @inheritdoc
|
|
94
|
+ */
|
|
95
|
+ async componentDidUpdate() {
|
|
96
|
+ const hasExtensions = await this._checkExtensionsInstalled();
|
|
97
|
+
|
|
98
|
+ if (
|
|
99
|
+ hasExtensions
|
|
100
|
+ && hasExtensions.length
|
|
101
|
+ && hasExtensions.every(ext => !ext)
|
|
102
|
+ && !this.state.shouldShow
|
|
103
|
+ ) {
|
|
104
|
+ this.setState({ shouldShow: true }); // eslint-disable-line
|
|
105
|
+ }
|
|
106
|
+ }
|
|
107
|
+
|
|
108
|
+ _onClosePressed: () => void;
|
|
109
|
+
|
|
110
|
+ /**
|
|
111
|
+ * Closes the banner for the current session.
|
|
112
|
+ *
|
|
113
|
+ * @returns {void}
|
|
114
|
+ */
|
|
115
|
+ _onClosePressed() {
|
|
116
|
+ this.setState({ closePressed: true });
|
|
117
|
+ }
|
|
118
|
+
|
|
119
|
+ _onInstallExtensionClick: () => void;
|
|
120
|
+
|
|
121
|
+ /**
|
|
122
|
+ * Opens the chrome extension page.
|
|
123
|
+ *
|
|
124
|
+ * @returns {void}
|
|
125
|
+ */
|
|
126
|
+ _onInstallExtensionClick() {
|
|
127
|
+ window.open(this.props.chromeExtensionUrl);
|
|
128
|
+ this.setState({ closePressed: true });
|
|
129
|
+ }
|
|
130
|
+
|
|
131
|
+ _checkExtensionsInstalled: () => Promise<*>;
|
|
132
|
+
|
|
133
|
+ /**
|
|
134
|
+ * Checks whether the chrome extensions defined in the config file are installed or not.
|
|
135
|
+ *
|
|
136
|
+ * @returns {Promise[]}
|
|
137
|
+ */
|
|
138
|
+ _checkExtensionsInstalled() {
|
|
139
|
+ const isExtensionInstalled = info => new Promise(resolve => {
|
|
140
|
+ const img = new Image();
|
|
141
|
+
|
|
142
|
+ img.src = `chrome-extension://${info.id}/${info.path}`;
|
|
143
|
+ img.onload = function() {
|
|
144
|
+ resolve(true);
|
|
145
|
+ };
|
|
146
|
+ img.onerror = function() {
|
|
147
|
+ resolve(false);
|
|
148
|
+ };
|
|
149
|
+ });
|
|
150
|
+ const extensionInstalledFunction = info => isExtensionInstalled(info);
|
|
151
|
+
|
|
152
|
+ if (!this.props.chromeExtensionsInfo.length) {
|
|
153
|
+ console.warn('Further configuration needed, missing chrome extension(s) info');
|
|
154
|
+ }
|
|
155
|
+
|
|
156
|
+ return Promise.all(
|
|
157
|
+ this.props.chromeExtensionsInfo.map(info => extensionInstalledFunction(info))
|
|
158
|
+ );
|
|
159
|
+ }
|
|
160
|
+
|
|
161
|
+ _shouldNotRender: () => boolean;
|
|
162
|
+
|
|
163
|
+ /**
|
|
164
|
+ * Checks whether the banner should be displayed based on:
|
|
165
|
+ * Whether there is a configuration issue with the chrome extensions data.
|
|
166
|
+ * Whether the user checked don't show again checkbox in a previous session.
|
|
167
|
+ * Whether the user closed the banner.
|
|
168
|
+ * Whether the extension is already installed.
|
|
169
|
+ *
|
|
170
|
+ * @returns {boolean} whether to show the banner or not.
|
|
171
|
+ */
|
|
172
|
+ _shouldNotRender() {
|
|
173
|
+ if (!this.props.chromeExtensionUrl) {
|
|
174
|
+ console.warn('Further configuration needed, missing chrome extension URL');
|
|
175
|
+
|
|
176
|
+ return true;
|
|
177
|
+ }
|
|
178
|
+
|
|
179
|
+ const dontShowAgain = localStorage.getItem(DONT_SHOW_AGAIN_CHECKED) === 'true';
|
|
180
|
+
|
|
181
|
+ return dontShowAgain
|
|
182
|
+ || this.state.closePressed
|
|
183
|
+ || !this.state.shouldShow;
|
|
184
|
+ }
|
|
185
|
+
|
|
186
|
+ _onDontShowAgainChange: (object: Object) => void;
|
|
187
|
+
|
|
188
|
+ /**
|
|
189
|
+ * Handles the current `don't show again` checkbox state.
|
|
190
|
+ *
|
|
191
|
+ * @param {Object} event - Input change event.
|
|
192
|
+ * @returns {void}
|
|
193
|
+ */
|
|
194
|
+ _onDontShowAgainChange(event) {
|
|
195
|
+ this.setState({ dontShowAgainChecked: event.target.checked });
|
|
196
|
+ }
|
|
197
|
+
|
|
198
|
+ /**
|
|
199
|
+ * Implements React's {@link PureComponent#render()}.
|
|
200
|
+ *
|
|
201
|
+ * @inheritdoc
|
|
202
|
+ * @returns {ReactElement}
|
|
203
|
+ */
|
|
204
|
+ render() {
|
|
205
|
+ if (this._shouldNotRender()) {
|
|
206
|
+ if (this.state.dontShowAgainChecked) {
|
|
207
|
+ localStorage.setItem(DONT_SHOW_AGAIN_CHECKED, 'true');
|
|
208
|
+ }
|
|
209
|
+
|
|
210
|
+ return null;
|
|
211
|
+ }
|
|
212
|
+ const { t } = this.props;
|
|
213
|
+ const mainClassNames = this.props.conference
|
|
214
|
+ ? 'chrome-extension-banner chrome-extension-banner__pos_in_meeting'
|
|
215
|
+ : 'chrome-extension-banner';
|
|
216
|
+
|
|
217
|
+ return (
|
|
218
|
+ <div className = { mainClassNames }>
|
|
219
|
+ <div className = 'chrome-extension-banner__container'>
|
|
220
|
+ <div
|
|
221
|
+ className = 'chrome-extension-banner__icon-container' />
|
|
222
|
+ <div
|
|
223
|
+ className = 'chrome-extension-banner__text-container'>
|
|
224
|
+ { t('chromeExtensionBanner.installExtensionText') }
|
|
225
|
+ </div>
|
|
226
|
+ <div
|
|
227
|
+ className = 'chrome-extension-banner__close-container'
|
|
228
|
+ onClick = { this._onClosePressed }>
|
|
229
|
+ <Icon
|
|
230
|
+ className = 'gray'
|
|
231
|
+ size = { 12 }
|
|
232
|
+ src = { IconClose } />
|
|
233
|
+ </div>
|
|
234
|
+ </div>
|
|
235
|
+ <div
|
|
236
|
+ className = 'chrome-extension-banner__button-container'>
|
|
237
|
+ <div
|
|
238
|
+ className = 'chrome-extension-banner__button-open-url'
|
|
239
|
+ onClick = { this._onInstallExtensionClick }>
|
|
240
|
+ <div
|
|
241
|
+ className = 'chrome-extension-banner__button-text'>
|
|
242
|
+ { t('chromeExtensionBanner.buttonText') }
|
|
243
|
+ </div>
|
|
244
|
+ </div>
|
|
245
|
+ </div>
|
|
246
|
+ <div className = 'chrome-extension-banner__checkbox-container'>
|
|
247
|
+ <label className = 'chrome-extension-banner__checkbox-label'>
|
|
248
|
+ <input
|
|
249
|
+ checked = { this.state.dontShowAgainChecked }
|
|
250
|
+ onChange = { this._onDontShowAgainChange }
|
|
251
|
+ type = 'checkbox' />
|
|
252
|
+ { t('chromeExtensionBanner.dontShowAgain') }
|
|
253
|
+ </label>
|
|
254
|
+ </div>
|
|
255
|
+ </div>
|
|
256
|
+ );
|
|
257
|
+ }
|
|
258
|
+}
|
|
259
|
+
|
|
260
|
+/**
|
|
261
|
+ * Function that maps parts of Redux state tree into component props.
|
|
262
|
+ *
|
|
263
|
+ * @param {Object} state - Redux state.
|
|
264
|
+ * @returns {Object}
|
|
265
|
+ */
|
|
266
|
+const _mapStateToProps = state => {
|
|
267
|
+ const bannerCfg = state['features/base/config'].chromeExtensionBanner || {};
|
|
268
|
+
|
|
269
|
+ return {
|
|
270
|
+ chromeExtensionUrl: bannerCfg.url,
|
|
271
|
+ chromeExtensionsInfo: bannerCfg.chromeExtensionsInfo || [],
|
|
272
|
+ conference: getCurrentConference(state)
|
|
273
|
+ };
|
|
274
|
+};
|
|
275
|
+
|
|
276
|
+export default translate(connect(_mapStateToProps)(ChromeExtensionBanner));
|