Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

VideoLayout.js 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. /* global config, APP, $, interfaceConfig, JitsiMeetJS */
  2. /* jshint -W101 */
  3. import AudioLevels from "../audio_levels/AudioLevels";
  4. import Avatar from "../avatar/Avatar";
  5. import BottomToolbar from "../toolbars/BottomToolbar";
  6. import UIEvents from "../../../service/UI/UIEvents";
  7. import UIUtil from "../util/UIUtil";
  8. import RemoteVideo from "./RemoteVideo";
  9. import LargeVideoManager, {VideoContainerType} from "./LargeVideo";
  10. import {PreziContainerType} from '../prezi/Prezi';
  11. import LocalVideo from "./LocalVideo";
  12. const RTCUIUtil = JitsiMeetJS.util.RTCUIHelper;
  13. var remoteVideos = {};
  14. var remoteVideoTypes = {};
  15. var localVideoThumbnail = null;
  16. var currentDominantSpeaker = null;
  17. var lastNCount = config.channelLastN;
  18. var localLastNCount = config.channelLastN;
  19. var localLastNSet = [];
  20. var lastNEndpointsCache = [];
  21. var lastNPickupId = null;
  22. var eventEmitter = null;
  23. /**
  24. * Currently focused video jid
  25. * @type {String}
  26. */
  27. var focusedVideoResourceJid = null;
  28. const thumbAspectRatio = 16.0 / 9.0;
  29. /**
  30. * On contact list item clicked.
  31. */
  32. function onContactClicked (id) {
  33. if (APP.conference.isLocalId(id)) {
  34. $("#localVideoContainer").click();
  35. return;
  36. }
  37. let remoteVideo = remoteVideos[id];
  38. if (remoteVideo && remoteVideo.hasVideo()) {
  39. // It is not always the case that a videoThumb exists (if there is
  40. // no actual video).
  41. if (remoteVideo.hasVideoStarted()) {
  42. // We have a video src, great! Let's update the large video
  43. // now.
  44. VideoLayout.handleVideoThumbClicked(false, id);
  45. } else {
  46. // If we don't have a video src for jid, there's absolutely
  47. // no point in calling handleVideoThumbClicked; Quite
  48. // simply, it won't work because it needs an src to attach
  49. // to the large video.
  50. //
  51. // Instead, we trigger the pinned endpoint changed event to
  52. // let the bridge adjust its lastN set for myjid and store
  53. // the pinned user in the lastNPickupId variable to be
  54. // picked up later by the lastN changed event handler.
  55. lastNPickupId = id;
  56. eventEmitter.emit(UIEvents.PINNED_ENDPOINT, id);
  57. }
  58. }
  59. }
  60. /**
  61. * Returns the corresponding resource id to the given peer container
  62. * DOM element.
  63. *
  64. * @return the corresponding resource id to the given peer container
  65. * DOM element
  66. */
  67. function getPeerContainerResourceId (containerElement) {
  68. if (localVideoThumbnail.container === containerElement) {
  69. return localVideoThumbnail.id;
  70. }
  71. let i = containerElement.id.indexOf('participant_');
  72. if (i >= 0) {
  73. return containerElement.id.substring(i + 12);
  74. }
  75. }
  76. let largeVideo;
  77. var VideoLayout = {
  78. init (emitter) {
  79. eventEmitter = emitter;
  80. localVideoThumbnail = new LocalVideo(VideoLayout, emitter);
  81. emitter.addListener(UIEvents.CONTACT_CLICKED, onContactClicked);
  82. },
  83. initLargeVideo (isSideBarVisible) {
  84. largeVideo = new LargeVideoManager();
  85. largeVideo.updateContainerSize(isSideBarVisible);
  86. AudioLevels.init();
  87. },
  88. setAudioLevel(id, lvl) {
  89. if (!largeVideo) {
  90. return;
  91. }
  92. AudioLevels.updateAudioLevel(
  93. id, lvl, largeVideo.id
  94. );
  95. },
  96. isInLastN (resource) {
  97. return lastNCount < 0 || // lastN is disabled
  98. // lastNEndpoints cache not built yet
  99. (lastNCount > 0 && !lastNEndpointsCache.length) ||
  100. (lastNEndpointsCache &&
  101. lastNEndpointsCache.indexOf(resource) !== -1);
  102. },
  103. changeLocalAudio (stream) {
  104. let localAudio = document.getElementById('localAudio');
  105. localAudio = stream.attach(localAudio);
  106. // Now when Temasys plugin is converting also <audio> elements to
  107. // plugin's <object>s, in current layout it will capture click events
  108. // before it reaches the local video object. We hide it here in order
  109. // to prevent that.
  110. //if (RTCBrowserType.isIExplorer()) {
  111. // The issue is not present on Safari. Also if we hide it in Safari
  112. // then the local audio track will have 'enabled' flag set to false
  113. // which will result in audio mute issues
  114. // $(localAudio).hide();
  115. localAudio.width = 1;
  116. localAudio.height = 1;
  117. //}
  118. },
  119. changeLocalVideo (stream) {
  120. // Set default display name.
  121. localVideoThumbnail.setDisplayName();
  122. localVideoThumbnail.createConnectionIndicator();
  123. let localId = APP.conference.localId;
  124. this.onVideoTypeChanged(localId, stream.videoType);
  125. let {thumbWidth, thumbHeight} = this.calculateThumbnailSize();
  126. AudioLevels.updateAudioLevelCanvas(
  127. null, thumbWidth, thumbHeight);
  128. if (!stream.isMuted()) {
  129. localVideoThumbnail.changeVideo(stream);
  130. }
  131. /* force update if we're currently being displayed */
  132. if (this.isCurrentlyOnLarge(localId)) {
  133. this.updateLargeVideo(localId, true);
  134. }
  135. },
  136. /**
  137. * Get's the localID of the conference and set it to the local video
  138. * (small one). This needs to be called as early as possible, when muc is
  139. * actually joined. Otherwise events can come with information like email
  140. * and setting them assume the id is already set.
  141. */
  142. mucJoined () {
  143. if (largeVideo && !largeVideo.id) {
  144. this.updateLargeVideo(APP.conference.localId, true);
  145. }
  146. },
  147. /**
  148. * Adds or removes icons for not available camera and microphone.
  149. * @param resourceJid the jid of user
  150. * @param devices available devices
  151. */
  152. setDeviceAvailabilityIcons (id, devices) {
  153. if (APP.conference.isLocalId(id)) {
  154. localVideoThumbnail.setDeviceAvailabilityIcons(devices);
  155. return;
  156. }
  157. let video = remoteVideos[id];
  158. if (!video) {
  159. return;
  160. }
  161. video.setDeviceAvailabilityIcons(devices);
  162. },
  163. /**
  164. * Checks if removed video is currently displayed and tries to display
  165. * another one instead.
  166. */
  167. updateRemovedVideo (id) {
  168. if (!this.isCurrentlyOnLarge(id)) {
  169. return;
  170. }
  171. let newId;
  172. // We'll show user's avatar if he is the dominant speaker or if
  173. // his video thumbnail is pinned
  174. if (remoteVideos[id] && (id === focusedVideoResourceJid
  175. || id === currentDominantSpeaker)) {
  176. newId = id;
  177. } else {
  178. // Otherwise select last visible video
  179. newId = this.electLastVisibleVideo();
  180. }
  181. this.updateLargeVideo(newId);
  182. },
  183. electLastVisibleVideo () {
  184. // pick the last visible video in the row
  185. // if nobody else is left, this picks the local video
  186. let thumbs = BottomToolbar.getThumbs(true).filter('[id!="mixedstream"]');
  187. let lastVisible = thumbs.filter(':visible:last');
  188. if (lastVisible.length) {
  189. let id = getPeerContainerResourceId(lastVisible[0]);
  190. if (remoteVideos[id]) {
  191. console.info("electLastVisibleVideo: " + id);
  192. return id;
  193. }
  194. // The RemoteVideo was removed (but the DOM elements may still
  195. // exist).
  196. }
  197. console.info("Last visible video no longer exists");
  198. thumbs = BottomToolbar.getThumbs();
  199. if (thumbs.length) {
  200. let id = getPeerContainerResourceId(thumbs[0]);
  201. if (remoteVideos[id]) {
  202. console.info("electLastVisibleVideo: " + id);
  203. return id;
  204. }
  205. // The RemoteVideo was removed (but the DOM elements may
  206. // still exist).
  207. }
  208. // Go with local video
  209. console.info("Fallback to local video...");
  210. let id = APP.conference.localId;
  211. console.info("electLastVisibleVideo: " + id);
  212. return id;
  213. },
  214. onRemoteStreamAdded (stream) {
  215. let id = stream.getParticipantId();
  216. remoteVideos[id].addRemoteStreamElement(stream);
  217. // if track is muted make sure we reflect that
  218. if(stream.isMuted())
  219. {
  220. if(stream.getType() === "audio")
  221. this.onAudioMute(stream.getParticipantId(), true);
  222. else
  223. this.onVideoMute(stream.getParticipantId(), true);
  224. }
  225. },
  226. onRemoteStreamRemoved (stream) {
  227. let id = stream.getParticipantId();
  228. let remoteVideo = remoteVideos[id];
  229. if (remoteVideo) { // remote stream may be removed after participant left the conference
  230. remoteVideo.removeRemoteStreamElement(stream);
  231. }
  232. },
  233. /**
  234. * Return the type of the remote video.
  235. * @param id the id for the remote video
  236. * @returns the video type video or screen.
  237. */
  238. getRemoteVideoType (id) {
  239. return remoteVideoTypes[id];
  240. },
  241. handleVideoThumbClicked (noPinnedEndpointChangedEvent,
  242. resourceJid) {
  243. if(focusedVideoResourceJid) {
  244. var oldSmallVideo
  245. = VideoLayout.getSmallVideo(focusedVideoResourceJid);
  246. if (oldSmallVideo && !interfaceConfig.filmStripOnly)
  247. oldSmallVideo.focus(false);
  248. }
  249. var smallVideo = VideoLayout.getSmallVideo(resourceJid);
  250. // Unlock current focused.
  251. if (focusedVideoResourceJid === resourceJid)
  252. {
  253. focusedVideoResourceJid = null;
  254. // Enable the currently set dominant speaker.
  255. if (currentDominantSpeaker) {
  256. if(smallVideo && smallVideo.hasVideo()) {
  257. this.updateLargeVideo(currentDominantSpeaker);
  258. }
  259. }
  260. if (!noPinnedEndpointChangedEvent) {
  261. eventEmitter.emit(UIEvents.PINNED_ENDPOINT);
  262. }
  263. return;
  264. }
  265. // Lock new video
  266. focusedVideoResourceJid = resourceJid;
  267. // Update focused/pinned interface.
  268. if (resourceJid) {
  269. if (smallVideo && !interfaceConfig.filmStripOnly)
  270. smallVideo.focus(true);
  271. if (!noPinnedEndpointChangedEvent) {
  272. eventEmitter.emit(UIEvents.PINNED_ENDPOINT, resourceJid);
  273. }
  274. }
  275. this.updateLargeVideo(resourceJid);
  276. },
  277. /**
  278. * Checks if container for participant identified by given id exists
  279. * in the document and creates it eventually.
  280. *
  281. * @return Returns <tt>true</tt> if the peer container exists,
  282. * <tt>false</tt> - otherwise
  283. */
  284. addParticipantContainer (id) {
  285. let remoteVideo = new RemoteVideo(id, VideoLayout, eventEmitter);
  286. remoteVideos[id] = remoteVideo;
  287. let videoType = remoteVideoTypes[id];
  288. if (videoType) {
  289. remoteVideo.setVideoType(videoType);
  290. }
  291. // In case this is not currently in the last n we don't show it.
  292. if (localLastNCount && localLastNCount > 0 &&
  293. BottomToolbar.getThumbs().length >= localLastNCount + 2) {
  294. remoteVideo.showPeerContainer('hide');
  295. } else {
  296. VideoLayout.resizeThumbnails(false, true);
  297. }
  298. },
  299. videoactive (videoelem, resourceJid) {
  300. console.info(resourceJid + " video is now active", videoelem);
  301. $(videoelem).show();
  302. VideoLayout.resizeThumbnails();
  303. // Update the large video to the last added video only if there's no
  304. // current dominant, focused speaker or prezi playing or update it to
  305. // the current dominant speaker.
  306. if ((!focusedVideoResourceJid &&
  307. !currentDominantSpeaker &&
  308. !this.isLargeContainerTypeVisible(PreziContainerType)) ||
  309. focusedVideoResourceJid === resourceJid ||
  310. (resourceJid &&
  311. currentDominantSpeaker === resourceJid)) {
  312. this.updateLargeVideo(resourceJid, true);
  313. }
  314. },
  315. /**
  316. * Shows the presence status message for the given video.
  317. */
  318. setPresenceStatus (id, statusMsg) {
  319. remoteVideos[id].setPresenceStatus(statusMsg);
  320. },
  321. /**
  322. * Shows a visual indicator for the moderator of the conference.
  323. * On local or remote participants.
  324. */
  325. showModeratorIndicator () {
  326. let isModerator = APP.conference.isModerator;
  327. if (isModerator) {
  328. localVideoThumbnail.createModeratorIndicatorElement();
  329. }
  330. APP.conference.listMembers().forEach(function (member) {
  331. let id = member.getId();
  332. if (member.isModerator()) {
  333. remoteVideos[id].removeRemoteVideoMenu();
  334. remoteVideos[id].createModeratorIndicatorElement();
  335. } else if (isModerator) {
  336. // We are moderator, but user is not - add menu
  337. if ($(`#remote_popupmenu_${id}`).length <= 0) {
  338. remoteVideos[id].addRemoteVideoMenu();
  339. }
  340. }
  341. });
  342. },
  343. /*
  344. * Shows or hides the audio muted indicator over the local thumbnail video.
  345. * @param {boolean} isMuted
  346. */
  347. showLocalAudioIndicator (isMuted) {
  348. localVideoThumbnail.showAudioIndicator(isMuted);
  349. },
  350. /**
  351. * Resizes the large video container.
  352. */
  353. resizeLargeVideoContainer (isSideBarVisible, forceUpdate) {
  354. let animate = false;
  355. if (largeVideo) {
  356. largeVideo.updateContainerSize(isSideBarVisible);
  357. largeVideo.resize(animate);
  358. }
  359. this.resizeVideoSpace(animate, isSideBarVisible);
  360. this.resizeThumbnails(false, forceUpdate);
  361. },
  362. /**
  363. * Resizes thumbnails.
  364. */
  365. resizeThumbnails (animate = false, forceUpdate = false) {
  366. let {thumbWidth, thumbHeight} = this.calculateThumbnailSize();
  367. $('.userAvatar').css('left', (thumbWidth - thumbHeight) / 2);
  368. BottomToolbar.resizeThumbnails(thumbWidth, thumbHeight,
  369. animate, forceUpdate)
  370. .then(function () {
  371. BottomToolbar.resizeToolbar(thumbWidth, thumbHeight);
  372. AudioLevels.updateCanvasSize(thumbWidth, thumbHeight);
  373. });
  374. },
  375. /**
  376. * Calculates the thumbnail size.
  377. *
  378. */
  379. calculateThumbnailSize () {
  380. let videoSpaceWidth = BottomToolbar.getFilmStripWidth();
  381. // Calculate the available height, which is the inner window height
  382. // minus 39px for the header minus 2px for the delimiter lines on the
  383. // top and bottom of the large video, minus the 36px space inside the
  384. // remoteVideos container used for highlighting shadow.
  385. let availableHeight = 100;
  386. let numvids = BottomToolbar.getThumbs().length;
  387. if (localLastNCount && localLastNCount > 0) {
  388. numvids = Math.min(localLastNCount + 1, numvids);
  389. }
  390. // Remove the 3px borders arround videos and border around the remote
  391. // videos area and the 4 pixels between the local video and the others
  392. //TODO: Find out where the 4 pixels come from and remove them
  393. let availableWinWidth = videoSpaceWidth - 2 * 3 * numvids - 70 - 4;
  394. let availableWidth = availableWinWidth / numvids;
  395. let maxHeight = Math.min(160, availableHeight);
  396. availableHeight
  397. = Math.min( maxHeight,
  398. availableWidth / thumbAspectRatio,
  399. window.innerHeight - 18);
  400. if (availableHeight < availableWidth / thumbAspectRatio) {
  401. availableWidth = Math.floor(availableHeight * thumbAspectRatio);
  402. }
  403. return {
  404. thumbWidth: availableWidth,
  405. thumbHeight: availableHeight
  406. };
  407. },
  408. /**
  409. * On audio muted event.
  410. */
  411. onAudioMute (id, isMuted) {
  412. if (APP.conference.isLocalId(id)) {
  413. localVideoThumbnail.showAudioIndicator(isMuted);
  414. } else {
  415. remoteVideos[id].showAudioIndicator(isMuted);
  416. if (APP.conference.isModerator) {
  417. remoteVideos[id].updateRemoteVideoMenu(isMuted);
  418. }
  419. }
  420. },
  421. /**
  422. * On video muted event.
  423. */
  424. onVideoMute (id, value) {
  425. if (APP.conference.isLocalId(id)) {
  426. localVideoThumbnail.setMutedView(value);
  427. } else {
  428. var remoteVideo = remoteVideos[id];
  429. remoteVideo.setMutedView(value);
  430. }
  431. if (this.isCurrentlyOnLarge(id)) {
  432. // large video will show avatar instead of muted stream
  433. this.updateLargeVideo(id, true);
  434. }
  435. },
  436. /**
  437. * Display name changed.
  438. */
  439. onDisplayNameChanged (id, displayName, status) {
  440. if (id === 'localVideoContainer' ||
  441. APP.conference.isLocalId(id)) {
  442. localVideoThumbnail.setDisplayName(displayName);
  443. } else {
  444. remoteVideos[id].setDisplayName(displayName, status);
  445. }
  446. },
  447. /**
  448. * On dominant speaker changed event.
  449. */
  450. onDominantSpeakerChanged (id) {
  451. if (id === currentDominantSpeaker) {
  452. return;
  453. }
  454. let oldSpeakerRemoteVideo = remoteVideos[currentDominantSpeaker];
  455. // We ignore local user events, but just unmark remote user as dominant
  456. // while we are talking
  457. if (APP.conference.isLocalId(id)) {
  458. if(oldSpeakerRemoteVideo)
  459. {
  460. oldSpeakerRemoteVideo.updateDominantSpeakerIndicator(false);
  461. localVideoThumbnail.updateDominantSpeakerIndicator(true);
  462. currentDominantSpeaker = null;
  463. }
  464. return;
  465. }
  466. let remoteVideo = remoteVideos[id];
  467. if (!remoteVideo) {
  468. return;
  469. }
  470. // Update the current dominant speaker.
  471. remoteVideo.updateDominantSpeakerIndicator(true);
  472. localVideoThumbnail.updateDominantSpeakerIndicator(false);
  473. // let's remove the indications from the remote video if any
  474. if (oldSpeakerRemoteVideo) {
  475. oldSpeakerRemoteVideo.updateDominantSpeakerIndicator(false);
  476. }
  477. currentDominantSpeaker = id;
  478. // Local video will not have container found, but that's ok
  479. // since we don't want to switch to local video.
  480. // Update the large video if the video source is already available,
  481. // otherwise wait for the "videoactive.jingle" event.
  482. if (!focusedVideoResourceJid && remoteVideo.hasVideoStarted()) {
  483. this.updateLargeVideo(id);
  484. }
  485. },
  486. /**
  487. * On last N change event.
  488. *
  489. * @param lastNEndpoints the list of last N endpoints
  490. * @param endpointsEnteringLastN the list currently entering last N
  491. * endpoints
  492. */
  493. onLastNEndpointsChanged (lastNEndpoints, endpointsEnteringLastN) {
  494. if (lastNCount !== lastNEndpoints.length)
  495. lastNCount = lastNEndpoints.length;
  496. lastNEndpointsCache = lastNEndpoints;
  497. // Say A, B, C, D, E, and F are in a conference and LastN = 3.
  498. //
  499. // If LastN drops to, say, 2, because of adaptivity, then E should see
  500. // thumbnails for A, B and C. A and B are in E's server side LastN set,
  501. // so E sees them. C is only in E's local LastN set.
  502. //
  503. // If F starts talking and LastN = 3, then E should see thumbnails for
  504. // F, A, B. B gets "ejected" from E's server side LastN set, but it
  505. // enters E's local LastN ejecting C.
  506. // Increase the local LastN set size, if necessary.
  507. if (lastNCount > localLastNCount) {
  508. localLastNCount = lastNCount;
  509. }
  510. // Update the local LastN set preserving the order in which the
  511. // endpoints appeared in the LastN/local LastN set.
  512. var nextLocalLastNSet = lastNEndpoints.slice(0);
  513. for (var i = 0; i < localLastNSet.length; i++) {
  514. if (nextLocalLastNSet.length >= localLastNCount) {
  515. break;
  516. }
  517. var resourceJid = localLastNSet[i];
  518. if (nextLocalLastNSet.indexOf(resourceJid) === -1) {
  519. nextLocalLastNSet.push(resourceJid);
  520. }
  521. }
  522. localLastNSet = nextLocalLastNSet;
  523. var updateLargeVideo = false;
  524. // Handle LastN/local LastN changes.
  525. BottomToolbar.getThumbs().each(( index, element ) => {
  526. var resourceJid = getPeerContainerResourceId(element);
  527. var smallVideo = remoteVideos[resourceJid];
  528. // We do not want to process any logic for our own(local) video
  529. // because the local participant is never in the lastN set.
  530. // The code of this function might detect that the local participant
  531. // has been dropped out of the lastN set and will update the large
  532. // video
  533. // Detected from avatar tests, where lastN event override
  534. // local video pinning
  535. if(APP.conference.isLocalId(resourceJid))
  536. return;
  537. var isReceived = true;
  538. if (resourceJid &&
  539. lastNEndpoints.indexOf(resourceJid) < 0 &&
  540. localLastNSet.indexOf(resourceJid) < 0) {
  541. console.log("Remove from last N", resourceJid);
  542. if (smallVideo)
  543. smallVideo.showPeerContainer('hide');
  544. else if (!APP.conference.isLocalId(resourceJid))
  545. console.error("No remote video for: " + resourceJid);
  546. isReceived = false;
  547. } else if (resourceJid &&
  548. smallVideo.isVisible() &&
  549. lastNEndpoints.indexOf(resourceJid) < 0 &&
  550. localLastNSet.indexOf(resourceJid) >= 0) {
  551. if (smallVideo)
  552. smallVideo.showPeerContainer('avatar');
  553. else if (!APP.conference.isLocalId(resourceJid))
  554. console.error("No remote video for: " + resourceJid);
  555. isReceived = false;
  556. }
  557. if (!isReceived) {
  558. // resourceJid has dropped out of the server side lastN set, so
  559. // it is no longer being received. If resourceJid was being
  560. // displayed in the large video we have to switch to another
  561. // user.
  562. if (!updateLargeVideo &&
  563. this.isCurrentlyOnLarge(resourceJid)) {
  564. updateLargeVideo = true;
  565. }
  566. }
  567. });
  568. if (!endpointsEnteringLastN || endpointsEnteringLastN.length < 0)
  569. endpointsEnteringLastN = lastNEndpoints;
  570. if (endpointsEnteringLastN && endpointsEnteringLastN.length > 0) {
  571. endpointsEnteringLastN.forEach(function (resourceJid) {
  572. var remoteVideo = remoteVideos[resourceJid];
  573. remoteVideo.showPeerContainer('show');
  574. if (!remoteVideo.isVisible()) {
  575. console.log("Add to last N", resourceJid);
  576. remoteVideo.addRemoteStreamElement(remoteVideo.videoStream);
  577. if (lastNPickupId == resourceJid) {
  578. // Clean up the lastN pickup id.
  579. lastNPickupId = null;
  580. // Don't fire the events again, they've already
  581. // been fired in the contact list click handler.
  582. VideoLayout.handleVideoThumbClicked(
  583. false,
  584. resourceJid);
  585. updateLargeVideo = false;
  586. }
  587. remoteVideo.waitForPlayback(
  588. remoteVideo.selectVideoElement()[0],
  589. remoteVideo.videoStream);
  590. }
  591. });
  592. }
  593. // The endpoint that was being shown in the large video has dropped out
  594. // of the lastN set and there was no lastN pickup jid. We need to update
  595. // the large video now.
  596. if (updateLargeVideo) {
  597. var resource;
  598. // Find out which endpoint to show in the large video.
  599. for (i = 0; i < lastNEndpoints.length; i++) {
  600. resource = lastNEndpoints[i];
  601. if (!resource || APP.conference.isLocalId(resource))
  602. continue;
  603. // videoSrcToSsrc needs to be update for this call to succeed.
  604. this.updateLargeVideo(resource);
  605. break;
  606. }
  607. }
  608. },
  609. /**
  610. * Updates local stats
  611. * @param percent
  612. * @param object
  613. */
  614. updateLocalConnectionStats (percent, object) {
  615. let resolutions = object.resolution;
  616. object.resolution = resolutions[APP.conference.localId];
  617. localVideoThumbnail.updateStatsIndicator(percent, object);
  618. Object.keys(resolutions).forEach(function (id) {
  619. if (APP.conference.isLocalId(id)) {
  620. return;
  621. }
  622. let resolution = resolutions[id];
  623. let remoteVideo = remoteVideos[id];
  624. if (resolution && remoteVideo) {
  625. remoteVideo.updateResolution(resolution);
  626. }
  627. });
  628. },
  629. /**
  630. * Updates remote stats.
  631. * @param id the id associated with the stats
  632. * @param percent the connection quality percent
  633. * @param object the stats data
  634. */
  635. updateConnectionStats (id, percent, object) {
  636. if (remoteVideos[id]) {
  637. remoteVideos[id].updateStatsIndicator(percent, object);
  638. }
  639. },
  640. /**
  641. * Hides the connection indicator
  642. * @param id
  643. */
  644. hideConnectionIndicator (id) {
  645. remoteVideos[id].hideConnectionIndicator();
  646. },
  647. /**
  648. * Hides all the indicators
  649. */
  650. hideStats () {
  651. for(var video in remoteVideos) {
  652. remoteVideos[video].hideIndicator();
  653. }
  654. localVideoThumbnail.hideIndicator();
  655. },
  656. removeParticipantContainer (id) {
  657. // Unlock large video
  658. if (focusedVideoResourceJid === id) {
  659. console.info("Focused video owner has left the conference");
  660. focusedVideoResourceJid = null;
  661. }
  662. if (currentDominantSpeaker === id) {
  663. console.info("Dominant speaker has left the conference");
  664. currentDominantSpeaker = null;
  665. }
  666. var remoteVideo = remoteVideos[id];
  667. if (remoteVideo) {
  668. // Remove remote video
  669. console.info("Removing remote video: " + id);
  670. delete remoteVideos[id];
  671. remoteVideo.remove();
  672. } else {
  673. console.warn("No remote video for " + id);
  674. }
  675. VideoLayout.resizeThumbnails();
  676. },
  677. onVideoTypeChanged (id, newVideoType) {
  678. if (remoteVideoTypes[id] === newVideoType) {
  679. return;
  680. }
  681. console.info("Peer video type changed: ", id, newVideoType);
  682. remoteVideoTypes[id] = newVideoType;
  683. var smallVideo;
  684. if (APP.conference.isLocalId(id)) {
  685. if (!localVideoThumbnail) {
  686. console.warn("Local video not ready yet");
  687. return;
  688. }
  689. smallVideo = localVideoThumbnail;
  690. } else if (remoteVideos[id]) {
  691. smallVideo = remoteVideos[id];
  692. } else {
  693. return;
  694. }
  695. smallVideo.setVideoType(newVideoType);
  696. if (this.isCurrentlyOnLarge(id)) {
  697. this.updateLargeVideo(id, true);
  698. }
  699. },
  700. showMore (id) {
  701. if (id === 'local') {
  702. localVideoThumbnail.connectionIndicator.showMore();
  703. } else {
  704. let remoteVideo = remoteVideos[id];
  705. if (remoteVideo) {
  706. remoteVideo.connectionIndicator.showMore();
  707. } else {
  708. console.info("Error - no remote video for id: " + id);
  709. }
  710. }
  711. },
  712. addRemoteVideoContainer (id) {
  713. return RemoteVideo.createContainer(id);
  714. },
  715. /**
  716. * Resizes the video area.
  717. *
  718. * @param isSideBarVisible indicates if the side bar is currently visible
  719. * @param callback a function to be called when the video space is
  720. * resized.
  721. */
  722. resizeVideoArea (isSideBarVisible, callback) {
  723. let animate = true;
  724. if (largeVideo) {
  725. largeVideo.updateContainerSize(isSideBarVisible);
  726. largeVideo.resize(animate);
  727. this.resizeVideoSpace(animate, isSideBarVisible, callback);
  728. }
  729. VideoLayout.resizeThumbnails(animate);
  730. },
  731. /**
  732. * Resizes the #videospace html element
  733. * @param animate boolean property that indicates whether the resize should
  734. * be animated or not.
  735. * @param isChatVisible boolean property that indicates whether the chat
  736. * area is displayed or not.
  737. * If that parameter is null the method will check the chat panel
  738. * visibility.
  739. * @param completeFunction a function to be called when the video space
  740. * is resized.
  741. */
  742. resizeVideoSpace (animate, isChatVisible, completeFunction) {
  743. let availableHeight = window.innerHeight;
  744. let availableWidth = UIUtil.getAvailableVideoWidth(isChatVisible);
  745. if (availableWidth < 0 || availableHeight < 0) {
  746. return;
  747. }
  748. $('#videospace').animate({
  749. right: window.innerWidth - availableWidth,
  750. width: availableWidth,
  751. height: availableHeight
  752. }, {
  753. queue: false,
  754. duration: animate ? 500 : 1,
  755. complete: completeFunction
  756. });
  757. },
  758. getSmallVideo (id) {
  759. if (APP.conference.isLocalId(id)) {
  760. return localVideoThumbnail;
  761. } else {
  762. return remoteVideos[id];
  763. }
  764. },
  765. changeUserAvatar (id, avatarUrl) {
  766. var smallVideo = VideoLayout.getSmallVideo(id);
  767. if (smallVideo) {
  768. smallVideo.avatarChanged(avatarUrl);
  769. } else {
  770. console.warn(
  771. "Missed avatar update - no small video yet for " + id
  772. );
  773. }
  774. if (this.isCurrentlyOnLarge(id)) {
  775. largeVideo.updateAvatar(avatarUrl);
  776. }
  777. },
  778. /**
  779. * Indicates that the video has been interrupted.
  780. */
  781. onVideoInterrupted () {
  782. this.enableVideoProblemFilter(true);
  783. let reconnectingKey = "connection.RECONNECTING";
  784. $('#videoConnectionMessage')
  785. .attr("data-i18n", reconnectingKey)
  786. .text(APP.translation.translateString(reconnectingKey))
  787. .css({display: "block"});
  788. },
  789. /**
  790. * Indicates that the video has been restored.
  791. */
  792. onVideoRestored () {
  793. this.enableVideoProblemFilter(false);
  794. $('#videoConnectionMessage').css({display: "none"});
  795. },
  796. enableVideoProblemFilter (enable) {
  797. if (!largeVideo) {
  798. return;
  799. }
  800. largeVideo.enableVideoProblemFilter(enable);
  801. },
  802. isLargeVideoVisible () {
  803. return this.isLargeContainerTypeVisible(VideoContainerType);
  804. },
  805. isCurrentlyOnLarge (id) {
  806. return largeVideo && largeVideo.id === id;
  807. },
  808. updateLargeVideo (id, forceUpdate) {
  809. if (!largeVideo) {
  810. return;
  811. }
  812. let isOnLarge = this.isCurrentlyOnLarge(id);
  813. let currentId = largeVideo.id;
  814. if (!isOnLarge || forceUpdate) {
  815. if (id !== currentId) {
  816. eventEmitter.emit(UIEvents.SELECTED_ENDPOINT, id);
  817. }
  818. if (currentId) {
  819. var oldSmallVideo = this.getSmallVideo(currentId);
  820. }
  821. let smallVideo = this.getSmallVideo(id);
  822. let videoType = this.getRemoteVideoType(id);
  823. largeVideo.updateLargeVideo(
  824. id,
  825. smallVideo.videoStream,
  826. videoType
  827. ).then(function() {
  828. // update current small video and the old one
  829. smallVideo.updateView();
  830. oldSmallVideo && oldSmallVideo.updateView();
  831. }, function () {
  832. // use clicked other video during update, nothing to do.
  833. });
  834. } else if (currentId) {
  835. let currentSmallVideo = this.getSmallVideo(currentId);
  836. currentSmallVideo.updateView();
  837. }
  838. },
  839. addLargeVideoContainer (type, container) {
  840. largeVideo && largeVideo.addContainer(type, container);
  841. },
  842. removeLargeVideoContainer (type) {
  843. largeVideo && largeVideo.removeContainer(type);
  844. },
  845. /**
  846. * @returns Promise
  847. */
  848. showLargeVideoContainer (type, show) {
  849. if (!largeVideo) {
  850. return Promise.reject();
  851. }
  852. let isVisible = this.isLargeContainerTypeVisible(type);
  853. if (isVisible === show) {
  854. return Promise.resolve();
  855. }
  856. // if !show then use default type - large video
  857. return largeVideo.showContainer(show ? type : VideoContainerType);
  858. },
  859. isLargeContainerTypeVisible (type) {
  860. return largeVideo && largeVideo.state === type;
  861. },
  862. /**
  863. * Returns the id of the current video shown on large.
  864. * Currently used by tests (troture).
  865. */
  866. getLargeVideoID () {
  867. return largeVideo.id;
  868. }
  869. };
  870. export default VideoLayout;