2017-10-10 23:31:40 +00:00
|
|
|
/* global $, config, interfaceConfig, APP */
|
2017-07-14 19:22:27 +00:00
|
|
|
|
|
|
|
/* eslint-disable no-unused-vars */
|
|
|
|
import React, { Component } from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import { Provider } from 'react-redux';
|
|
|
|
|
2017-10-10 23:31:40 +00:00
|
|
|
import { JitsiTrackEvents } from '../../../react/features/base/lib-jitsi-meet';
|
2017-07-14 19:22:27 +00:00
|
|
|
import { VideoTrack } from '../../../react/features/base/media';
|
2018-04-12 19:58:20 +00:00
|
|
|
import { updateSettings } from '../../../react/features/base/settings';
|
fix(tile-view): prevent local participant being selected on pin exit
On tile view enter/exit, local video is moved in the DOM (an effect
of not being reactified and moving being easier) and play is called
on its video element. The race condition setup is such: in tile
view with other participants and local video is on large (not
visible in the UI but visible in the app state and pip popout).
The race is such: pin a remote video, large video update is queued,
tile view is exited, local video is moved, play is called,,
onVideoPlaying callback executed, middleware fires mute update,
which checks if local is on large (it is), previous large video
update is cleared, and local is placed on large.
The fix is ensuring the redux representation of local video is
passed in, which holds the boolean videoStarted, which prevents
the onVideoPlaying callback from firing on subsequent plays.
2018-11-27 22:13:47 +00:00
|
|
|
import { getLocalVideoTrack } from '../../../react/features/base/tracks';
|
2018-08-08 18:48:23 +00:00
|
|
|
import { shouldDisplayTileView } from '../../../react/features/video-layout';
|
2017-07-14 19:22:27 +00:00
|
|
|
/* eslint-enable no-unused-vars */
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
2016-11-11 15:00:54 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
import UIEvents from '../../../service/UI/UIEvents';
|
|
|
|
import SmallVideo from './SmallVideo';
|
2015-12-14 12:26:50 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2018-05-21 22:10:43 +00:00
|
|
|
function LocalVideo(VideoLayout, emitter, streamEndedCallback) {
|
2017-10-12 23:02:29 +00:00
|
|
|
this.videoSpanId = 'localVideoContainer';
|
2018-05-21 22:10:43 +00:00
|
|
|
this.streamEndedCallback = streamEndedCallback;
|
2017-06-30 17:40:55 +00:00
|
|
|
this.container = this.createContainer();
|
2017-06-30 23:07:37 +00:00
|
|
|
this.$container = $(this.container);
|
2018-08-08 18:48:23 +00:00
|
|
|
this.updateDOMLocation();
|
2017-06-30 17:40:55 +00:00
|
|
|
|
2016-05-07 01:50:37 +00:00
|
|
|
this.localVideoId = null;
|
2016-10-26 20:45:51 +00:00
|
|
|
this.bindHoverHandler();
|
2019-05-23 16:07:05 +00:00
|
|
|
if (!config.disableLocalVideoFlip) {
|
2016-05-09 17:39:42 +00:00
|
|
|
this._buildContextMenu();
|
2017-10-12 23:02:29 +00:00
|
|
|
}
|
2015-07-15 10:14:34 +00:00
|
|
|
this.isLocal = true;
|
2015-12-01 12:53:01 +00:00
|
|
|
this.emitter = emitter;
|
2017-08-14 15:02:58 +00:00
|
|
|
this.statsPopoverLocation = interfaceConfig.VERTICAL_FILMSTRIP
|
2017-10-03 16:30:42 +00:00
|
|
|
? 'left top' : 'top center';
|
2017-08-14 15:02:58 +00:00
|
|
|
|
2016-02-09 10:19:43 +00:00
|
|
|
Object.defineProperty(this, 'id', {
|
2017-10-12 23:02:29 +00:00
|
|
|
get() {
|
2016-07-08 01:44:04 +00:00
|
|
|
return APP.conference.getMyUserId();
|
2016-02-09 10:19:43 +00:00
|
|
|
}
|
|
|
|
});
|
2016-08-08 22:03:00 +00:00
|
|
|
this.initBrowserSpecificProperties();
|
|
|
|
|
2016-03-15 20:42:53 +00:00
|
|
|
SmallVideo.call(this, VideoLayout);
|
2016-08-31 19:18:09 +00:00
|
|
|
|
|
|
|
// Set default display name.
|
2019-03-26 16:34:02 +00:00
|
|
|
this.updateDisplayName();
|
2016-08-31 19:18:09 +00:00
|
|
|
|
2017-12-19 23:11:54 +00:00
|
|
|
// Initialize the avatar display with an avatar url selected from the redux
|
|
|
|
// state. Redux stores the local user with a hardcoded participant id of
|
|
|
|
// 'local' if no id has been assigned yet.
|
2019-06-26 14:08:23 +00:00
|
|
|
this.initializeAvatar();
|
2017-12-19 23:11:54 +00:00
|
|
|
|
2016-09-28 21:31:40 +00:00
|
|
|
this.addAudioLevelIndicator();
|
2017-07-05 18:17:30 +00:00
|
|
|
this.updateIndicators();
|
2017-11-09 00:17:38 +00:00
|
|
|
|
2018-11-30 22:13:39 +00:00
|
|
|
this.container.onclick = this._onContainerClick;
|
2015-06-23 08:00:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LocalVideo.prototype = Object.create(SmallVideo.prototype);
|
|
|
|
LocalVideo.prototype.constructor = LocalVideo;
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
LocalVideo.prototype.createContainer = function() {
|
2017-06-30 17:40:55 +00:00
|
|
|
const containerSpan = document.createElement('span');
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2017-06-30 17:40:55 +00:00
|
|
|
containerSpan.classList.add('videocontainer');
|
|
|
|
containerSpan.id = this.videoSpanId;
|
|
|
|
|
|
|
|
containerSpan.innerHTML = `
|
|
|
|
<div class = 'videocontainer__background'></div>
|
|
|
|
<span id = 'localVideoWrapper'></span>
|
|
|
|
<div class = 'videocontainer__toolbar'></div>
|
|
|
|
<div class = 'videocontainer__toptoolbar'></div>
|
|
|
|
<div class = 'videocontainer__hoverOverlay'></div>
|
|
|
|
<div class = 'displayNameContainer'></div>
|
|
|
|
<div class = 'avatar-container'></div>`;
|
|
|
|
|
|
|
|
return containerSpan;
|
|
|
|
};
|
|
|
|
|
2015-06-23 08:00:46 +00:00
|
|
|
/**
|
2019-03-26 16:34:02 +00:00
|
|
|
* Triggers re-rendering of the display name using current instance state.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
2015-06-23 08:00:46 +00:00
|
|
|
*/
|
2019-03-26 16:34:02 +00:00
|
|
|
LocalVideo.prototype.updateDisplayName = function() {
|
2015-06-23 08:00:46 +00:00
|
|
|
if (!this.container) {
|
2016-11-11 15:00:54 +00:00
|
|
|
logger.warn(
|
2017-10-12 23:02:29 +00:00
|
|
|
`Unable to set displayName - ${this.videoSpanId
|
|
|
|
} does not exist`);
|
|
|
|
|
2015-06-23 08:00:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-26 16:34:02 +00:00
|
|
|
this._renderDisplayName({
|
2017-12-13 23:37:27 +00:00
|
|
|
allowEditing: APP.store.getState()['features/base/jwt'].isGuest,
|
2017-06-29 03:35:43 +00:00
|
|
|
displayNameSuffix: interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME,
|
|
|
|
elementID: 'localDisplayName',
|
|
|
|
participantID: this.id
|
|
|
|
});
|
2015-07-28 21:52:32 +00:00
|
|
|
};
|
2015-06-23 08:00:46 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
LocalVideo.prototype.changeVideo = function(stream) {
|
2016-01-29 00:33:27 +00:00
|
|
|
this.videoStream = stream;
|
2015-06-23 08:00:46 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
this.localVideoId = `localVideo_${stream.getId()}`;
|
2015-06-23 08:00:46 +00:00
|
|
|
|
2018-08-08 18:48:23 +00:00
|
|
|
this._updateVideoElement();
|
2015-06-23 08:00:46 +00:00
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
// eslint-disable-next-line eqeqeq
|
|
|
|
const isVideo = stream.videoType != 'desktop';
|
2018-04-12 19:58:20 +00:00
|
|
|
const settings = APP.store.getState()['features/base/settings'];
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2016-05-07 01:50:37 +00:00
|
|
|
this._enableDisableContextMenu(isVideo);
|
2018-04-12 19:58:20 +00:00
|
|
|
this.setFlipX(isVideo ? settings.localFlipX : false);
|
2017-10-12 23:02:29 +00:00
|
|
|
|
|
|
|
const endedHandler = () => {
|
2018-08-08 18:48:23 +00:00
|
|
|
const localVideoContainer
|
|
|
|
= document.getElementById('localVideoWrapper');
|
2015-06-23 08:00:46 +00:00
|
|
|
|
2017-07-14 19:22:27 +00:00
|
|
|
// Only remove if there is no video and not a transition state.
|
|
|
|
// Previous non-react logic created a new video element with each track
|
|
|
|
// removal whereas react reuses the video component so it could be the
|
|
|
|
// stream ended but a new one is being used.
|
2018-08-08 18:48:23 +00:00
|
|
|
if (localVideoContainer && this.videoStream.isEnded()) {
|
2017-07-14 19:22:27 +00:00
|
|
|
ReactDOM.unmountComponentAtNode(localVideoContainer);
|
|
|
|
}
|
|
|
|
|
2018-05-21 22:10:43 +00:00
|
|
|
this._notifyOfStreamEnded();
|
2017-10-10 23:31:40 +00:00
|
|
|
stream.off(JitsiTrackEvents.LOCAL_TRACK_STOPPED, endedHandler);
|
2016-01-06 22:39:13 +00:00
|
|
|
};
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2017-10-10 23:31:40 +00:00
|
|
|
stream.on(JitsiTrackEvents.LOCAL_TRACK_STOPPED, endedHandler);
|
2015-07-20 17:32:04 +00:00
|
|
|
};
|
2015-06-23 08:00:46 +00:00
|
|
|
|
2018-05-21 22:10:43 +00:00
|
|
|
/**
|
|
|
|
* Notify any subscribers of the local video stream ending.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
LocalVideo.prototype._notifyOfStreamEnded = function() {
|
|
|
|
if (this.streamEndedCallback) {
|
|
|
|
this.streamEndedCallback(this.id);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-01 18:35:18 +00:00
|
|
|
/**
|
|
|
|
* Shows or hides the local video container.
|
|
|
|
* @param {boolean} true to make the local video container visible, false
|
|
|
|
* otherwise
|
|
|
|
*/
|
|
|
|
LocalVideo.prototype.setVisible = function(visible) {
|
|
|
|
|
|
|
|
// We toggle the hidden class as an indication to other interested parties
|
|
|
|
// that this container has been hidden on purpose.
|
2017-10-12 23:02:29 +00:00
|
|
|
this.$container.toggleClass('hidden');
|
2016-05-01 18:35:18 +00:00
|
|
|
|
|
|
|
// We still show/hide it as we need to overwrite the style property if we
|
|
|
|
// want our action to take effect. Toggling the display property through
|
|
|
|
// the above css class didn't succeed in overwriting the style.
|
|
|
|
if (visible) {
|
2017-06-30 23:07:37 +00:00
|
|
|
this.$container.show();
|
2017-10-12 23:02:29 +00:00
|
|
|
} else {
|
2017-06-30 23:07:37 +00:00
|
|
|
this.$container.hide();
|
2016-05-01 18:35:18 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-07 01:50:37 +00:00
|
|
|
/**
|
|
|
|
* Sets the flipX state of the video.
|
|
|
|
* @param val {boolean} true for flipped otherwise false;
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
LocalVideo.prototype.setFlipX = function(val) {
|
2016-05-07 01:50:37 +00:00
|
|
|
this.emitter.emit(UIEvents.LOCAL_FLIPX_CHANGED, val);
|
2017-10-12 23:02:29 +00:00
|
|
|
if (!this.localVideoId) {
|
2016-05-07 01:50:37 +00:00
|
|
|
return;
|
2017-10-12 23:02:29 +00:00
|
|
|
}
|
|
|
|
if (val) {
|
|
|
|
this.selectVideoElement().addClass('flipVideoX');
|
2016-05-07 01:50:37 +00:00
|
|
|
} else {
|
2017-10-12 23:02:29 +00:00
|
|
|
this.selectVideoElement().removeClass('flipVideoX');
|
2016-05-07 01:50:37 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the context menu for the local video.
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
LocalVideo.prototype._buildContextMenu = function() {
|
2016-05-07 01:50:37 +00:00
|
|
|
$.contextMenu({
|
2017-10-12 23:02:29 +00:00
|
|
|
selector: `#${this.videoSpanId}`,
|
2016-05-07 01:50:37 +00:00
|
|
|
zIndex: 10000,
|
|
|
|
items: {
|
|
|
|
flip: {
|
2017-10-12 23:02:29 +00:00
|
|
|
name: 'Flip',
|
2016-05-07 01:50:37 +00:00
|
|
|
callback: () => {
|
2018-04-12 19:58:20 +00:00
|
|
|
const { store } = APP;
|
|
|
|
const val = !store.getState()['features/base/settings']
|
|
|
|
.localFlipX;
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2016-05-07 01:50:37 +00:00
|
|
|
this.setFlipX(val);
|
2018-04-12 19:58:20 +00:00
|
|
|
store.dispatch(updateSettings({
|
|
|
|
localFlipX: val
|
|
|
|
}));
|
2016-05-07 01:50:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
events: {
|
2017-10-12 23:02:29 +00:00
|
|
|
show(options) {
|
|
|
|
options.items.flip.name
|
|
|
|
= APP.translation.generateTranslationHTML(
|
|
|
|
'videothumbnail.flip');
|
2016-05-07 01:50:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enables or disables the context menu for the local video.
|
|
|
|
* @param enable {boolean} true for enable, false for disable
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
LocalVideo.prototype._enableDisableContextMenu = function(enable) {
|
|
|
|
if (this.$container.contextMenu) {
|
2017-06-30 23:07:37 +00:00
|
|
|
this.$container.contextMenu(enable);
|
2017-10-12 23:02:29 +00:00
|
|
|
}
|
2016-05-07 01:50:37 +00:00
|
|
|
};
|
|
|
|
|
2018-08-08 18:48:23 +00:00
|
|
|
/**
|
|
|
|
* Places the {@code LocalVideo} in the DOM based on the current video layout.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
LocalVideo.prototype.updateDOMLocation = function() {
|
|
|
|
if (!this.container) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.container.parentElement) {
|
|
|
|
this.container.parentElement.removeChild(this.container);
|
|
|
|
}
|
|
|
|
|
|
|
|
const appendTarget = shouldDisplayTileView(APP.store.getState())
|
|
|
|
? document.getElementById('localVideoTileViewContainer')
|
|
|
|
: document.getElementById('filmstripLocalVideoThumbnail');
|
|
|
|
|
|
|
|
appendTarget && appendTarget.appendChild(this.container);
|
|
|
|
|
|
|
|
this._updateVideoElement();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the React Element for displaying video in {@code LocalVideo}.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
LocalVideo.prototype._updateVideoElement = function() {
|
|
|
|
const localVideoContainer = document.getElementById('localVideoWrapper');
|
fix(tile-view): prevent local participant being selected on pin exit
On tile view enter/exit, local video is moved in the DOM (an effect
of not being reactified and moving being easier) and play is called
on its video element. The race condition setup is such: in tile
view with other participants and local video is on large (not
visible in the UI but visible in the app state and pip popout).
The race is such: pin a remote video, large video update is queued,
tile view is exited, local video is moved, play is called,,
onVideoPlaying callback executed, middleware fires mute update,
which checks if local is on large (it is), previous large video
update is cleared, and local is placed on large.
The fix is ensuring the redux representation of local video is
passed in, which holds the boolean videoStarted, which prevents
the onVideoPlaying callback from firing on subsequent plays.
2018-11-27 22:13:47 +00:00
|
|
|
const videoTrack
|
|
|
|
= getLocalVideoTrack(APP.store.getState()['features/base/tracks']);
|
2018-08-08 18:48:23 +00:00
|
|
|
|
|
|
|
ReactDOM.render(
|
|
|
|
<Provider store = { APP.store }>
|
|
|
|
<VideoTrack
|
|
|
|
id = 'localVideo_container'
|
fix(tile-view): prevent local participant being selected on pin exit
On tile view enter/exit, local video is moved in the DOM (an effect
of not being reactified and moving being easier) and play is called
on its video element. The race condition setup is such: in tile
view with other participants and local video is on large (not
visible in the UI but visible in the app state and pip popout).
The race is such: pin a remote video, large video update is queued,
tile view is exited, local video is moved, play is called,,
onVideoPlaying callback executed, middleware fires mute update,
which checks if local is on large (it is), previous large video
update is cleared, and local is placed on large.
The fix is ensuring the redux representation of local video is
passed in, which holds the boolean videoStarted, which prevents
the onVideoPlaying callback from firing on subsequent plays.
2018-11-27 22:13:47 +00:00
|
|
|
videoTrack = { videoTrack } />
|
2018-08-08 18:48:23 +00:00
|
|
|
</Provider>,
|
|
|
|
localVideoContainer
|
|
|
|
);
|
|
|
|
|
|
|
|
// Ensure the video gets play() called on it. This may be necessary in the
|
|
|
|
// case where the local video container was moved and re-attached, in which
|
|
|
|
// case video does not autoplay.
|
|
|
|
const video = this.container.querySelector('video');
|
|
|
|
|
|
|
|
video && video.play();
|
|
|
|
};
|
|
|
|
|
2015-12-14 12:26:50 +00:00
|
|
|
export default LocalVideo;
|