|
|
@@ -1,6 +1,6 @@
|
|
1
|
1
|
import React, { Component } from 'react';
|
|
2
|
2
|
|
|
3
|
|
-import { translate } from '../../base/i18n';
|
|
|
3
|
+import { VideoTrack } from '../../base/media';
|
|
4
|
4
|
|
|
5
|
5
|
const VIDEO_ERROR_CLASS = 'video-preview-has-error';
|
|
6
|
6
|
|
|
|
@@ -23,86 +23,12 @@ class VideoInputPreview extends Component {
|
|
23
|
23
|
*/
|
|
24
|
24
|
error: React.PropTypes.string,
|
|
25
|
25
|
|
|
26
|
|
- /**
|
|
27
|
|
- * Invoked to obtain translated strings.
|
|
28
|
|
- */
|
|
29
|
|
- t: React.PropTypes.func,
|
|
30
|
|
-
|
|
31
|
26
|
/**
|
|
32
|
27
|
* The JitsiLocalTrack to display.
|
|
33
|
28
|
*/
|
|
34
|
29
|
track: React.PropTypes.object
|
|
35
|
30
|
};
|
|
36
|
31
|
|
|
37
|
|
- /**
|
|
38
|
|
- * Initializes a new VideoInputPreview instance.
|
|
39
|
|
- *
|
|
40
|
|
- * @param {Object} props - The read-only React Component props with which
|
|
41
|
|
- * the new instance is to be initialized.
|
|
42
|
|
- */
|
|
43
|
|
- constructor(props) {
|
|
44
|
|
- super(props);
|
|
45
|
|
-
|
|
46
|
|
- /**
|
|
47
|
|
- * The internal reference to the DOM/HTML element intended for showing
|
|
48
|
|
- * error messages.
|
|
49
|
|
- *
|
|
50
|
|
- * @private
|
|
51
|
|
- * @type {HTMLDivElement}
|
|
52
|
|
- */
|
|
53
|
|
- this._errorElement = null;
|
|
54
|
|
-
|
|
55
|
|
- /**
|
|
56
|
|
- * The internal reference to topmost DOM/HTML element backing the React
|
|
57
|
|
- * {@code Component}. Accessed directly for toggling a classname to
|
|
58
|
|
- * indicate an error is present so styling can be changed to display it.
|
|
59
|
|
- *
|
|
60
|
|
- * @private
|
|
61
|
|
- * @type {HTMLDivElement}
|
|
62
|
|
- */
|
|
63
|
|
- this._rootElement = null;
|
|
64
|
|
-
|
|
65
|
|
- /**
|
|
66
|
|
- * The internal reference to the DOM/HTML element intended for
|
|
67
|
|
- * displaying a video. This element may be an HTML video element or a
|
|
68
|
|
- * temasys video object.
|
|
69
|
|
- *
|
|
70
|
|
- * @private
|
|
71
|
|
- * @type {HTMLVideoElement|Object}
|
|
72
|
|
- */
|
|
73
|
|
- this._videoElement = null;
|
|
74
|
|
-
|
|
75
|
|
- // Bind event handlers so they are only bound once for every instance.
|
|
76
|
|
- this._setErrorElement = this._setErrorElement.bind(this);
|
|
77
|
|
- this._setRootElement = this._setRootElement.bind(this);
|
|
78
|
|
- this._setVideoElement = this._setVideoElement.bind(this);
|
|
79
|
|
- }
|
|
80
|
|
-
|
|
81
|
|
- /**
|
|
82
|
|
- * Invokes the library for rendering the video on initial display.
|
|
83
|
|
- *
|
|
84
|
|
- * @inheritdoc
|
|
85
|
|
- * @returns {void}
|
|
86
|
|
- */
|
|
87
|
|
- componentDidMount() {
|
|
88
|
|
- if (this.props.error) {
|
|
89
|
|
- this._updateErrorView(this.props.error);
|
|
90
|
|
- } else {
|
|
91
|
|
- this._attachTrack(this.props.track);
|
|
92
|
|
- }
|
|
93
|
|
- }
|
|
94
|
|
-
|
|
95
|
|
- /**
|
|
96
|
|
- * Remove any existing associations between the current previewed track and
|
|
97
|
|
- * the component's video element.
|
|
98
|
|
- *
|
|
99
|
|
- * @inheritdoc
|
|
100
|
|
- * @returns {void}
|
|
101
|
|
- */
|
|
102
|
|
- componentWillUnmount() {
|
|
103
|
|
- this._detachTrack(this.props.track);
|
|
104
|
|
- }
|
|
105
|
|
-
|
|
106
|
32
|
/**
|
|
107
|
33
|
* Implements React's {@link Component#render()}.
|
|
108
|
34
|
*
|
|
|
@@ -110,146 +36,22 @@ class VideoInputPreview extends Component {
|
|
110
|
36
|
* @returns {ReactElement}
|
|
111
|
37
|
*/
|
|
112
|
38
|
render() {
|
|
|
39
|
+ const { error } = this.props;
|
|
|
40
|
+ const errorClass = error ? VIDEO_ERROR_CLASS : '';
|
|
|
41
|
+ const className = `video-input-preview ${errorClass}`;
|
|
|
42
|
+
|
|
113
|
43
|
return (
|
|
114
|
|
- <div
|
|
115
|
|
- className = 'video-input-preview'
|
|
116
|
|
- ref = { this._setRootElement }>
|
|
117
|
|
- <video
|
|
118
|
|
- autoPlay = { true }
|
|
|
44
|
+ <div className = { className }>
|
|
|
45
|
+ <VideoTrack
|
|
119
|
46
|
className = 'video-input-preview-display flipVideoX'
|
|
120
|
|
- ref = { this._setVideoElement } />
|
|
121
|
|
- <div
|
|
122
|
|
- className = 'video-input-preview-error'
|
|
123
|
|
- ref = { this._setErrorElement } />
|
|
|
47
|
+ triggerOnPlayingUpdate = { false }
|
|
|
48
|
+ videoTrack = {{ jitsiTrack: this.props.track }} />
|
|
|
49
|
+ <div className = 'video-input-preview-error'>
|
|
|
50
|
+ { error || '' }
|
|
|
51
|
+ </div>
|
|
124
|
52
|
</div>
|
|
125
|
53
|
);
|
|
126
|
54
|
}
|
|
127
|
|
-
|
|
128
|
|
- /**
|
|
129
|
|
- * Only update when the deviceId has changed. This component is somewhat
|
|
130
|
|
- * black-boxed from React's rendering so lib-jitsi-meet can instead handle
|
|
131
|
|
- * updating of the video preview, which takes browser differences into
|
|
132
|
|
- * consideration. For example, temasys's video object must be visible to
|
|
133
|
|
- * update the displayed track, but React's re-rendering could potentially
|
|
134
|
|
- * remove the video object from the page.
|
|
135
|
|
- *
|
|
136
|
|
- * @inheritdoc
|
|
137
|
|
- * @returns {void}
|
|
138
|
|
- */
|
|
139
|
|
- shouldComponentUpdate(nextProps) {
|
|
140
|
|
- const hasNewTrack = nextProps.track !== this.props.track;
|
|
141
|
|
-
|
|
142
|
|
- if (hasNewTrack || nextProps.error) {
|
|
143
|
|
- this._detachTrack(this.props.track);
|
|
144
|
|
- this._updateErrorView(nextProps.error);
|
|
145
|
|
- }
|
|
146
|
|
-
|
|
147
|
|
- // Never attempt to show the new track if there is an error present.
|
|
148
|
|
- if (hasNewTrack && !nextProps.error) {
|
|
149
|
|
- this._attachTrack(nextProps.track);
|
|
150
|
|
- }
|
|
151
|
|
-
|
|
152
|
|
- return false;
|
|
153
|
|
- }
|
|
154
|
|
-
|
|
155
|
|
- /**
|
|
156
|
|
- * Calls into the passed in track to associate the track with the
|
|
157
|
|
- * component's video element and render video. Also sets the instance
|
|
158
|
|
- * variable for the video element as the element the track attached to,
|
|
159
|
|
- * which could be an Object if on a temasys supported browser.
|
|
160
|
|
- *
|
|
161
|
|
- * @param {JitsiLocalTrack} track - The library's track model which will be
|
|
162
|
|
- * displayed.
|
|
163
|
|
- * @private
|
|
164
|
|
- * @returns {void}
|
|
165
|
|
- */
|
|
166
|
|
- _attachTrack(track) {
|
|
167
|
|
- if (!track) {
|
|
168
|
|
- return;
|
|
169
|
|
- }
|
|
170
|
|
-
|
|
171
|
|
- const updatedVideoElement = track.attach(this._videoElement);
|
|
172
|
|
-
|
|
173
|
|
- this._setVideoElement(updatedVideoElement);
|
|
174
|
|
- }
|
|
175
|
|
-
|
|
176
|
|
- /**
|
|
177
|
|
- * Removes the association to the component's video element from the passed
|
|
178
|
|
- * in JitsiLocalTrack to stop the track from rendering. With temasys, the
|
|
179
|
|
- * video element must still be visible for detaching to complete.
|
|
180
|
|
- *
|
|
181
|
|
- * @param {JitsiLocalTrack} track - The library's track model which needs
|
|
182
|
|
- * to stop previewing in the video element.
|
|
183
|
|
- * @private
|
|
184
|
|
- * @returns {void}
|
|
185
|
|
- */
|
|
186
|
|
- _detachTrack(track) {
|
|
187
|
|
- // Detach the video element from the track only if it has already
|
|
188
|
|
- // been attached. This accounts for a special case with temasys
|
|
189
|
|
- // where if detach is being called before attach, the video
|
|
190
|
|
- // element is converted to Object without updating this
|
|
191
|
|
- // component's reference to the video element.
|
|
192
|
|
- if (this._videoElement
|
|
193
|
|
- && track
|
|
194
|
|
- && track.containers.includes(this._videoElement)) {
|
|
195
|
|
- track.detach(this._videoElement);
|
|
196
|
|
- }
|
|
197
|
|
- }
|
|
198
|
|
-
|
|
199
|
|
- /**
|
|
200
|
|
- * Sets an instance variable for the component's element intended for
|
|
201
|
|
- * displaying error messages. The element will be accessed directly to
|
|
202
|
|
- * display an error message.
|
|
203
|
|
- *
|
|
204
|
|
- * @param {Object} element - DOM element intended for displaying errors.
|
|
205
|
|
- * @private
|
|
206
|
|
- * @returns {void}
|
|
207
|
|
- */
|
|
208
|
|
- _setErrorElement(element) {
|
|
209
|
|
- this._errorElement = element;
|
|
210
|
|
- }
|
|
211
|
|
-
|
|
212
|
|
- /**
|
|
213
|
|
- * Sets the component's root element.
|
|
214
|
|
- *
|
|
215
|
|
- * @param {Object} element - The highest DOM element in the component.
|
|
216
|
|
- * @private
|
|
217
|
|
- * @returns {void}
|
|
218
|
|
- */
|
|
219
|
|
- _setRootElement(element) {
|
|
220
|
|
- this._rootElement = element;
|
|
221
|
|
- }
|
|
222
|
|
-
|
|
223
|
|
- /**
|
|
224
|
|
- * Sets an instance variable for the component's video element so it can be
|
|
225
|
|
- * referenced later for attaching and detaching a JitsiLocalTrack.
|
|
226
|
|
- *
|
|
227
|
|
- * @param {Object} element - DOM element for the component's video display.
|
|
228
|
|
- * @private
|
|
229
|
|
- * @returns {void}
|
|
230
|
|
- */
|
|
231
|
|
- _setVideoElement(element) {
|
|
232
|
|
- this._videoElement = element;
|
|
233
|
|
- }
|
|
234
|
|
-
|
|
235
|
|
- /**
|
|
236
|
|
- * Adds or removes a class to the component's parent node to indicate an
|
|
237
|
|
- * error has occurred. Also sets the error text.
|
|
238
|
|
- *
|
|
239
|
|
- * @param {string} error - The error message to display. If falsy, error
|
|
240
|
|
- * message display will be hidden.
|
|
241
|
|
- * @private
|
|
242
|
|
- * @returns {void}
|
|
243
|
|
- */
|
|
244
|
|
- _updateErrorView(error) {
|
|
245
|
|
- if (error) {
|
|
246
|
|
- this._rootElement.classList.add(VIDEO_ERROR_CLASS);
|
|
247
|
|
- } else {
|
|
248
|
|
- this._rootElement.classList.remove(VIDEO_ERROR_CLASS);
|
|
249
|
|
- }
|
|
250
|
|
-
|
|
251
|
|
- this._errorElement.innerText = error || '';
|
|
252
|
|
- }
|
|
253
|
55
|
}
|
|
254
|
56
|
|
|
255
|
|
-export default translate(VideoInputPreview);
|
|
|
57
|
+export default VideoInputPreview;
|