12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208 |
- /* global APP, $, interfaceConfig */
- const logger = require('jitsi-meet-logger').getLogger(__filename);
-
- import {
- getNearestReceiverVideoQualityLevel,
- setMaxReceiverVideoQuality
- } from '../../../react/features/base/conference';
- import {
- JitsiParticipantConnectionStatus
- } from '../../../react/features/base/lib-jitsi-meet';
- import { VIDEO_TYPE } from '../../../react/features/base/media';
- import {
- getLocalParticipant as getLocalParticipantFromStore,
- getPinnedParticipant,
- pinParticipant
- } from '../../../react/features/base/participants';
- import {
- shouldDisplayTileView
- } from '../../../react/features/video-layout';
- import { SHARED_VIDEO_CONTAINER_TYPE } from '../shared_video/SharedVideo';
- import SharedVideoThumb from '../shared_video/SharedVideoThumb';
-
- import Filmstrip from './Filmstrip';
- import UIEvents from '../../../service/UI/UIEvents';
- import UIUtil from '../util/UIUtil';
-
- import RemoteVideo from './RemoteVideo';
- import LargeVideoManager from './LargeVideoManager';
- import { VIDEO_CONTAINER_TYPE } from './VideoContainer';
-
- import LocalVideo from './LocalVideo';
-
- const remoteVideos = {};
- let localVideoThumbnail = null;
-
- let eventEmitter = null;
-
- let largeVideo;
-
- /**
- * flipX state of the localVideo
- */
- let localFlipX = null;
-
- /**
- * Handler for local flip X changed event.
- * @param {Object} val
- */
- function onLocalFlipXChanged(val) {
- localFlipX = val;
- if (largeVideo) {
- largeVideo.onLocalFlipXChange(val);
- }
- }
-
- /**
- * Returns the redux representation of all known users.
- *
- * @private
- * @returns {Array}
- */
- function getAllParticipants() {
- return APP.store.getState()['features/base/participants'];
- }
-
- /**
- * Returns an array of all thumbnails in the filmstrip.
- *
- * @private
- * @returns {Array}
- */
- function getAllThumbnails() {
- return [
- localVideoThumbnail,
- ...Object.values(remoteVideos)
- ];
- }
-
- /**
- * Private helper to get the redux representation of the local participant.
- *
- * @private
- * @returns {Object}
- */
- function getLocalParticipant() {
- return getLocalParticipantFromStore(APP.store.getState());
- }
-
- /**
- * Returns the user ID of the remote participant that is current the dominant
- * speaker.
- *
- * @private
- * @returns {string|null}
- */
- function getCurrentRemoteDominantSpeakerID() {
- const dominantSpeaker = getAllParticipants()
- .find(participant => participant.dominantSpeaker);
-
- if (dominantSpeaker) {
- return dominantSpeaker.local ? null : dominantSpeaker.id;
- }
-
- return null;
- }
-
- /**
- * Returns the corresponding resource id to the given peer container
- * DOM element.
- *
- * @return the corresponding resource id to the given peer container
- * DOM element
- */
- function getPeerContainerResourceId(containerElement) {
- if (localVideoThumbnail.container === containerElement) {
- return localVideoThumbnail.id;
- }
-
- const i = containerElement.id.indexOf('participant_');
-
- if (i >= 0) {
- return containerElement.id.substring(i + 12);
- }
- }
-
- const VideoLayout = {
- init(emitter) {
- eventEmitter = emitter;
-
- localVideoThumbnail = new LocalVideo(
- VideoLayout,
- emitter,
- this._updateLargeVideoIfDisplayed.bind(this));
-
- // sets default video type of local video
- // FIXME container type is totally different thing from the video type
- localVideoThumbnail.setVideoType(VIDEO_CONTAINER_TYPE);
-
- // if we do not resize the thumbs here, if there is no video device
- // the local video thumb maybe one pixel
- this.resizeThumbnails(true);
-
- this.registerListeners();
- },
-
- /**
- * Registering listeners for UI events in Video layout component.
- *
- * @returns {void}
- */
- registerListeners() {
- eventEmitter.addListener(UIEvents.LOCAL_FLIPX_CHANGED,
- onLocalFlipXChanged);
- },
-
- /**
- * Cleans up state of this singleton {@code VideoLayout}.
- *
- * @returns {void}
- */
- reset() {
- this._resetLargeVideo();
- this._resetFilmstrip();
- },
-
- initLargeVideo() {
- this._resetLargeVideo();
-
- largeVideo = new LargeVideoManager(eventEmitter);
- if (localFlipX) {
- largeVideo.onLocalFlipXChange(localFlipX);
- }
- largeVideo.updateContainerSize();
- },
-
- /**
- * Sets the audio level of the video elements associated to the given id.
- *
- * @param id the video identifier in the form it comes from the library
- * @param lvl the new audio level to update to
- */
- setAudioLevel(id, lvl) {
- const smallVideo = this.getSmallVideo(id);
-
- if (smallVideo) {
- smallVideo.updateAudioLevelIndicator(lvl);
- }
-
- if (largeVideo && id === largeVideo.id) {
- largeVideo.updateLargeVideoAudioLevel(lvl);
- }
- },
-
- changeLocalVideo(stream) {
- const localId = getLocalParticipant().id;
-
- this.onVideoTypeChanged(localId, stream.videoType);
-
- localVideoThumbnail.changeVideo(stream);
-
- this._updateLargeVideoIfDisplayed(localId);
- },
-
- /**
- * Get's the localID of the conference and set it to the local video
- * (small one). This needs to be called as early as possible, when muc is
- * actually joined. Otherwise events can come with information like email
- * and setting them assume the id is already set.
- */
- mucJoined() {
- if (largeVideo && !largeVideo.id) {
- this.updateLargeVideo(getLocalParticipant().id, true);
- }
-
- // FIXME: replace this call with a generic update call once SmallVideo
- // only contains a ReactElement. Then remove this call once the
- // Filmstrip is fully in React.
- localVideoThumbnail.updateIndicators();
- },
-
- /**
- * Adds or removes icons for not available camera and microphone.
- * @param resourceJid the jid of user
- * @param devices available devices
- */
- setDeviceAvailabilityIcons(id, devices) {
- if (APP.conference.isLocalId(id)) {
- localVideoThumbnail.setDeviceAvailabilityIcons(devices);
-
- return;
- }
-
- const video = remoteVideos[id];
-
- if (!video) {
- return;
- }
-
- video.setDeviceAvailabilityIcons(devices);
- },
-
- /**
- * Shows/hides local video.
- * @param {boolean} true to make the local video visible, false - otherwise
- */
- setLocalVideoVisible(visible) {
- localVideoThumbnail.setVisible(visible);
- },
-
- /**
- * Checks if removed video is currently displayed and tries to display
- * another one instead.
- * Uses focusedID if any or dominantSpeakerID if any,
- * otherwise elects new video, in this order.
- */
- _updateAfterThumbRemoved(id) {
- // Always trigger an update if large video is empty.
- if (!largeVideo
- || (this.getLargeVideoID() && !this.isCurrentlyOnLarge(id))) {
- return;
- }
-
- const pinnedId = this.getPinnedId();
- let newId;
-
- if (pinnedId) {
- newId = pinnedId;
- } else if (getCurrentRemoteDominantSpeakerID()) {
- newId = getCurrentRemoteDominantSpeakerID();
- } else { // Otherwise select last visible video
- newId = this.electLastVisibleVideo();
- }
-
- this.updateLargeVideo(newId);
- },
-
- electLastVisibleVideo() {
- // pick the last visible video in the row
- // if nobody else is left, this picks the local video
- const remoteThumbs = Filmstrip.getThumbs(true).remoteThumbs;
- let thumbs = remoteThumbs.filter('[id!="mixedstream"]');
-
- const lastVisible = thumbs.filter(':visible:last');
-
- if (lastVisible.length) {
- const id = getPeerContainerResourceId(lastVisible[0]);
-
- if (remoteVideos[id]) {
- logger.info(`electLastVisibleVideo: ${id}`);
-
- return id;
- }
-
- // The RemoteVideo was removed (but the DOM elements may still
- // exist).
- }
-
- logger.info('Last visible video no longer exists');
- thumbs = Filmstrip.getThumbs().remoteThumbs;
- if (thumbs.length) {
- const id = getPeerContainerResourceId(thumbs[0]);
-
- if (remoteVideos[id]) {
- logger.info(`electLastVisibleVideo: ${id}`);
-
- return id;
- }
-
- // The RemoteVideo was removed (but the DOM elements may
- // still exist).
- }
-
- // Go with local video
- logger.info('Fallback to local video...');
-
- const { id } = getLocalParticipant();
-
- logger.info(`electLastVisibleVideo: ${id}`);
-
- return id;
- },
-
- onRemoteStreamAdded(stream) {
- const id = stream.getParticipantId();
- const remoteVideo = remoteVideos[id];
-
- if (!remoteVideo) {
- return;
- }
-
- remoteVideo.addRemoteStreamElement(stream);
-
- // Make sure track's muted state is reflected
- if (stream.getType() === 'audio') {
- this.onAudioMute(stream.getParticipantId(), stream.isMuted());
- } else {
- this.onVideoMute(stream.getParticipantId(), stream.isMuted());
- }
- },
-
- onRemoteStreamRemoved(stream) {
- const id = stream.getParticipantId();
- const remoteVideo = remoteVideos[id];
-
- // Remote stream may be removed after participant left the conference.
-
- if (remoteVideo) {
- remoteVideo.removeRemoteStreamElement(stream);
- }
-
- this.updateMutedForNoTracks(id, stream.getType());
- },
-
- /**
- * FIXME get rid of this method once muted indicator are reactified (by
- * making sure that user with no tracks is displayed as muted )
- *
- * If participant has no tracks will make the UI display muted status.
- * @param {string} participantId
- * @param {string} mediaType 'audio' or 'video'
- */
- updateMutedForNoTracks(participantId, mediaType) {
- const participant = APP.conference.getParticipantById(participantId);
-
- if (participant
- && !participant.getTracksByMediaType(mediaType).length) {
- if (mediaType === 'audio') {
- APP.UI.setAudioMuted(participantId, true);
- } else if (mediaType === 'video') {
- APP.UI.setVideoMuted(participantId, true);
- } else {
- logger.error(`Unsupported media type: ${mediaType}`);
- }
- }
- },
-
- /**
- * Return the type of the remote video.
- * @param id the id for the remote video
- * @returns {String} the video type video or screen.
- */
- getRemoteVideoType(id) {
- const smallVideo = VideoLayout.getSmallVideo(id);
-
-
- return smallVideo ? smallVideo.getVideoType() : null;
- },
-
- isPinned(id) {
- return id === this.getPinnedId();
- },
-
- getPinnedId() {
- const { id } = getPinnedParticipant(APP.store.getState()) || {};
-
- return id || null;
- },
-
- /**
- * Triggers a thumbnail to pin or unpin itself.
- *
- * @param {number} videoNumber - The index of the video to toggle pin on.
- * @private
- */
- togglePin(videoNumber) {
- const videos = getAllThumbnails();
- const videoView = videos[videoNumber];
-
- videoView && videoView.togglePin();
- },
-
- /**
- * Callback invoked to update display when the pin participant has changed.
- *
- * @paramn {string|null} pinnedParticipantID - The participant ID of the
- * participant that is pinned or null if no one is pinned.
- * @returns {void}
- */
- onPinChange(pinnedParticipantID) {
- if (interfaceConfig.filmStripOnly) {
- return;
- }
-
- getAllThumbnails().forEach(thumbnail =>
- thumbnail.focus(pinnedParticipantID === thumbnail.getId()));
-
- if (pinnedParticipantID) {
- this.updateLargeVideo(pinnedParticipantID);
- } else {
- const currentDominantSpeakerID
- = getCurrentRemoteDominantSpeakerID();
-
- if (currentDominantSpeakerID) {
- this.updateLargeVideo(currentDominantSpeakerID);
- } else {
- // if there is no currentDominantSpeakerID, it can also be
- // that local participant is the dominant speaker
- // we should act as a participant has left and was on large
- // and we should choose somebody (electLastVisibleVideo)
- this.updateLargeVideo(this.electLastVisibleVideo());
- }
- }
- },
-
- /**
- * Creates a participant container for the given id.
- *
- * @param {Object} participant - The redux representation of a remote
- * participant.
- * @returns {void}
- */
- addRemoteParticipantContainer(participant) {
- if (!participant || participant.local) {
- return;
- } else if (participant.isFakeParticipant) {
- const sharedVideoThumb = new SharedVideoThumb(
- participant,
- SHARED_VIDEO_CONTAINER_TYPE,
- VideoLayout);
-
- this.addRemoteVideoContainer(participant.id, sharedVideoThumb);
-
- return;
- }
-
- const id = participant.id;
- const jitsiParticipant = APP.conference.getParticipantById(id);
- const remoteVideo
- = new RemoteVideo(jitsiParticipant, VideoLayout, eventEmitter);
-
- this._setRemoteControlProperties(jitsiParticipant, remoteVideo);
- this.addRemoteVideoContainer(id, remoteVideo);
-
- this.updateMutedForNoTracks(id, 'audio');
- this.updateMutedForNoTracks(id, 'video');
-
- const remoteVideosCount = Object.keys(remoteVideos).length;
-
- if (remoteVideosCount === 1) {
- window.setTimeout(() => {
- const updatedRemoteVideosCount
- = Object.keys(remoteVideos).length;
-
- if (updatedRemoteVideosCount === 1 && remoteVideos[id]) {
- this._maybePlaceParticipantOnLargeVideo(id);
- }
- }, 3000);
- }
- },
-
- /**
- * Adds remote video container for the given id and <tt>SmallVideo</tt>.
- *
- * @param {string} the id of the video to add
- * @param {SmallVideo} smallVideo the small video instance to add as a
- * remote video
- */
- addRemoteVideoContainer(id, remoteVideo) {
- remoteVideos[id] = remoteVideo;
-
- if (!remoteVideo.getVideoType()) {
- // make video type the default one (camera)
- // FIXME container type is not a video type
- remoteVideo.setVideoType(VIDEO_CONTAINER_TYPE);
- }
-
- VideoLayout.resizeThumbnails(true);
-
- // Initialize the view
- remoteVideo.updateView();
- },
-
- // FIXME: what does this do???
- remoteVideoActive(videoElement, resourceJid) {
-
- logger.info(`${resourceJid} video is now active`, videoElement);
-
- VideoLayout.resizeThumbnails(
- false, () => {
- if (videoElement) {
- $(videoElement).show();
- }
- });
-
- this._maybePlaceParticipantOnLargeVideo(resourceJid);
- },
-
- /**
- * Update the large video to the last added video only if there's no current
- * dominant, focused speaker or update it to the current dominant speaker.
- *
- * @params {string} resourceJid - The id of the user to maybe display on
- * large video.
- * @returns {void}
- */
- _maybePlaceParticipantOnLargeVideo(resourceJid) {
- const pinnedId = this.getPinnedId();
-
- if ((!pinnedId
- && !getCurrentRemoteDominantSpeakerID()
- && this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE))
- || pinnedId === resourceJid
- || (!pinnedId && resourceJid
- && getCurrentRemoteDominantSpeakerID() === resourceJid)
-
- /* Playback started while we're on the stage - may need to update
- video source with the new stream */
- || this.isCurrentlyOnLarge(resourceJid)) {
-
- this.updateLargeVideo(resourceJid, true);
- }
- },
-
- /**
- * Shows a visual indicator for the moderator of the conference.
- * On local or remote participants.
- */
- showModeratorIndicator() {
- const isModerator = APP.conference.isModerator;
-
- if (isModerator) {
- localVideoThumbnail.addModeratorIndicator();
- } else {
- localVideoThumbnail.removeModeratorIndicator();
- }
-
- APP.conference.listMembers().forEach(member => {
- const id = member.getId();
- const remoteVideo = remoteVideos[id];
-
- if (!remoteVideo) {
- return;
- }
-
- if (member.isModerator()) {
- remoteVideo.addModeratorIndicator();
- }
-
- remoteVideo.updateRemoteVideoMenu();
- });
- },
-
- /*
- * Shows or hides the audio muted indicator over the local thumbnail video.
- * @param {boolean} isMuted
- */
- showLocalAudioIndicator(isMuted) {
- localVideoThumbnail.showAudioIndicator(isMuted);
- },
-
- /**
- * Resizes thumbnails.
- */
- resizeThumbnails(
- forceUpdate = false,
- onComplete = null) {
- const { localVideo, remoteVideo }
- = Filmstrip.calculateThumbnailSize();
-
- Filmstrip.resizeThumbnails(localVideo, remoteVideo, forceUpdate);
-
- if (shouldDisplayTileView(APP.store.getState())) {
- const height
- = (localVideo && localVideo.thumbHeight)
- || (remoteVideo && remoteVideo.thumbnHeight)
- || 0;
- const qualityLevel = getNearestReceiverVideoQualityLevel(height);
-
- APP.store.dispatch(setMaxReceiverVideoQuality(qualityLevel));
- }
-
- if (onComplete && typeof onComplete === 'function') {
- onComplete();
- }
- },
-
- /**
- * On audio muted event.
- */
- onAudioMute(id, isMuted) {
- if (APP.conference.isLocalId(id)) {
- localVideoThumbnail.showAudioIndicator(isMuted);
- } else {
- const remoteVideo = remoteVideos[id];
-
- if (!remoteVideo) {
- return;
- }
-
- remoteVideo.showAudioIndicator(isMuted);
- remoteVideo.updateRemoteVideoMenu(isMuted);
- }
- },
-
- /**
- * On video muted event.
- */
- onVideoMute(id, value) {
- if (APP.conference.isLocalId(id)) {
- localVideoThumbnail && localVideoThumbnail.setVideoMutedView(value);
- } else {
- const remoteVideo = remoteVideos[id];
-
- if (remoteVideo) {
- remoteVideo.setVideoMutedView(value);
- }
- }
-
- if (this.isCurrentlyOnLarge(id)) {
- // large video will show avatar instead of muted stream
- this.updateLargeVideo(id, true);
- }
- },
-
- /**
- * Display name changed.
- */
- onDisplayNameChanged(id) {
- if (id === 'localVideoContainer'
- || APP.conference.isLocalId(id)) {
- localVideoThumbnail.updateDisplayName();
- } else {
- const remoteVideo = remoteVideos[id];
-
- if (remoteVideo) {
- remoteVideo.updateDisplayName();
- }
- }
- },
-
- /**
- * On dominant speaker changed event.
- *
- * @param {string} id - The participant ID of the new dominant speaker.
- * @returns {void}
- */
- onDominantSpeakerChanged(id) {
- getAllThumbnails().forEach(thumbnail =>
- thumbnail.showDominantSpeakerIndicator(id === thumbnail.getId()));
-
-
- if (!remoteVideos[id]) {
- return;
- }
-
- // Local video will not have container found, but that's ok
- // since we don't want to switch to local video.
- if (!interfaceConfig.filmStripOnly && !this.getPinnedId()
- && !this.getCurrentlyOnLargeContainer().stayOnStage()) {
- this.updateLargeVideo(id);
- }
- },
-
- /**
- * Shows/hides warning about a user's connectivity issues.
- *
- * @param {string} id - The ID of the remote participant(MUC nickname).
- * @param {status} status - The new connection status.
- * @returns {void}
- */
- onParticipantConnectionStatusChanged(id, status) {
- if (APP.conference.isLocalId(id)) {
- // Maintain old logic of passing in either interrupted or active
- // to updateConnectionStatus.
- localVideoThumbnail.updateConnectionStatus(status);
-
- if (status === JitsiParticipantConnectionStatus.INTERRUPTED) {
- largeVideo && largeVideo.onVideoInterrupted();
- } else {
- largeVideo && largeVideo.onVideoRestored();
- }
-
- return;
- }
-
- // We have to trigger full large video update to transition from
- // avatar to video on connectivity restored.
- this._updateLargeVideoIfDisplayed(id, true);
-
- const remoteVideo = remoteVideos[id];
-
- if (remoteVideo) {
- // Updating only connection status indicator is not enough, because
- // when we the connection is restored while the avatar was displayed
- // (due to 'muted while disconnected' condition) we may want to show
- // the video stream again and in order to do that the display mode
- // must be updated.
- // remoteVideo.updateConnectionStatusIndicator(isActive);
- remoteVideo.updateView();
- }
- },
-
- /**
- * On last N change event.
- *
- * @param endpointsLeavingLastN the list currently leaving last N
- * endpoints
- * @param endpointsEnteringLastN the list currently entering last N
- * endpoints
- */
- onLastNEndpointsChanged(endpointsLeavingLastN, endpointsEnteringLastN) {
- if (endpointsLeavingLastN) {
- endpointsLeavingLastN.forEach(this._updateRemoteVideo, this);
- }
-
- if (endpointsEnteringLastN) {
- endpointsEnteringLastN.forEach(this._updateRemoteVideo, this);
- }
- },
-
- /**
- * Updates remote video by id if it exists.
- * @param {string} id of the remote video
- * @private
- */
- _updateRemoteVideo(id) {
- const remoteVideo = remoteVideos[id];
-
- if (remoteVideo) {
- remoteVideo.updateView();
- if (remoteVideo.isCurrentlyOnLargeVideo()) {
- this.updateLargeVideo(id);
- }
- }
- },
-
- /**
- * Hides the connection indicator
- * @param id
- */
- hideConnectionIndicator(id) {
- const remoteVideo = remoteVideos[id];
-
- if (remoteVideo) {
- remoteVideo.removeConnectionIndicator();
- }
- },
-
- /**
- * Hides all the indicators
- */
- hideStats() {
- for (const video in remoteVideos) { // eslint-disable-line guard-for-in
- const remoteVideo = remoteVideos[video];
-
- if (remoteVideo) {
- remoteVideo.removeConnectionIndicator();
- }
- }
- localVideoThumbnail.removeConnectionIndicator();
- },
-
- removeParticipantContainer(id) {
- // Unlock large video
- if (this.getPinnedId() === id) {
- logger.info('Focused video owner has left the conference');
- APP.store.dispatch(pinParticipant(null));
- }
-
- const remoteVideo = remoteVideos[id];
-
- if (remoteVideo) {
- // Remove remote video
- logger.info(`Removing remote video: ${id}`);
- delete remoteVideos[id];
- remoteVideo.remove();
- } else {
- logger.warn(`No remote video for ${id}`);
- }
-
- VideoLayout.resizeThumbnails();
- VideoLayout._updateAfterThumbRemoved(id);
- },
-
- onVideoTypeChanged(id, newVideoType) {
- if (VideoLayout.getRemoteVideoType(id) === newVideoType) {
- return;
- }
-
- logger.info('Peer video type changed: ', id, newVideoType);
-
- let smallVideo;
-
- if (APP.conference.isLocalId(id)) {
- if (!localVideoThumbnail) {
- logger.warn('Local video not ready yet');
-
- return;
- }
- smallVideo = localVideoThumbnail;
- } else if (remoteVideos[id]) {
- smallVideo = remoteVideos[id];
- } else {
- return;
- }
- smallVideo.setVideoType(newVideoType);
-
- if (this.isCurrentlyOnLarge(id)) {
- this.updateLargeVideo(id, true);
- }
- },
-
- /**
- * Resizes the video area.
- *
- * TODO: Remove the "animate" param as it is no longer passed in as true.
- *
- * @param forceUpdate indicates that hidden thumbnails will be shown
- */
- resizeVideoArea(
- forceUpdate = false,
- animate = false) {
- // Resize the thumbnails first.
- this.resizeThumbnails(forceUpdate);
-
- if (largeVideo) {
- largeVideo.updateContainerSize();
- largeVideo.resize(animate);
- }
-
- // Calculate available width and height.
- const availableHeight = window.innerHeight;
- const availableWidth = UIUtil.getAvailableVideoWidth();
-
- if (availableWidth < 0 || availableHeight < 0) {
- return;
- }
- },
-
- getSmallVideo(id) {
- if (APP.conference.isLocalId(id)) {
- return localVideoThumbnail;
- }
-
- return remoteVideos[id];
-
- },
-
- changeUserAvatar(id, avatarUrl) {
- const smallVideo = VideoLayout.getSmallVideo(id);
-
- if (smallVideo) {
- smallVideo.initializeAvatar();
- } else {
- logger.warn(
- `Missed avatar update - no small video yet for ${id}`
- );
- }
- if (this.isCurrentlyOnLarge(id)) {
- largeVideo.updateAvatar(avatarUrl);
- }
- },
-
- isLargeVideoVisible() {
- return this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE);
- },
-
- /**
- * @return {LargeContainer} the currently displayed container on large
- * video.
- */
- getCurrentlyOnLargeContainer() {
- return largeVideo.getCurrentContainer();
- },
-
- isCurrentlyOnLarge(id) {
- return largeVideo && largeVideo.id === id;
- },
-
- /**
- * Triggers an update of remote video and large video displays so they may
- * pick up any state changes that have occurred elsewhere.
- *
- * @returns {void}
- */
- updateAllVideos() {
- const displayedUserId = this.getLargeVideoID();
-
- if (displayedUserId) {
- this.updateLargeVideo(displayedUserId, true);
- }
-
- Object.keys(remoteVideos).forEach(video => {
- remoteVideos[video].updateView();
- });
- },
-
- updateLargeVideo(id, forceUpdate) {
- if (!largeVideo) {
- return;
- }
- const currentContainer = largeVideo.getCurrentContainer();
- const currentContainerType = largeVideo.getCurrentContainerType();
- const currentId = largeVideo.id;
- const isOnLarge = this.isCurrentlyOnLarge(id);
- const smallVideo = this.getSmallVideo(id);
-
- if (isOnLarge && !forceUpdate
- && LargeVideoManager.isVideoContainer(currentContainerType)
- && smallVideo) {
- const currentStreamId = currentContainer.getStreamID();
- const newStreamId
- = smallVideo.videoStream
- ? smallVideo.videoStream.getId() : null;
-
- // FIXME it might be possible to get rid of 'forceUpdate' argument
- if (currentStreamId !== newStreamId) {
- logger.debug('Enforcing large video update for stream change');
- forceUpdate = true; // eslint-disable-line no-param-reassign
- }
- }
-
- if ((!isOnLarge || forceUpdate) && smallVideo) {
- const videoType = this.getRemoteVideoType(id);
-
- // FIXME video type is not the same thing as container type
-
- if (id !== currentId && videoType === VIDEO_CONTAINER_TYPE) {
- APP.API.notifyOnStageParticipantChanged(id);
- }
-
- let oldSmallVideo;
-
- if (currentId) {
- oldSmallVideo = this.getSmallVideo(currentId);
- }
-
- smallVideo.waitForResolutionChange();
- if (oldSmallVideo) {
- oldSmallVideo.waitForResolutionChange();
- }
-
- largeVideo.updateLargeVideo(
- id,
- smallVideo.videoStream,
- videoType || VIDEO_TYPE.CAMERA
- ).then(() => {
- // update current small video and the old one
- smallVideo.updateView();
- oldSmallVideo && oldSmallVideo.updateView();
- }, () => {
- // use clicked other video during update, nothing to do.
- });
-
- } else if (currentId) {
- const currentSmallVideo = this.getSmallVideo(currentId);
-
- currentSmallVideo && currentSmallVideo.updateView();
- }
- },
-
- addLargeVideoContainer(type, container) {
- largeVideo && largeVideo.addContainer(type, container);
- },
-
- removeLargeVideoContainer(type) {
- largeVideo && largeVideo.removeContainer(type);
- },
-
- /**
- * @returns Promise
- */
- showLargeVideoContainer(type, show) {
- if (!largeVideo) {
- return Promise.reject();
- }
-
- const isVisible = this.isLargeContainerTypeVisible(type);
-
- if (isVisible === show) {
- return Promise.resolve();
- }
-
- const currentId = largeVideo.id;
- let oldSmallVideo;
-
- if (currentId) {
- oldSmallVideo = this.getSmallVideo(currentId);
- }
-
- let containerTypeToShow = type;
-
- // if we are hiding a container and there is focusedVideo
- // (pinned remote video) use its video type,
- // if not then use default type - large video
-
- if (!show) {
- const pinnedId = this.getPinnedId();
-
- if (pinnedId) {
- containerTypeToShow = this.getRemoteVideoType(pinnedId);
- } else {
- containerTypeToShow = VIDEO_CONTAINER_TYPE;
- }
- }
-
- return largeVideo.showContainer(containerTypeToShow)
- .then(() => {
- if (oldSmallVideo) {
- oldSmallVideo && oldSmallVideo.updateView();
- }
- });
- },
-
- isLargeContainerTypeVisible(type) {
- return largeVideo && largeVideo.state === type;
- },
-
- /**
- * Returns the id of the current video shown on large.
- * Currently used by tests (torture).
- */
- getLargeVideoID() {
- return largeVideo && largeVideo.id;
- },
-
- /**
- * Returns the the current video shown on large.
- * Currently used by tests (torture).
- */
- getLargeVideo() {
- return largeVideo;
- },
-
- /**
- * Sets the flipX state of the local video.
- * @param {boolean} true for flipped otherwise false;
- */
- setLocalFlipX(val) {
- this.localFlipX = val;
- },
-
- getEventEmitter() {
- return eventEmitter;
- },
-
- /**
- * Handles user's features changes.
- */
- onUserFeaturesChanged(user) {
- const video = this.getSmallVideo(user.getId());
-
- if (!video) {
- return;
- }
- this._setRemoteControlProperties(user, video);
- },
-
- /**
- * Sets the remote control properties (checks whether remote control
- * is supported and executes remoteVideo.setRemoteControlSupport).
- * @param {JitsiParticipant} user the user that will be checked for remote
- * control support.
- * @param {RemoteVideo} remoteVideo the remoteVideo on which the properties
- * will be set.
- */
- _setRemoteControlProperties(user, remoteVideo) {
- APP.remoteControl.checkUserRemoteControlSupport(user).then(result =>
- remoteVideo.setRemoteControlSupport(result));
- },
-
- /**
- * Returns the wrapper jquery selector for the largeVideo
- * @returns {JQuerySelector} the wrapper jquery selector for the largeVideo
- */
- getLargeVideoWrapper() {
- return this.getCurrentlyOnLargeContainer().$wrapper;
- },
-
- /**
- * Returns the number of remove video ids.
- *
- * @returns {number} The number of remote videos.
- */
- getRemoteVideosCount() {
- return Object.keys(remoteVideos).length;
- },
-
- /**
- * Sets the remote control active status for a remote participant.
- *
- * @param {string} participantID - The id of the remote participant.
- * @param {boolean} isActive - The new remote control active status.
- * @returns {void}
- */
- setRemoteControlActiveStatus(participantID, isActive) {
- remoteVideos[participantID].setRemoteControlActiveStatus(isActive);
- },
-
- /**
- * Sets the remote control active status for the local participant.
- *
- * @returns {void}
- */
- setLocalRemoteControlActiveChanged() {
- Object.values(remoteVideos).forEach(
- remoteVideo => remoteVideo.updateRemoteVideoMenu()
- );
- },
-
- /**
- * Helper method to invoke when the video layout has changed and elements
- * have to be re-arranged and resized.
- *
- * @returns {void}
- */
- refreshLayout() {
- localVideoThumbnail && localVideoThumbnail.updateDOMLocation();
- VideoLayout.resizeVideoArea();
-
- localVideoThumbnail && localVideoThumbnail.rerender();
- Object.values(remoteVideos).forEach(
- remoteVideo => remoteVideo.rerender()
- );
- },
-
- /**
- * Cleans up any existing largeVideo instance.
- *
- * @private
- * @returns {void}
- */
- _resetLargeVideo() {
- if (largeVideo) {
- largeVideo.destroy();
- }
-
- largeVideo = null;
- },
-
- /**
- * Cleans up filmstrip state. While a separate {@code Filmstrip} exists, its
- * implementation is mainly for querying and manipulating the DOM while
- * state mostly remains in {@code VideoLayout}.
- *
- * @private
- * @returns {void}
- */
- _resetFilmstrip() {
- Object.keys(remoteVideos).forEach(remoteVideoId => {
- this.removeParticipantContainer(remoteVideoId);
- delete remoteVideos[remoteVideoId];
- });
-
- if (localVideoThumbnail) {
- localVideoThumbnail.remove();
- localVideoThumbnail = null;
- }
- },
-
- /**
- * Triggers an update of large video if the passed in participant is
- * currently displayed on large video.
- *
- * @param {string} participantId - The participant ID that should trigger an
- * update of large video if displayed.
- * @param {boolean} force - Whether or not the large video update should
- * happen no matter what.
- * @returns {void}
- */
- _updateLargeVideoIfDisplayed(participantId, force = false) {
- if (this.isCurrentlyOnLarge(participantId)) {
- this.updateLargeVideo(participantId, force);
- }
- }
- };
-
- export default VideoLayout;
|