You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VideoLayout.js 38KB

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