|
|
@@ -1,388 +1,10 @@
|
|
1
|
1
|
/* global $, APP, interfaceConfig */
|
|
2
|
2
|
/* jshint -W101 */
|
|
3
|
3
|
|
|
4
|
|
-import UIUtil from "../util/UIUtil";
|
|
5
|
|
-import UIEvents from "../../../service/UI/UIEvents";
|
|
6
|
|
-import LargeContainer from './LargeContainer';
|
|
7
|
|
-import FilmStrip from './FilmStrip';
|
|
8
|
4
|
import Avatar from "../avatar/Avatar";
|
|
9
|
5
|
import {createDeferred} from '../../util/helpers';
|
|
10
|
|
-
|
|
11
|
|
-const FADE_DURATION_MS = 300;
|
|
12
|
|
-
|
|
13
|
|
-export const VIDEO_CONTAINER_TYPE = "camera";
|
|
14
|
|
-
|
|
15
|
|
-/**
|
|
16
|
|
- * Get stream id.
|
|
17
|
|
- * @param {JitsiTrack?} stream
|
|
18
|
|
- */
|
|
19
|
|
-function getStreamOwnerId(stream) {
|
|
20
|
|
- if (!stream) {
|
|
21
|
|
- return;
|
|
22
|
|
- }
|
|
23
|
|
- if (stream.isLocal()) { // local stream doesn't have method "getParticipantId"
|
|
24
|
|
- return APP.conference.getMyUserId();
|
|
25
|
|
- } else {
|
|
26
|
|
- return stream.getParticipantId();
|
|
27
|
|
- }
|
|
28
|
|
-}
|
|
29
|
|
-
|
|
30
|
|
-/**
|
|
31
|
|
- * Returns an array of the video dimensions, so that it keeps it's aspect
|
|
32
|
|
- * ratio and fits available area with it's larger dimension. This method
|
|
33
|
|
- * ensures that whole video will be visible and can leave empty areas.
|
|
34
|
|
- *
|
|
35
|
|
- * @return an array with 2 elements, the video width and the video height
|
|
36
|
|
- */
|
|
37
|
|
-function getDesktopVideoSize(videoWidth,
|
|
38
|
|
- videoHeight,
|
|
39
|
|
- videoSpaceWidth,
|
|
40
|
|
- videoSpaceHeight) {
|
|
41
|
|
-
|
|
42
|
|
- let aspectRatio = videoWidth / videoHeight;
|
|
43
|
|
-
|
|
44
|
|
- let availableWidth = Math.max(videoWidth, videoSpaceWidth);
|
|
45
|
|
- let availableHeight = Math.max(videoHeight, videoSpaceHeight);
|
|
46
|
|
-
|
|
47
|
|
- videoSpaceHeight -= FilmStrip.getFilmStripHeight();
|
|
48
|
|
-
|
|
49
|
|
- if (availableWidth / aspectRatio >= videoSpaceHeight) {
|
|
50
|
|
- availableHeight = videoSpaceHeight;
|
|
51
|
|
- availableWidth = availableHeight * aspectRatio;
|
|
52
|
|
- }
|
|
53
|
|
-
|
|
54
|
|
- if (availableHeight * aspectRatio >= videoSpaceWidth) {
|
|
55
|
|
- availableWidth = videoSpaceWidth;
|
|
56
|
|
- availableHeight = availableWidth / aspectRatio;
|
|
57
|
|
- }
|
|
58
|
|
-
|
|
59
|
|
- return [ availableWidth, availableHeight ];
|
|
60
|
|
-}
|
|
61
|
|
-
|
|
62
|
|
-
|
|
63
|
|
-/**
|
|
64
|
|
- * Returns an array of the video dimensions. It respects the
|
|
65
|
|
- * VIDEO_LAYOUT_FIT config, to fit the video to the screen, by hiding some parts
|
|
66
|
|
- * of it, or to fit it to the height or width.
|
|
67
|
|
- *
|
|
68
|
|
- * @param videoWidth the original video width
|
|
69
|
|
- * @param videoHeight the original video height
|
|
70
|
|
- * @param videoSpaceWidth the width of the video space
|
|
71
|
|
- * @param videoSpaceHeight the height of the video space
|
|
72
|
|
- * @return an array with 2 elements, the video width and the video height
|
|
73
|
|
- */
|
|
74
|
|
-function getCameraVideoSize(videoWidth,
|
|
75
|
|
- videoHeight,
|
|
76
|
|
- videoSpaceWidth,
|
|
77
|
|
- videoSpaceHeight) {
|
|
78
|
|
-
|
|
79
|
|
- let aspectRatio = videoWidth / videoHeight;
|
|
80
|
|
-
|
|
81
|
|
- let availableWidth = videoWidth;
|
|
82
|
|
- let availableHeight = videoHeight;
|
|
83
|
|
-
|
|
84
|
|
- if (interfaceConfig.VIDEO_LAYOUT_FIT == 'height') {
|
|
85
|
|
- availableHeight = videoSpaceHeight;
|
|
86
|
|
- availableWidth = availableHeight*aspectRatio;
|
|
87
|
|
- }
|
|
88
|
|
- else if (interfaceConfig.VIDEO_LAYOUT_FIT == 'width') {
|
|
89
|
|
- availableWidth = videoSpaceWidth;
|
|
90
|
|
- availableHeight = availableWidth/aspectRatio;
|
|
91
|
|
- }
|
|
92
|
|
- else if (interfaceConfig.VIDEO_LAYOUT_FIT == 'both') {
|
|
93
|
|
- availableWidth = Math.max(videoWidth, videoSpaceWidth);
|
|
94
|
|
- availableHeight = Math.max(videoHeight, videoSpaceHeight);
|
|
95
|
|
-
|
|
96
|
|
- if (availableWidth / aspectRatio < videoSpaceHeight) {
|
|
97
|
|
- availableHeight = videoSpaceHeight;
|
|
98
|
|
- availableWidth = availableHeight * aspectRatio;
|
|
99
|
|
- }
|
|
100
|
|
-
|
|
101
|
|
- if (availableHeight * aspectRatio < videoSpaceWidth) {
|
|
102
|
|
- availableWidth = videoSpaceWidth;
|
|
103
|
|
- availableHeight = availableWidth / aspectRatio;
|
|
104
|
|
- }
|
|
105
|
|
- }
|
|
106
|
|
-
|
|
107
|
|
-
|
|
108
|
|
- return [ availableWidth, availableHeight ];
|
|
109
|
|
-}
|
|
110
|
|
-
|
|
111
|
|
-/**
|
|
112
|
|
- * Returns an array of the video horizontal and vertical indents,
|
|
113
|
|
- * so that if fits its parent.
|
|
114
|
|
- *
|
|
115
|
|
- * @return an array with 2 elements, the horizontal indent and the vertical
|
|
116
|
|
- * indent
|
|
117
|
|
- */
|
|
118
|
|
-function getCameraVideoPosition(videoWidth,
|
|
119
|
|
- videoHeight,
|
|
120
|
|
- videoSpaceWidth,
|
|
121
|
|
- videoSpaceHeight) {
|
|
122
|
|
- // Parent height isn't completely calculated when we position the video in
|
|
123
|
|
- // full screen mode and this is why we use the screen height in this case.
|
|
124
|
|
- // Need to think it further at some point and implement it properly.
|
|
125
|
|
- if (UIUtil.isFullScreen()) {
|
|
126
|
|
- videoSpaceHeight = window.innerHeight;
|
|
127
|
|
- }
|
|
128
|
|
-
|
|
129
|
|
- let horizontalIndent = (videoSpaceWidth - videoWidth) / 2;
|
|
130
|
|
- let verticalIndent = (videoSpaceHeight - videoHeight) / 2;
|
|
131
|
|
-
|
|
132
|
|
- return { horizontalIndent, verticalIndent };
|
|
133
|
|
-}
|
|
134
|
|
-
|
|
135
|
|
-/**
|
|
136
|
|
- * Returns an array of the video horizontal and vertical indents.
|
|
137
|
|
- * Centers horizontally and top aligns vertically.
|
|
138
|
|
- *
|
|
139
|
|
- * @return an array with 2 elements, the horizontal indent and the vertical
|
|
140
|
|
- * indent
|
|
141
|
|
- */
|
|
142
|
|
-function getDesktopVideoPosition(videoWidth,
|
|
143
|
|
- videoHeight,
|
|
144
|
|
- videoSpaceWidth,
|
|
145
|
|
- videoSpaceHeight) {
|
|
146
|
|
-
|
|
147
|
|
- let horizontalIndent = (videoSpaceWidth - videoWidth) / 2;
|
|
148
|
|
-
|
|
149
|
|
- let verticalIndent = 0;// Top aligned
|
|
150
|
|
-
|
|
151
|
|
- return { horizontalIndent, verticalIndent };
|
|
152
|
|
-}
|
|
153
|
|
-
|
|
154
|
|
-/**
|
|
155
|
|
- * Container for user video.
|
|
156
|
|
- */
|
|
157
|
|
-class VideoContainer extends LargeContainer {
|
|
158
|
|
- // FIXME: With Temasys we have to re-select everytime
|
|
159
|
|
- get $video () {
|
|
160
|
|
- return $('#largeVideo');
|
|
161
|
|
- }
|
|
162
|
|
-
|
|
163
|
|
- get id () {
|
|
164
|
|
- return getStreamOwnerId(this.stream);
|
|
165
|
|
- }
|
|
166
|
|
-
|
|
167
|
|
- constructor (onPlay, emitter) {
|
|
168
|
|
- super();
|
|
169
|
|
- this.stream = null;
|
|
170
|
|
- this.videoType = null;
|
|
171
|
|
- this.localFlipX = true;
|
|
172
|
|
- this.emitter = emitter;
|
|
173
|
|
-
|
|
174
|
|
- this.isVisible = false;
|
|
175
|
|
-
|
|
176
|
|
- this.$avatar = $('#dominantSpeaker');
|
|
177
|
|
- this.$wrapper = $('#largeVideoWrapper');
|
|
178
|
|
-
|
|
179
|
|
- this.avatarHeight = $("#dominantSpeakerAvatar").height();
|
|
180
|
|
-
|
|
181
|
|
- // This does not work with Temasys plugin - has to be a property to be
|
|
182
|
|
- // copied between new <object> elements
|
|
183
|
|
- //this.$video.on('play', onPlay);
|
|
184
|
|
- this.$video[0].onplay = onPlay;
|
|
185
|
|
- }
|
|
186
|
|
-
|
|
187
|
|
- /**
|
|
188
|
|
- * Get size of video element.
|
|
189
|
|
- * @returns {{width, height}}
|
|
190
|
|
- */
|
|
191
|
|
- getStreamSize () {
|
|
192
|
|
- let video = this.$video[0];
|
|
193
|
|
- return {
|
|
194
|
|
- width: video.videoWidth,
|
|
195
|
|
- height: video.videoHeight
|
|
196
|
|
- };
|
|
197
|
|
- }
|
|
198
|
|
-
|
|
199
|
|
- /**
|
|
200
|
|
- * Calculate optimal video size for specified container size.
|
|
201
|
|
- * @param {number} containerWidth container width
|
|
202
|
|
- * @param {number} containerHeight container height
|
|
203
|
|
- * @returns {{availableWidth, availableHeight}}
|
|
204
|
|
- */
|
|
205
|
|
- getVideoSize (containerWidth, containerHeight) {
|
|
206
|
|
- let { width, height } = this.getStreamSize();
|
|
207
|
|
- if (this.stream && this.isScreenSharing()) {
|
|
208
|
|
- return getDesktopVideoSize( width,
|
|
209
|
|
- height,
|
|
210
|
|
- containerWidth,
|
|
211
|
|
- containerHeight);
|
|
212
|
|
- } else {
|
|
213
|
|
- return getCameraVideoSize( width,
|
|
214
|
|
- height,
|
|
215
|
|
- containerWidth,
|
|
216
|
|
- containerHeight);
|
|
217
|
|
- }
|
|
218
|
|
- }
|
|
219
|
|
-
|
|
220
|
|
- /**
|
|
221
|
|
- * Calculate optimal video position (offset for top left corner)
|
|
222
|
|
- * for specified video size and container size.
|
|
223
|
|
- * @param {number} width video width
|
|
224
|
|
- * @param {number} height video height
|
|
225
|
|
- * @param {number} containerWidth container width
|
|
226
|
|
- * @param {number} containerHeight container height
|
|
227
|
|
- * @returns {{horizontalIndent, verticalIndent}}
|
|
228
|
|
- */
|
|
229
|
|
- getVideoPosition (width, height, containerWidth, containerHeight) {
|
|
230
|
|
- if (this.stream && this.isScreenSharing()) {
|
|
231
|
|
- return getDesktopVideoPosition( width,
|
|
232
|
|
- height,
|
|
233
|
|
- containerWidth,
|
|
234
|
|
- containerHeight);
|
|
235
|
|
- } else {
|
|
236
|
|
- return getCameraVideoPosition( width,
|
|
237
|
|
- height,
|
|
238
|
|
- containerWidth,
|
|
239
|
|
- containerHeight);
|
|
240
|
|
- }
|
|
241
|
|
- }
|
|
242
|
|
-
|
|
243
|
|
- resize (containerWidth, containerHeight, animate = false) {
|
|
244
|
|
- let [width, height]
|
|
245
|
|
- = this.getVideoSize(containerWidth, containerHeight);
|
|
246
|
|
- let { horizontalIndent, verticalIndent }
|
|
247
|
|
- = this.getVideoPosition(width, height,
|
|
248
|
|
- containerWidth, containerHeight);
|
|
249
|
|
-
|
|
250
|
|
- // update avatar position
|
|
251
|
|
- let top = containerHeight / 2 - this.avatarHeight / 4 * 3;
|
|
252
|
|
-
|
|
253
|
|
- this.$avatar.css('top', top);
|
|
254
|
|
-
|
|
255
|
|
- this.$wrapper.animate({
|
|
256
|
|
- width: width,
|
|
257
|
|
- height: height,
|
|
258
|
|
-
|
|
259
|
|
- top: verticalIndent,
|
|
260
|
|
- bottom: verticalIndent,
|
|
261
|
|
-
|
|
262
|
|
- left: horizontalIndent,
|
|
263
|
|
- right: horizontalIndent
|
|
264
|
|
- }, {
|
|
265
|
|
- queue: false,
|
|
266
|
|
- duration: animate ? 500 : 0
|
|
267
|
|
- });
|
|
268
|
|
- }
|
|
269
|
|
-
|
|
270
|
|
- /**
|
|
271
|
|
- * Update video stream.
|
|
272
|
|
- * @param {JitsiTrack?} stream new stream
|
|
273
|
|
- * @param {string} videoType video type
|
|
274
|
|
- */
|
|
275
|
|
- setStream (stream, videoType) {
|
|
276
|
|
- // detach old stream
|
|
277
|
|
- if (this.stream) {
|
|
278
|
|
- this.stream.detach(this.$video[0]);
|
|
279
|
|
- }
|
|
280
|
|
-
|
|
281
|
|
- this.stream = stream;
|
|
282
|
|
- this.videoType = videoType;
|
|
283
|
|
-
|
|
284
|
|
- if (!stream) {
|
|
285
|
|
- return;
|
|
286
|
|
- }
|
|
287
|
|
-
|
|
288
|
|
- stream.attach(this.$video[0]);
|
|
289
|
|
- let flipX = stream.isLocal() && this.localFlipX;
|
|
290
|
|
- this.$video.css({
|
|
291
|
|
- transform: flipX ? 'scaleX(-1)' : 'none'
|
|
292
|
|
- });
|
|
293
|
|
- }
|
|
294
|
|
-
|
|
295
|
|
- /**
|
|
296
|
|
- * Changes the flipX state of the local video.
|
|
297
|
|
- * @param val {boolean} true if flipped.
|
|
298
|
|
- */
|
|
299
|
|
- setLocalFlipX(val) {
|
|
300
|
|
- this.localFlipX = val;
|
|
301
|
|
- if(!this.$video || !this.stream || !this.stream.isLocal())
|
|
302
|
|
- return;
|
|
303
|
|
- this.$video.css({
|
|
304
|
|
- transform: this.localFlipX ? 'scaleX(-1)' : 'none'
|
|
305
|
|
- });
|
|
306
|
|
- }
|
|
307
|
|
-
|
|
308
|
|
- /**
|
|
309
|
|
- * Check if current video stream is screen sharing.
|
|
310
|
|
- * @returns {boolean}
|
|
311
|
|
- */
|
|
312
|
|
- isScreenSharing () {
|
|
313
|
|
- return this.videoType === 'desktop';
|
|
314
|
|
- }
|
|
315
|
|
-
|
|
316
|
|
- /**
|
|
317
|
|
- * Show or hide user avatar.
|
|
318
|
|
- * @param {boolean} show
|
|
319
|
|
- */
|
|
320
|
|
- showAvatar (show) {
|
|
321
|
|
- // TO FIX: Video background need to be black, so that we don't have a
|
|
322
|
|
- // flickering effect when scrolling between videos and have the screen
|
|
323
|
|
- // move to grey before going back to video. Avatars though can have the
|
|
324
|
|
- // default background set.
|
|
325
|
|
- // In order to fix this code we need to introduce video background or
|
|
326
|
|
- // find a workaround for the video flickering.
|
|
327
|
|
- $("#largeVideoContainer").css("background",
|
|
328
|
|
- (show) ? interfaceConfig.DEFAULT_BACKGROUND : "#000");
|
|
329
|
|
-
|
|
330
|
|
- this.$avatar.css("visibility", show ? "visible" : "hidden");
|
|
331
|
|
-
|
|
332
|
|
- this.emitter.emit(UIEvents.LARGE_VIDEO_AVATAR_DISPLAYED, show);
|
|
333
|
|
- }
|
|
334
|
|
-
|
|
335
|
|
- // We are doing fadeOut/fadeIn animations on parent div which wraps
|
|
336
|
|
- // largeVideo, because when Temasys plugin is in use it replaces
|
|
337
|
|
- // <video> elements with plugin <object> tag. In Safari jQuery is
|
|
338
|
|
- // unable to store values on this plugin object which breaks all
|
|
339
|
|
- // animation effects performed on it directly.
|
|
340
|
|
-
|
|
341
|
|
- show () {
|
|
342
|
|
- // its already visible
|
|
343
|
|
- if (this.isVisible) {
|
|
344
|
|
- return Promise.resolve();
|
|
345
|
|
- }
|
|
346
|
|
-
|
|
347
|
|
- let $wrapper = this.$wrapper;
|
|
348
|
|
- return new Promise((resolve) => {
|
|
349
|
|
- this.$wrapper.css('visibility', 'visible').fadeTo(
|
|
350
|
|
- FADE_DURATION_MS,
|
|
351
|
|
- 1,
|
|
352
|
|
- () => {
|
|
353
|
|
- this.isVisible = true;
|
|
354
|
|
- resolve();
|
|
355
|
|
- }
|
|
356
|
|
- );
|
|
357
|
|
- });
|
|
358
|
|
- }
|
|
359
|
|
-
|
|
360
|
|
- hide () {
|
|
361
|
|
- // as the container is hidden/replaced by another container
|
|
362
|
|
- // hide its avatar
|
|
363
|
|
- this.showAvatar(false);
|
|
364
|
|
-
|
|
365
|
|
- // its already hidden
|
|
366
|
|
- if (!this.isVisible) {
|
|
367
|
|
- return Promise.resolve();
|
|
368
|
|
- }
|
|
369
|
|
-
|
|
370
|
|
- return new Promise((resolve) => {
|
|
371
|
|
- this.$wrapper.fadeTo(FADE_DURATION_MS, 0, () => {
|
|
372
|
|
- this.$wrapper.css('visibility', 'hidden');
|
|
373
|
|
- this.isVisible = false;
|
|
374
|
|
- resolve();
|
|
375
|
|
- });
|
|
376
|
|
- });
|
|
377
|
|
- }
|
|
378
|
|
-
|
|
379
|
|
- /**
|
|
380
|
|
- * @return {boolean} switch on dominant speaker event if on stage.
|
|
381
|
|
- */
|
|
382
|
|
- stayOnStage () {
|
|
383
|
|
- return false;
|
|
384
|
|
- }
|
|
385
|
|
-}
|
|
|
6
|
+import UIUtil from "../util/UIUtil";
|
|
|
7
|
+import {VideoContainer, VIDEO_CONTAINER_TYPE} from "./VideoContainer";
|
|
386
|
8
|
|
|
387
|
9
|
/**
|
|
388
|
10
|
* Manager for all Large containers.
|