選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

VideoLayout.js 35KB

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