Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

VideoLayout.js 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  1. /* global APP, $, interfaceConfig, JitsiMeetJS */
  2. const logger = require("jitsi-meet-logger").getLogger(__filename);
  3. import {
  4. getPinnedParticipant,
  5. pinParticipant
  6. } from '../../../react/features/base/participants';
  7. import Filmstrip from "./Filmstrip";
  8. import UIEvents from "../../../service/UI/UIEvents";
  9. import UIUtil from "../util/UIUtil";
  10. import RemoteVideo from "./RemoteVideo";
  11. import LargeVideoManager from "./LargeVideoManager";
  12. import {VIDEO_CONTAINER_TYPE} from "./VideoContainer";
  13. import LocalVideo from "./LocalVideo";
  14. const ParticipantConnectionStatus
  15. = JitsiMeetJS.constants.participantConnectionStatus;
  16. var remoteVideos = {};
  17. var localVideoThumbnail = null;
  18. var currentDominantSpeaker = null;
  19. var eventEmitter = null;
  20. /**
  21. * flipX state of the localVideo
  22. */
  23. let localFlipX = null;
  24. /**
  25. * On contact list item clicked.
  26. */
  27. function onContactClicked (id) {
  28. if (APP.conference.isLocalId(id)) {
  29. $("#localVideoContainer").click();
  30. return;
  31. }
  32. let remoteVideo = remoteVideos[id];
  33. if (remoteVideo && remoteVideo.hasVideo()) {
  34. // It is not always the case that a videoThumb exists (if there is
  35. // no actual video).
  36. if (remoteVideo.hasVideoStarted()) {
  37. // We have a video src, great! Let's update the large video
  38. // now.
  39. VideoLayout.handleVideoThumbClicked(id);
  40. } else {
  41. // If we don't have a video src for jid, there's absolutely
  42. // no point in calling handleVideoThumbClicked; Quite
  43. // simply, it won't work because it needs an src to attach
  44. // to the large video.
  45. //
  46. // Instead, we trigger the pinned endpoint changed event to
  47. // let the bridge adjust its lastN set for myjid and store
  48. // the pinned user in the lastNPickupId variable to be
  49. // picked up later by the lastN changed event handler.
  50. this.pinParticipant(remoteVideo.id);
  51. }
  52. }
  53. }
  54. /**
  55. * Handler for local flip X changed event.
  56. * @param {Object} val
  57. */
  58. function onLocalFlipXChanged (val) {
  59. localFlipX = val;
  60. if(largeVideo) {
  61. largeVideo.onLocalFlipXChange(val);
  62. }
  63. }
  64. /**
  65. * Returns the corresponding resource id to the given peer container
  66. * DOM element.
  67. *
  68. * @return the corresponding resource id to the given peer container
  69. * DOM element
  70. */
  71. function getPeerContainerResourceId (containerElement) {
  72. if (localVideoThumbnail.container === containerElement) {
  73. return localVideoThumbnail.id;
  74. }
  75. let i = containerElement.id.indexOf('participant_');
  76. if (i >= 0) {
  77. return containerElement.id.substring(i + 12);
  78. }
  79. }
  80. let largeVideo;
  81. var VideoLayout = {
  82. init (emitter) {
  83. eventEmitter = emitter;
  84. // Unregister listeners in case of reinitialization
  85. this.unregisterListeners();
  86. localVideoThumbnail = new LocalVideo(VideoLayout, emitter);
  87. // sets default video type of local video
  88. // FIXME container type is totally different thing from the video type
  89. localVideoThumbnail.setVideoType(VIDEO_CONTAINER_TYPE);
  90. // if we do not resize the thumbs here, if there is no video device
  91. // the local video thumb maybe one pixel
  92. this.resizeThumbnails(false, true);
  93. this._onContactClicked = onContactClicked.bind(this);
  94. this.registerListeners();
  95. },
  96. /**
  97. * Cleans up any existing largeVideo instance.
  98. *
  99. * @returns {void}
  100. */
  101. resetLargeVideo() {
  102. if (largeVideo) {
  103. largeVideo.destroy();
  104. }
  105. largeVideo = null;
  106. },
  107. /**
  108. * Registering listeners for UI events in Video layout component.
  109. *
  110. * @returns {void}
  111. */
  112. registerListeners() {
  113. eventEmitter.addListener(UIEvents.LOCAL_FLIPX_CHANGED,
  114. onLocalFlipXChanged);
  115. eventEmitter.addListener(UIEvents.CONTACT_CLICKED,
  116. this._onContactClicked);
  117. },
  118. /**
  119. * Unregistering listeners for UI events in Video layout component.
  120. *
  121. * @returns {void}
  122. */
  123. unregisterListeners() {
  124. if (this._onContactClicked) {
  125. eventEmitter.removeListener(UIEvents.CONTACT_CLICKED,
  126. this._onContactClicked);
  127. }
  128. },
  129. initLargeVideo () {
  130. this.resetLargeVideo();
  131. largeVideo = new LargeVideoManager(eventEmitter);
  132. if(localFlipX) {
  133. largeVideo.onLocalFlipXChange(localFlipX);
  134. }
  135. largeVideo.updateContainerSize();
  136. },
  137. /**
  138. * Sets the audio level of the video elements associated to the given id.
  139. *
  140. * @param id the video identifier in the form it comes from the library
  141. * @param lvl the new audio level to update to
  142. */
  143. setAudioLevel(id, lvl) {
  144. let smallVideo = this.getSmallVideo(id);
  145. if (smallVideo)
  146. smallVideo.updateAudioLevelIndicator(lvl);
  147. if (largeVideo && id === largeVideo.id)
  148. largeVideo.updateLargeVideoAudioLevel(lvl);
  149. },
  150. changeLocalVideo (stream) {
  151. let localId = APP.conference.getMyUserId();
  152. this.onVideoTypeChanged(localId, stream.videoType);
  153. localVideoThumbnail.changeVideo(stream);
  154. /* Update if we're currently being displayed */
  155. if (this.isCurrentlyOnLarge(localId)) {
  156. this.updateLargeVideo(localId);
  157. }
  158. },
  159. /**
  160. * Get's the localID of the conference and set it to the local video
  161. * (small one). This needs to be called as early as possible, when muc is
  162. * actually joined. Otherwise events can come with information like email
  163. * and setting them assume the id is already set.
  164. */
  165. mucJoined () {
  166. if (largeVideo && !largeVideo.id) {
  167. this.updateLargeVideo(APP.conference.getMyUserId(), true);
  168. }
  169. // FIXME: replace this call with a generic update call once SmallVideo
  170. // only contains a ReactElement. Then remove this call once the
  171. // Filmstrip is fully in React.
  172. localVideoThumbnail.updateIndicators();
  173. },
  174. /**
  175. * Adds or removes icons for not available camera and microphone.
  176. * @param resourceJid the jid of user
  177. * @param devices available devices
  178. */
  179. setDeviceAvailabilityIcons (id, devices) {
  180. if (APP.conference.isLocalId(id)) {
  181. localVideoThumbnail.setDeviceAvailabilityIcons(devices);
  182. return;
  183. }
  184. let video = remoteVideos[id];
  185. if (!video) {
  186. return;
  187. }
  188. video.setDeviceAvailabilityIcons(devices);
  189. },
  190. /**
  191. * Enables/disables device availability icons for the given participant id.
  192. * The default value is {true}.
  193. * @param id the identifier of the participant
  194. * @param enable {true} to enable device availability icons
  195. */
  196. enableDeviceAvailabilityIcons (id, enable) {
  197. let video;
  198. if (APP.conference.isLocalId(id)) {
  199. video = localVideoThumbnail;
  200. }
  201. else {
  202. video = remoteVideos[id];
  203. }
  204. if (video)
  205. video.enableDeviceAvailabilityIcons(enable);
  206. },
  207. /**
  208. * Shows/hides local video.
  209. * @param {boolean} true to make the local video visible, false - otherwise
  210. */
  211. setLocalVideoVisible(visible) {
  212. localVideoThumbnail.setVisible(visible);
  213. },
  214. /**
  215. * Checks if removed video is currently displayed and tries to display
  216. * another one instead.
  217. * Uses focusedID if any or dominantSpeakerID if any,
  218. * otherwise elects new video, in this order.
  219. */
  220. updateAfterThumbRemoved (id) {
  221. // Always trigger an update if large video is empty.
  222. if (!largeVideo
  223. || (this.getLargeVideoID() && !this.isCurrentlyOnLarge(id))) {
  224. return;
  225. }
  226. const pinnedId = this.getPinnedId();
  227. let newId;
  228. if (pinnedId)
  229. newId = pinnedId;
  230. else if (currentDominantSpeaker)
  231. newId = currentDominantSpeaker;
  232. else // Otherwise select last visible video
  233. newId = this.electLastVisibleVideo();
  234. this.updateLargeVideo(newId);
  235. },
  236. electLastVisibleVideo () {
  237. // pick the last visible video in the row
  238. // if nobody else is left, this picks the local video
  239. let remoteThumbs = Filmstrip.getThumbs(true).remoteThumbs;
  240. let thumbs = remoteThumbs.filter('[id!="mixedstream"]');
  241. let lastVisible = thumbs.filter(':visible:last');
  242. if (lastVisible.length) {
  243. let id = getPeerContainerResourceId(lastVisible[0]);
  244. if (remoteVideos[id]) {
  245. logger.info("electLastVisibleVideo: " + id);
  246. return id;
  247. }
  248. // The RemoteVideo was removed (but the DOM elements may still
  249. // exist).
  250. }
  251. logger.info("Last visible video no longer exists");
  252. thumbs = Filmstrip.getThumbs().remoteThumbs;
  253. if (thumbs.length) {
  254. let id = getPeerContainerResourceId(thumbs[0]);
  255. if (remoteVideos[id]) {
  256. logger.info("electLastVisibleVideo: " + id);
  257. return id;
  258. }
  259. // The RemoteVideo was removed (but the DOM elements may
  260. // still exist).
  261. }
  262. // Go with local video
  263. logger.info("Fallback to local video...");
  264. let id = APP.conference.getMyUserId();
  265. logger.info("electLastVisibleVideo: " + id);
  266. return id;
  267. },
  268. onRemoteStreamAdded (stream) {
  269. let id = stream.getParticipantId();
  270. let remoteVideo = remoteVideos[id];
  271. if (!remoteVideo)
  272. return;
  273. remoteVideo.addRemoteStreamElement(stream);
  274. // Make sure track's muted state is reflected
  275. if (stream.getType() === "audio") {
  276. this.onAudioMute(stream.getParticipantId(), stream.isMuted());
  277. } else {
  278. this.onVideoMute(stream.getParticipantId(), stream.isMuted());
  279. }
  280. },
  281. onRemoteStreamRemoved (stream) {
  282. let id = stream.getParticipantId();
  283. let remoteVideo = remoteVideos[id];
  284. // Remote stream may be removed after participant left the conference.
  285. if (remoteVideo) {
  286. remoteVideo.removeRemoteStreamElement(stream);
  287. }
  288. this.updateMutedForNoTracks(id, stream.getType());
  289. },
  290. /**
  291. * FIXME get rid of this method once muted indicator are reactified (by
  292. * making sure that user with no tracks is displayed as muted )
  293. *
  294. * If participant has no tracks will make the UI display muted status.
  295. * @param {string} participantId
  296. * @param {string} mediaType 'audio' or 'video'
  297. */
  298. updateMutedForNoTracks(participantId, mediaType) {
  299. const participant = APP.conference.getParticipantById(participantId);
  300. if (participant
  301. && !participant.getTracksByMediaType(mediaType).length) {
  302. if (mediaType === 'audio') {
  303. APP.UI.setAudioMuted(participantId, true);
  304. } else if (mediaType === 'video') {
  305. APP.UI.setVideoMuted(participantId, true);
  306. } else {
  307. logger.error(`Unsupported media type: ${mediaType}`);
  308. }
  309. }
  310. },
  311. /**
  312. * Return the type of the remote video.
  313. * @param id the id for the remote video
  314. * @returns {String} the video type video or screen.
  315. */
  316. getRemoteVideoType (id) {
  317. let smallVideo = VideoLayout.getSmallVideo(id);
  318. return smallVideo ? smallVideo.getVideoType() : null;
  319. },
  320. isPinned (id) {
  321. return id === this.getPinnedId();
  322. },
  323. getPinnedId () {
  324. const { id } = getPinnedParticipant(APP.store.getState()) || {};
  325. return id || null;
  326. },
  327. /**
  328. * Updates the desired pinned participant and notifies web UI of the change.
  329. *
  330. * @param {string|null} id - The participant id of the participant to be
  331. * pinned. Pass in null to unpin without pinning another participant.
  332. * @returns {void}
  333. */
  334. pinParticipant(id) {
  335. APP.store.dispatch(pinParticipant(id));
  336. APP.UI.emitEvent(UIEvents.PINNED_ENDPOINT, id, Boolean(id));
  337. },
  338. /**
  339. * Handles the click on a video thumbnail.
  340. *
  341. * @param id the identifier of the video thumbnail
  342. */
  343. handleVideoThumbClicked (id) {
  344. var smallVideo = VideoLayout.getSmallVideo(id);
  345. const pinnedId = this.getPinnedId();
  346. if(pinnedId) {
  347. var oldSmallVideo = VideoLayout.getSmallVideo(pinnedId);
  348. if (oldSmallVideo && !interfaceConfig.filmStripOnly) {
  349. oldSmallVideo.focus(false);
  350. }
  351. }
  352. // Unpin if currently pinned.
  353. if (pinnedId === id)
  354. {
  355. this.pinParticipant(null);
  356. // Enable the currently set dominant speaker.
  357. if (currentDominantSpeaker) {
  358. if(smallVideo && smallVideo.hasVideo()) {
  359. this.updateLargeVideo(currentDominantSpeaker);
  360. }
  361. } else {
  362. // if there is no currentDominantSpeaker, it can also be
  363. // that local participant is the dominant speaker
  364. // we should act as a participant has left and was on large
  365. // and we should choose somebody (electLastVisibleVideo)
  366. this.updateLargeVideo(this.electLastVisibleVideo());
  367. }
  368. return;
  369. }
  370. // Update focused/pinned interface.
  371. if (id) {
  372. if (smallVideo && !interfaceConfig.filmStripOnly) {
  373. smallVideo.focus(true);
  374. this.pinParticipant(id);
  375. }
  376. }
  377. this.updateLargeVideo(id);
  378. },
  379. /**
  380. * Creates or adds a participant container for the given id and smallVideo.
  381. *
  382. * @param {JitsiParticipant} user the participant to add
  383. * @param {SmallVideo} smallVideo optional small video instance to add as a
  384. * remote video, if undefined <tt>RemoteVideo</tt> will be created
  385. */
  386. addParticipantContainer (user, smallVideo) {
  387. let id = user.getId();
  388. let remoteVideo;
  389. if(smallVideo)
  390. remoteVideo = smallVideo;
  391. else
  392. remoteVideo = new RemoteVideo(user, VideoLayout, eventEmitter);
  393. this._setRemoteControlProperties(user, remoteVideo);
  394. this.addRemoteVideoContainer(id, remoteVideo);
  395. this.updateMutedForNoTracks(id, 'audio');
  396. this.updateMutedForNoTracks(id, 'video');
  397. const remoteVideosCount = Object.keys(remoteVideos).length;
  398. if (remoteVideosCount === 1) {
  399. window.setTimeout(() => {
  400. const updatedRemoteVideosCount
  401. = Object.keys(remoteVideos).length;
  402. if (updatedRemoteVideosCount === 1 && remoteVideos[id]) {
  403. this._maybePlaceParticipantOnLargeVideo(id);
  404. }
  405. }, 3000);
  406. }
  407. },
  408. /**
  409. * Adds remote video container for the given id and <tt>SmallVideo</tt>.
  410. *
  411. * @param {string} the id of the video to add
  412. * @param {SmallVideo} smallVideo the small video instance to add as a
  413. * remote video
  414. */
  415. addRemoteVideoContainer (id, remoteVideo) {
  416. remoteVideos[id] = remoteVideo;
  417. if (!remoteVideo.getVideoType()) {
  418. // make video type the default one (camera)
  419. // FIXME container type is not a video type
  420. remoteVideo.setVideoType(VIDEO_CONTAINER_TYPE);
  421. }
  422. VideoLayout.resizeThumbnails(false, true);
  423. // Initialize the view
  424. remoteVideo.updateView();
  425. },
  426. // FIXME: what does this do???
  427. remoteVideoActive(videoElement, resourceJid) {
  428. logger.info(resourceJid + " video is now active", videoElement);
  429. VideoLayout.resizeThumbnails(
  430. false, false, () => {
  431. if (videoElement) {
  432. $(videoElement).show();
  433. }
  434. });
  435. this._maybePlaceParticipantOnLargeVideo(resourceJid);
  436. },
  437. /**
  438. * Update the large video to the last added video only if there's no current
  439. * dominant, focused speaker or update it to the current dominant speaker.
  440. *
  441. * @params {string} resourceJid - The id of the user to maybe display on
  442. * large video.
  443. * @returns {void}
  444. */
  445. _maybePlaceParticipantOnLargeVideo(resourceJid) {
  446. const pinnedId = this.getPinnedId();
  447. if ((!pinnedId &&
  448. !currentDominantSpeaker &&
  449. this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE)) ||
  450. pinnedId === resourceJid ||
  451. (!pinnedId && resourceJid &&
  452. currentDominantSpeaker === resourceJid) ||
  453. /* Playback started while we're on the stage - may need to update
  454. video source with the new stream */
  455. this.isCurrentlyOnLarge(resourceJid)) {
  456. this.updateLargeVideo(resourceJid, true);
  457. }
  458. },
  459. /**
  460. * Shows a visual indicator for the moderator of the conference.
  461. * On local or remote participants.
  462. */
  463. showModeratorIndicator () {
  464. let isModerator = APP.conference.isModerator;
  465. if (isModerator) {
  466. localVideoThumbnail.addModeratorIndicator();
  467. } else {
  468. localVideoThumbnail.removeModeratorIndicator();
  469. }
  470. APP.conference.listMembers().forEach(function (member) {
  471. let id = member.getId();
  472. let remoteVideo = remoteVideos[id];
  473. if (!remoteVideo)
  474. return;
  475. if (member.isModerator()) {
  476. remoteVideo.addModeratorIndicator();
  477. }
  478. if (isModerator) {
  479. // We are moderator, but user is not - add menu
  480. if(!remoteVideo.hasRemoteVideoMenu) {
  481. remoteVideo.addRemoteVideoMenu();
  482. }
  483. }
  484. });
  485. },
  486. /*
  487. * Shows or hides the audio muted indicator over the local thumbnail video.
  488. * @param {boolean} isMuted
  489. */
  490. showLocalAudioIndicator (isMuted) {
  491. localVideoThumbnail.showAudioIndicator(isMuted);
  492. },
  493. /**
  494. * Shows/hides the indication about local connection being interrupted.
  495. *
  496. * @param {boolean} isInterrupted <tt>true</tt> if local connection is
  497. * currently in the interrupted state or <tt>false</tt> if the connection
  498. * is fine.
  499. */
  500. showLocalConnectionInterrupted (isInterrupted) {
  501. // Currently local video thumbnail displays only "active" or
  502. // "interrupted" despite the fact that ConnectionIndicator supports more
  503. // states.
  504. const status
  505. = isInterrupted
  506. ? ParticipantConnectionStatus.INTERRUPTED
  507. : ParticipantConnectionStatus.ACTIVE;
  508. localVideoThumbnail.updateConnectionStatus(status);
  509. },
  510. /**
  511. * Resizes thumbnails.
  512. */
  513. resizeThumbnails(
  514. animate = false,
  515. forceUpdate = false,
  516. onComplete = null) {
  517. const { localVideo, remoteVideo }
  518. = Filmstrip.calculateThumbnailSize();
  519. Filmstrip.resizeThumbnails(localVideo, remoteVideo,
  520. animate, forceUpdate)
  521. .then(function () {
  522. if (onComplete && typeof onComplete === "function")
  523. onComplete();
  524. });
  525. return { localVideo, remoteVideo };
  526. },
  527. /**
  528. * On audio muted event.
  529. */
  530. onAudioMute (id, isMuted) {
  531. if (APP.conference.isLocalId(id)) {
  532. localVideoThumbnail.showAudioIndicator(isMuted);
  533. } else {
  534. let remoteVideo = remoteVideos[id];
  535. if (!remoteVideo)
  536. return;
  537. remoteVideo.showAudioIndicator(isMuted);
  538. remoteVideo.updateRemoteVideoMenu(isMuted);
  539. }
  540. },
  541. /**
  542. * On video muted event.
  543. */
  544. onVideoMute (id, value) {
  545. if (APP.conference.isLocalId(id)) {
  546. localVideoThumbnail.setVideoMutedView(value);
  547. } else {
  548. let remoteVideo = remoteVideos[id];
  549. if (remoteVideo)
  550. remoteVideo.setVideoMutedView(value);
  551. }
  552. if (this.isCurrentlyOnLarge(id)) {
  553. // large video will show avatar instead of muted stream
  554. this.updateLargeVideo(id, true);
  555. }
  556. },
  557. /**
  558. * Display name changed.
  559. */
  560. onDisplayNameChanged (id, displayName, status) {
  561. if (id === 'localVideoContainer' ||
  562. APP.conference.isLocalId(id)) {
  563. localVideoThumbnail.setDisplayName(displayName);
  564. } else {
  565. let remoteVideo = remoteVideos[id];
  566. if (remoteVideo)
  567. remoteVideo.setDisplayName(displayName, status);
  568. }
  569. },
  570. /**
  571. * Sets the "raised hand" status for a participant identified by 'id'.
  572. */
  573. setRaisedHandStatus(id, raisedHandStatus) {
  574. var video
  575. = APP.conference.isLocalId(id)
  576. ? localVideoThumbnail : remoteVideos[id];
  577. if (video) {
  578. video.showRaisedHandIndicator(raisedHandStatus);
  579. if (raisedHandStatus) {
  580. video.showDominantSpeakerIndicator(false);
  581. }
  582. }
  583. },
  584. /**
  585. * On dominant speaker changed event.
  586. */
  587. onDominantSpeakerChanged (id) {
  588. if (id === currentDominantSpeaker) {
  589. return;
  590. }
  591. let oldSpeakerRemoteVideo = remoteVideos[currentDominantSpeaker];
  592. // We ignore local user events, but just unmark remote user as dominant
  593. // while we are talking
  594. if (APP.conference.isLocalId(id)) {
  595. if(oldSpeakerRemoteVideo)
  596. {
  597. oldSpeakerRemoteVideo.showDominantSpeakerIndicator(false);
  598. currentDominantSpeaker = null;
  599. }
  600. localVideoThumbnail.showDominantSpeakerIndicator(true);
  601. return;
  602. }
  603. let remoteVideo = remoteVideos[id];
  604. if (!remoteVideo) {
  605. return;
  606. }
  607. // Update the current dominant speaker.
  608. remoteVideo.showDominantSpeakerIndicator(true);
  609. localVideoThumbnail.showDominantSpeakerIndicator(false);
  610. // let's remove the indications from the remote video if any
  611. if (oldSpeakerRemoteVideo) {
  612. oldSpeakerRemoteVideo.showDominantSpeakerIndicator(false);
  613. }
  614. currentDominantSpeaker = id;
  615. // Local video will not have container found, but that's ok
  616. // since we don't want to switch to local video.
  617. // Update the large video if the video source is already available,
  618. // otherwise wait for the "videoactive.jingle" event.
  619. // FIXME: there is no "videoactive.jingle" event.
  620. if (!interfaceConfig.filmStripOnly && !this.getPinnedId()
  621. && remoteVideo.hasVideoStarted()
  622. && !this.getCurrentlyOnLargeContainer().stayOnStage()) {
  623. this.updateLargeVideo(id);
  624. }
  625. },
  626. /**
  627. * Shows/hides warning about remote user's connectivity issues.
  628. *
  629. * @param {string} id the ID of the remote participant(MUC nickname)
  630. */
  631. // eslint-disable-next-line no-unused-vars
  632. onParticipantConnectionStatusChanged (id) {
  633. // Show/hide warning on the large video
  634. if (this.isCurrentlyOnLarge(id)) {
  635. if (largeVideo) {
  636. // We have to trigger full large video update to transition from
  637. // avatar to video on connectivity restored.
  638. this.updateLargeVideo(id, true /* force update */);
  639. }
  640. }
  641. // Show/hide warning on the thumbnail
  642. let remoteVideo = remoteVideos[id];
  643. if (remoteVideo) {
  644. // Updating only connection status indicator is not enough, because
  645. // when we the connection is restored while the avatar was displayed
  646. // (due to 'muted while disconnected' condition) we may want to show
  647. // the video stream again and in order to do that the display mode
  648. // must be updated.
  649. //remoteVideo.updateConnectionStatusIndicator(isActive);
  650. remoteVideo.updateView();
  651. }
  652. },
  653. /**
  654. * On last N change event.
  655. *
  656. * @param endpointsLeavingLastN the list currently leaving last N
  657. * endpoints
  658. * @param endpointsEnteringLastN the list currently entering last N
  659. * endpoints
  660. */
  661. onLastNEndpointsChanged (endpointsLeavingLastN, endpointsEnteringLastN) {
  662. if (endpointsLeavingLastN) {
  663. endpointsLeavingLastN.forEach(this._updateRemoteVideo, this);
  664. }
  665. if (endpointsEnteringLastN) {
  666. endpointsEnteringLastN.forEach(this._updateRemoteVideo, this);
  667. }
  668. },
  669. /**
  670. * Updates remote video by id if it exists.
  671. * @param {string} id of the remote video
  672. * @private
  673. */
  674. _updateRemoteVideo(id) {
  675. const remoteVideo = remoteVideos[id];
  676. if (remoteVideo) {
  677. remoteVideo.updateView();
  678. if (remoteVideo.isCurrentlyOnLargeVideo()) {
  679. this.updateLargeVideo(id);
  680. }
  681. }
  682. },
  683. /**
  684. * Hides the connection indicator
  685. * @param id
  686. */
  687. hideConnectionIndicator (id) {
  688. let remoteVideo = remoteVideos[id];
  689. if (remoteVideo)
  690. remoteVideo.removeConnectionIndicator();
  691. },
  692. /**
  693. * Hides all the indicators
  694. */
  695. hideStats () {
  696. for (var video in remoteVideos) {
  697. let remoteVideo = remoteVideos[video];
  698. if (remoteVideo)
  699. remoteVideo.removeConnectionIndicator();
  700. }
  701. localVideoThumbnail.removeConnectionIndicator();
  702. },
  703. removeParticipantContainer (id) {
  704. // Unlock large video
  705. if (this.getPinnedId() === id) {
  706. logger.info("Focused video owner has left the conference");
  707. this.pinParticipant(null);
  708. }
  709. if (currentDominantSpeaker === id) {
  710. logger.info("Dominant speaker has left the conference");
  711. currentDominantSpeaker = null;
  712. }
  713. var remoteVideo = remoteVideos[id];
  714. if (remoteVideo) {
  715. // Remove remote video
  716. logger.info("Removing remote video: " + id);
  717. delete remoteVideos[id];
  718. remoteVideo.remove();
  719. } else {
  720. logger.warn("No remote video for " + id);
  721. }
  722. VideoLayout.resizeThumbnails();
  723. },
  724. onVideoTypeChanged (id, newVideoType) {
  725. if (VideoLayout.getRemoteVideoType(id) === newVideoType) {
  726. return;
  727. }
  728. logger.info("Peer video type changed: ", id, newVideoType);
  729. var smallVideo;
  730. if (APP.conference.isLocalId(id)) {
  731. if (!localVideoThumbnail) {
  732. logger.warn("Local video not ready yet");
  733. return;
  734. }
  735. smallVideo = localVideoThumbnail;
  736. } else if (remoteVideos[id]) {
  737. smallVideo = remoteVideos[id];
  738. } else {
  739. return;
  740. }
  741. smallVideo.setVideoType(newVideoType);
  742. if (this.isCurrentlyOnLarge(id)) {
  743. this.updateLargeVideo(id, true);
  744. }
  745. },
  746. /**
  747. * Resizes the video area.
  748. *
  749. * @param forceUpdate indicates that hidden thumbnails will be shown
  750. * @param completeFunction a function to be called when the video area is
  751. * resized.
  752. */
  753. resizeVideoArea(
  754. forceUpdate = false,
  755. animate = false,
  756. completeFunction = null) {
  757. if (largeVideo) {
  758. largeVideo.updateContainerSize();
  759. largeVideo.resize(animate);
  760. }
  761. // Calculate available width and height.
  762. let availableHeight = window.innerHeight;
  763. let availableWidth = UIUtil.getAvailableVideoWidth();
  764. if (availableWidth < 0 || availableHeight < 0) {
  765. return;
  766. }
  767. // Resize the thumbnails first.
  768. this.resizeThumbnails(false, forceUpdate);
  769. // Resize the video area element.
  770. $('#videospace').animate({
  771. right: window.innerWidth - availableWidth,
  772. width: availableWidth,
  773. height: availableHeight
  774. }, {
  775. queue: false,
  776. duration: animate ? 500 : 1,
  777. complete: completeFunction
  778. });
  779. },
  780. getSmallVideo (id) {
  781. if (APP.conference.isLocalId(id)) {
  782. return localVideoThumbnail;
  783. } else {
  784. return remoteVideos[id];
  785. }
  786. },
  787. changeUserAvatar (id, avatarUrl) {
  788. var smallVideo = VideoLayout.getSmallVideo(id);
  789. if (smallVideo) {
  790. smallVideo.avatarChanged(avatarUrl);
  791. } else {
  792. logger.warn(
  793. "Missed avatar update - no small video yet for " + id
  794. );
  795. }
  796. if (this.isCurrentlyOnLarge(id)) {
  797. largeVideo.updateAvatar(avatarUrl);
  798. }
  799. },
  800. /**
  801. * Indicates that the video has been interrupted.
  802. */
  803. onVideoInterrupted () {
  804. if (largeVideo) {
  805. largeVideo.onVideoInterrupted();
  806. }
  807. },
  808. /**
  809. * Indicates that the video has been restored.
  810. */
  811. onVideoRestored () {
  812. if (largeVideo) {
  813. largeVideo.onVideoRestored();
  814. }
  815. },
  816. isLargeVideoVisible () {
  817. return this.isLargeContainerTypeVisible(VIDEO_CONTAINER_TYPE);
  818. },
  819. /**
  820. * @return {LargeContainer} the currently displayed container on large
  821. * video.
  822. */
  823. getCurrentlyOnLargeContainer () {
  824. return largeVideo.getCurrentContainer();
  825. },
  826. isCurrentlyOnLarge (id) {
  827. return largeVideo && largeVideo.id === id;
  828. },
  829. /**
  830. * Triggers an update of remote video and large video displays so they may
  831. * pick up any state changes that have occurred elsewhere.
  832. *
  833. * @returns {void}
  834. */
  835. updateAllVideos() {
  836. const displayedUserId = this.getLargeVideoID();
  837. if (displayedUserId) {
  838. this.updateLargeVideo(displayedUserId, true);
  839. }
  840. Object.keys(remoteVideos).forEach(video => {
  841. remoteVideos[video].updateView();
  842. });
  843. },
  844. updateLargeVideo (id, forceUpdate) {
  845. if (!largeVideo) {
  846. return;
  847. }
  848. const currentContainer = largeVideo.getCurrentContainer();
  849. const currentContainerType = largeVideo.getCurrentContainerType();
  850. const currentId = largeVideo.id;
  851. const isOnLarge = this.isCurrentlyOnLarge(id);
  852. const smallVideo = this.getSmallVideo(id);
  853. if (isOnLarge && !forceUpdate
  854. && LargeVideoManager.isVideoContainer(currentContainerType)
  855. && smallVideo) {
  856. const currentStreamId = currentContainer.getStreamID();
  857. const newStreamId
  858. = smallVideo.videoStream
  859. ? smallVideo.videoStream.getId() : null;
  860. // FIXME it might be possible to get rid of 'forceUpdate' argument
  861. if (currentStreamId !== newStreamId) {
  862. logger.debug('Enforcing large video update for stream change');
  863. forceUpdate = true;
  864. }
  865. }
  866. if (!isOnLarge || forceUpdate) {
  867. let videoType = this.getRemoteVideoType(id);
  868. // FIXME video type is not the same thing as container type
  869. if (id !== currentId && videoType === VIDEO_CONTAINER_TYPE) {
  870. eventEmitter.emit(UIEvents.SELECTED_ENDPOINT, id);
  871. }
  872. let oldSmallVideo;
  873. if (currentId) {
  874. oldSmallVideo = this.getSmallVideo(currentId);
  875. }
  876. smallVideo.waitForResolutionChange();
  877. if (oldSmallVideo)
  878. oldSmallVideo.waitForResolutionChange();
  879. largeVideo.updateLargeVideo(
  880. id,
  881. smallVideo.videoStream,
  882. videoType
  883. ).then(function() {
  884. // update current small video and the old one
  885. smallVideo.updateView();
  886. oldSmallVideo && oldSmallVideo.updateView();
  887. }, function () {
  888. // use clicked other video during update, nothing to do.
  889. });
  890. } else if (currentId) {
  891. let currentSmallVideo = this.getSmallVideo(currentId);
  892. currentSmallVideo.updateView();
  893. }
  894. },
  895. addLargeVideoContainer (type, container) {
  896. largeVideo && largeVideo.addContainer(type, container);
  897. },
  898. removeLargeVideoContainer (type) {
  899. largeVideo && largeVideo.removeContainer(type);
  900. },
  901. /**
  902. * @returns Promise
  903. */
  904. showLargeVideoContainer (type, show) {
  905. if (!largeVideo) {
  906. return Promise.reject();
  907. }
  908. let isVisible = this.isLargeContainerTypeVisible(type);
  909. if (isVisible === show) {
  910. return Promise.resolve();
  911. }
  912. let currentId = largeVideo.id;
  913. if(currentId) {
  914. var oldSmallVideo = this.getSmallVideo(currentId);
  915. }
  916. let containerTypeToShow = type;
  917. // if we are hiding a container and there is focusedVideo
  918. // (pinned remote video) use its video type,
  919. // if not then use default type - large video
  920. if (!show) {
  921. const pinnedId = this.getPinnedId();
  922. if(pinnedId)
  923. containerTypeToShow = this.getRemoteVideoType(pinnedId);
  924. else
  925. containerTypeToShow = VIDEO_CONTAINER_TYPE;
  926. }
  927. return largeVideo.showContainer(containerTypeToShow)
  928. .then(() => {
  929. if(oldSmallVideo)
  930. oldSmallVideo && oldSmallVideo.updateView();
  931. });
  932. },
  933. isLargeContainerTypeVisible (type) {
  934. return largeVideo && largeVideo.state === type;
  935. },
  936. /**
  937. * Returns the id of the current video shown on large.
  938. * Currently used by tests (torture).
  939. */
  940. getLargeVideoID () {
  941. return largeVideo.id;
  942. },
  943. /**
  944. * Returns the the current video shown on large.
  945. * Currently used by tests (torture).
  946. */
  947. getLargeVideo () {
  948. return largeVideo;
  949. },
  950. /**
  951. * Sets the flipX state of the local video.
  952. * @param {boolean} true for flipped otherwise false;
  953. */
  954. setLocalFlipX (val) {
  955. this.localFlipX = val;
  956. },
  957. getEventEmitter() {return eventEmitter;},
  958. /**
  959. * Handles user's features changes.
  960. */
  961. onUserFeaturesChanged (user) {
  962. let video = this.getSmallVideo(user.getId());
  963. if (!video) {
  964. return;
  965. }
  966. this._setRemoteControlProperties(user, video);
  967. },
  968. /**
  969. * Sets the remote control properties (checks whether remote control
  970. * is supported and executes remoteVideo.setRemoteControlSupport).
  971. * @param {JitsiParticipant} user the user that will be checked for remote
  972. * control support.
  973. * @param {RemoteVideo} remoteVideo the remoteVideo on which the properties
  974. * will be set.
  975. */
  976. _setRemoteControlProperties (user, remoteVideo) {
  977. APP.remoteControl.checkUserRemoteControlSupport(user).then(result =>
  978. remoteVideo.setRemoteControlSupport(result));
  979. },
  980. /**
  981. * Returns the wrapper jquery selector for the largeVideo
  982. * @returns {JQuerySelector} the wrapper jquery selector for the largeVideo
  983. */
  984. getLargeVideoWrapper() {
  985. return this.getCurrentlyOnLargeContainer().$wrapper;
  986. },
  987. /**
  988. * Returns the number of remove video ids.
  989. *
  990. * @returns {number} The number of remote videos.
  991. */
  992. getRemoteVideosCount() {
  993. return Object.keys(remoteVideos).length;
  994. },
  995. /**
  996. * Sets the remote control active status for a remote participant.
  997. *
  998. * @param {string} participantID - The id of the remote participant.
  999. * @param {boolean} isActive - The new remote control active status.
  1000. * @returns {void}
  1001. */
  1002. setRemoteControlActiveStatus(participantID, isActive) {
  1003. remoteVideos[participantID].setRemoteControlActiveStatus(isActive);
  1004. },
  1005. /**
  1006. * Sets the remote control active status for the local participant.
  1007. *
  1008. * @returns {void}
  1009. */
  1010. setLocalRemoteControlActiveChanged() {
  1011. Object.values(remoteVideos).forEach(
  1012. remoteVideo => remoteVideo.updateRemoteVideoMenu()
  1013. );
  1014. }
  1015. };
  1016. export default VideoLayout;