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

FilmStrip.js 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. /* global $, APP, JitsiMeetJS, interfaceConfig */
  2. import UIEvents from "../../../service/UI/UIEvents";
  3. import UIUtil from "../util/UIUtil";
  4. const FilmStrip = {
  5. /**
  6. *
  7. * @param eventEmitter the {EventEmitter} through which {FilmStrip} is to
  8. * emit/fire {UIEvents} (such as {UIEvents.TOGGLED_FILM_STRIP}).
  9. */
  10. init (eventEmitter) {
  11. this.iconMenuDownClassName = 'icon-menu-down';
  12. this.iconMenuUpClassName = 'icon-menu-up';
  13. this.filmStripContainerClassName = 'filmstrip';
  14. this.filmStrip = $('#remoteVideos');
  15. this.eventEmitter = eventEmitter;
  16. this._initFilmStripToolbar();
  17. this.registerListeners();
  18. },
  19. /**
  20. * Initializes the filmstrip toolbar
  21. */
  22. _initFilmStripToolbar() {
  23. let toolbar = this._generateFilmStripToolbar();
  24. let className = this.filmStripContainerClassName;
  25. let container = document.querySelector(`.${className}`);
  26. UIUtil.prependChild(container, toolbar);
  27. let iconSelector = '#hideVideoToolbar i';
  28. this.toggleFilmStripIcon = document.querySelector(iconSelector);
  29. },
  30. /**
  31. * Generates HTML layout for filmstrip toolbar
  32. * @returns {HTMLElement}
  33. * @private
  34. */
  35. _generateFilmStripToolbar() {
  36. let container = document.createElement('div');
  37. let isVisible = this.isFilmStripVisible();
  38. container.className = 'filmstrip__toolbar';
  39. container.innerHTML = `
  40. <button id="hideVideoToolbar">
  41. <i class="icon-menu-${isVisible ? 'down' : 'up'}">
  42. </i>
  43. </button>
  44. `;
  45. return container;
  46. },
  47. /**
  48. * Attach 'click' listener to "hide filmstrip" button
  49. */
  50. registerListeners() {
  51. let toggleFilmstripMethod = this.toggleFilmStrip.bind(this);
  52. let selector = '#hideVideoToolbar';
  53. $('#videospace').on('click', selector, toggleFilmstripMethod);
  54. this._registerToggleFilmstripShortcut();
  55. },
  56. /**
  57. * Registering toggle filmstrip shortcut
  58. * @private
  59. */
  60. _registerToggleFilmstripShortcut() {
  61. let shortcut = 'F';
  62. let shortcutAttr = 'filmstripPopover';
  63. let description = 'keyboardShortcuts.toggleFilmstrip';
  64. let handler = () => {
  65. JitsiMeetJS.analytics.sendEvent('toolbar.filmstrip.toggled');
  66. this.eventEmitter.emit(UIEvents.TOGGLE_FILM_STRIP);
  67. };
  68. APP.keyboardshortcut.registerShortcut(
  69. shortcut,
  70. shortcutAttr,
  71. handler,
  72. description
  73. );
  74. },
  75. /**
  76. * Changes classes of icon for showing down state
  77. */
  78. showMenuDownIcon() {
  79. let icon = this.toggleFilmStripIcon;
  80. icon.classList.add(this.iconMenuDownClassName);
  81. icon.classList.remove(this.iconMenuUpClassName);
  82. },
  83. /**
  84. * Changes classes of icon for showing up state
  85. */
  86. showMenuUpIcon() {
  87. let icon = this.toggleFilmStripIcon;
  88. icon.classList.add(this.iconMenuUpClassName);
  89. icon.classList.remove(this.iconMenuDownClassName);
  90. },
  91. /**
  92. * Toggles the visibility of the film strip.
  93. *
  94. * @param visible optional {Boolean} which specifies the desired visibility
  95. * of the film strip. If not specified, the visibility will be flipped
  96. * (i.e. toggled); otherwise, the visibility will be set to the specified
  97. * value.
  98. */
  99. toggleFilmStrip(visible) {
  100. let isVisibleDefined = typeof visible === 'boolean';
  101. if (!isVisibleDefined) {
  102. visible = this.isFilmStripVisible();
  103. } else if (this.isFilmStripVisible() === visible) {
  104. return;
  105. }
  106. this.filmStrip.toggleClass("hidden");
  107. if (!visible) {
  108. this.showMenuDownIcon();
  109. } else {
  110. this.showMenuUpIcon();
  111. }
  112. // Emit/fire UIEvents.TOGGLED_FILM_STRIP.
  113. var eventEmitter = this.eventEmitter;
  114. if (eventEmitter) {
  115. eventEmitter.emit(
  116. UIEvents.TOGGLED_FILM_STRIP,
  117. this.isFilmStripVisible());
  118. }
  119. },
  120. /**
  121. * Shows if filmstrip is visible
  122. * @returns {boolean}
  123. */
  124. isFilmStripVisible() {
  125. return !this.filmStrip.hasClass('hidden');
  126. },
  127. setupFilmStripOnly() {
  128. this.filmStrip.css({
  129. padding: "0px 0px 18px 0px",
  130. right: 0
  131. });
  132. },
  133. /**
  134. * Returns the height of filmstrip
  135. * @returns {number} height
  136. */
  137. getFilmStripHeight() {
  138. if (this.isFilmStripVisible()) {
  139. return this.filmStrip.outerHeight();
  140. } else {
  141. return 0;
  142. }
  143. },
  144. /**
  145. * Returns the width of filmstip
  146. * @returns {number} width
  147. */
  148. getFilmStripWidth() {
  149. return this.filmStrip.innerWidth()
  150. - parseInt(this.filmStrip.css('paddingLeft'), 10)
  151. - parseInt(this.filmStrip.css('paddingRight'), 10);
  152. },
  153. /**
  154. * Calculates the size for thumbnails: local and remote one
  155. * @returns {*|{localVideo, remoteVideo}}
  156. */
  157. calculateThumbnailSize() {
  158. let availableSizes = this.calculateAvailableSize();
  159. let width = availableSizes.availableWidth;
  160. let height = availableSizes.availableHeight;
  161. return this.calculateThumbnailSizeFromAvailable(width, height);
  162. },
  163. /**
  164. * Calculates available size for one thumbnail according to
  165. * the current window size.
  166. *
  167. * @returns {{availableWidth: number, availableHeight: number}}
  168. */
  169. calculateAvailableSize() {
  170. let availableHeight = interfaceConfig.FILM_STRIP_MAX_HEIGHT;
  171. let thumbs = this.getThumbs(true);
  172. let numvids = thumbs.remoteThumbs.length;
  173. let localVideoContainer = $("#localVideoContainer");
  174. /**
  175. * If the videoAreaAvailableWidth is set we use this one to calculate
  176. * the filmStrip width, because we're probably in a state where the
  177. * film strip size hasn't been updated yet, but it will be.
  178. */
  179. let videoAreaAvailableWidth
  180. = UIUtil.getAvailableVideoWidth()
  181. - this.getFilmstripPanelsWidth()
  182. - UIUtil.parseCssInt(this.filmStrip.css('right'), 10)
  183. - UIUtil.parseCssInt(this.filmStrip.css('paddingLeft'), 10)
  184. - UIUtil.parseCssInt(this.filmStrip.css('paddingRight'), 10)
  185. - UIUtil.parseCssInt(this.filmStrip.css('borderLeftWidth'), 10)
  186. - UIUtil.parseCssInt(this.filmStrip.css('borderRightWidth'), 10)
  187. - 5;
  188. let availableWidth = videoAreaAvailableWidth;
  189. // If local thumb is not hidden
  190. if(thumbs.localThumb) {
  191. availableWidth = Math.floor(
  192. (videoAreaAvailableWidth - (
  193. UIUtil.parseCssInt(
  194. localVideoContainer.css('borderLeftWidth'), 10)
  195. + UIUtil.parseCssInt(
  196. localVideoContainer.css('borderRightWidth'), 10)
  197. + UIUtil.parseCssInt(
  198. localVideoContainer.css('paddingLeft'), 10)
  199. + UIUtil.parseCssInt(
  200. localVideoContainer.css('paddingRight'), 10)
  201. + UIUtil.parseCssInt(
  202. localVideoContainer.css('marginLeft'), 10)
  203. + UIUtil.parseCssInt(
  204. localVideoContainer.css('marginRight'), 10)))
  205. );
  206. }
  207. // If the number of videos is 0 or undefined we don't need to calculate
  208. // further.
  209. if (numvids) {
  210. let remoteVideoContainer = thumbs.remoteThumbs.eq(0);
  211. availableWidth = Math.floor(
  212. (videoAreaAvailableWidth - numvids * (
  213. UIUtil.parseCssInt(
  214. remoteVideoContainer.css('borderLeftWidth'), 10)
  215. + UIUtil.parseCssInt(
  216. remoteVideoContainer.css('borderRightWidth'), 10)
  217. + UIUtil.parseCssInt(
  218. remoteVideoContainer.css('paddingLeft'), 10)
  219. + UIUtil.parseCssInt(
  220. remoteVideoContainer.css('paddingRight'), 10)
  221. + UIUtil.parseCssInt(
  222. remoteVideoContainer.css('marginLeft'), 10)
  223. + UIUtil.parseCssInt(
  224. remoteVideoContainer.css('marginRight'), 10)))
  225. );
  226. }
  227. let maxHeight
  228. // If the MAX_HEIGHT property hasn't been specified
  229. // we have the static value.
  230. = Math.min(interfaceConfig.FILM_STRIP_MAX_HEIGHT || 120,
  231. availableHeight);
  232. availableHeight
  233. = Math.min(maxHeight, window.innerHeight - 18);
  234. return { availableWidth, availableHeight };
  235. },
  236. /**
  237. *
  238. * Calculates width of all panels inside filmstrip
  239. * @returns {number} width
  240. */
  241. getFilmstripPanelsWidth() {
  242. let filmstripPanelsWidth = 0;
  243. let className = this.filmStripContainerClassName;
  244. $(`.${className}`)
  245. .children()
  246. .each(function () {
  247. if (this.id !== 'remoteVideos') {
  248. filmstripPanelsWidth += $(this).outerWidth();
  249. }
  250. });
  251. return filmstripPanelsWidth;
  252. },
  253. /**
  254. Calculate the thumbnail size in order to fit all the thumnails in passed
  255. * dimensions.
  256. * NOTE: Here we assume that the remote and local thumbnails are with the
  257. * same height.
  258. * @param {int} availableWidth the maximum width for all thumbnails
  259. * @param {int} availableHeight the maximum height for all thumbnails
  260. * @returns {{localVideo, remoteVideo}}
  261. */
  262. calculateThumbnailSizeFromAvailable(availableWidth, availableHeight) {
  263. /**
  264. * Let:
  265. * lW - width of the local thumbnail
  266. * rW - width of the remote thumbnail
  267. * h - the height of the thumbnails
  268. * remoteRatio - width:height for the remote thumbnail
  269. * localRatio - width:height for the local thumbnail
  270. * numberRemoteThumbs - number of remote thumbnails (we have only one
  271. * local thumbnail)
  272. *
  273. * Since the height for local thumbnail = height for remote thumbnail
  274. * and we know the ratio (width:height) for the local and for the
  275. * remote thumbnail we can find rW/lW:
  276. * rW / remoteRatio = lW / localRatio then -
  277. * remoteLocalWidthRatio = rW / lW = remoteRatio / localRatio
  278. * and rW = lW * remoteRatio / localRatio = lW * remoteLocalWidthRatio
  279. * And the total width for the thumbnails is:
  280. * totalWidth = rW * numberRemoteThumbs + lW
  281. * = lW * remoteLocalWidthRatio * numberRemoteThumbs + lW =
  282. * lW * (remoteLocalWidthRatio * numberRemoteThumbs + 1)
  283. * and the h = lW/localRatio
  284. *
  285. * In order to fit all the thumbails in the area defined by
  286. * availableWidth * availableHeight we should check one of the
  287. * following options:
  288. * 1) if availableHeight == h - totalWidth should be less than
  289. * availableWidth
  290. * 2) if availableWidth == totalWidth - h should be less than
  291. * availableHeight
  292. *
  293. * 1) or 2) will be true and we are going to use it to calculate all
  294. * sizes.
  295. *
  296. * if 1) is true that means that
  297. * availableHeight/h > availableWidth/totalWidth otherwise 2) is true
  298. */
  299. const numberRemoteThumbs = this.getThumbs(true).remoteThumbs.length;
  300. const remoteLocalWidthRatio = interfaceConfig.REMOTE_THUMBNAIL_RATIO /
  301. interfaceConfig.LOCAL_THUMBNAIL_RATIO;
  302. const lW = Math.min(availableWidth /
  303. (remoteLocalWidthRatio * numberRemoteThumbs + 1), availableHeight *
  304. interfaceConfig.LOCAL_THUMBNAIL_RATIO);
  305. const h = lW / interfaceConfig.LOCAL_THUMBNAIL_RATIO;
  306. return {
  307. localVideo:{
  308. thumbWidth: lW,
  309. thumbHeight: h
  310. },
  311. remoteVideo: {
  312. thumbWidth: lW * remoteLocalWidthRatio,
  313. thumbHeight: h
  314. }
  315. };
  316. },
  317. /**
  318. * Resizes thumbnails
  319. * @param local
  320. * @param remote
  321. * @param animate
  322. * @param forceUpdate
  323. * @returns {Promise}
  324. */
  325. resizeThumbnails(local, remote,
  326. animate = false, forceUpdate = false) {
  327. return new Promise(resolve => {
  328. let thumbs = this.getThumbs(!forceUpdate);
  329. if(thumbs.localThumb)
  330. thumbs.localThumb.animate({
  331. height: local.thumbHeight,
  332. width: local.thumbWidth
  333. }, {
  334. queue: false,
  335. duration: animate ? 500 : 0,
  336. complete: resolve
  337. });
  338. if(thumbs.remoteThumbs)
  339. thumbs.remoteThumbs.animate({
  340. height: remote.thumbHeight,
  341. width: remote.thumbWidth
  342. }, {
  343. queue: false,
  344. duration: animate ? 500 : 0,
  345. complete: resolve
  346. });
  347. this.filmStrip.animate({
  348. // adds 2 px because of small video 1px border
  349. height: remote.thumbHeight + 2
  350. }, {
  351. queue: false,
  352. duration: animate ? 500 : 0
  353. });
  354. if (!animate) {
  355. resolve();
  356. }
  357. });
  358. },
  359. /**
  360. * Returns thumbnails of the filmstrip
  361. * @param only_visible
  362. * @returns {object} thumbnails
  363. */
  364. getThumbs(only_visible = false) {
  365. let selector = 'span';
  366. if (only_visible) {
  367. selector += ':visible';
  368. }
  369. let localThumb = $("#localVideoContainer");
  370. let remoteThumbs = this.filmStrip.children(selector)
  371. .not("#localVideoContainer");
  372. // Exclude the local video container if it has been hidden.
  373. if (localThumb.hasClass("hidden")) {
  374. return { remoteThumbs };
  375. } else {
  376. return { remoteThumbs, localThumb };
  377. }
  378. }
  379. };
  380. export default FilmStrip;