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.

FilmStrip.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* global $, APP, interfaceConfig, config*/
  2. import UIEvents from "../../../service/UI/UIEvents";
  3. import UIUtil from "../util/UIUtil";
  4. const thumbAspectRatio = 16.0 / 9.0;
  5. const FilmStrip = {
  6. /**
  7. *
  8. * @param eventEmitter the {EventEmitter} through which {FilmStrip} is to
  9. * emit/fire {UIEvents} (such as {UIEvents.TOGGLED_FILM_STRIP}).
  10. */
  11. init (eventEmitter) {
  12. this.filmStrip = $('#remoteVideos');
  13. this.eventEmitter = eventEmitter;
  14. },
  15. /**
  16. * Toggles the visibility of the film strip.
  17. *
  18. * @param visible optional {Boolean} which specifies the desired visibility
  19. * of the film strip. If not specified, the visibility will be flipped
  20. * (i.e. toggled); otherwise, the visibility will be set to the specified
  21. * value.
  22. */
  23. toggleFilmStrip (visible) {
  24. if (typeof visible === 'boolean'
  25. && this.isFilmStripVisible() == visible) {
  26. return;
  27. }
  28. this.filmStrip.toggleClass("hidden");
  29. // Emit/fire UIEvents.TOGGLED_FILM_STRIP.
  30. var eventEmitter = this.eventEmitter;
  31. if (eventEmitter) {
  32. eventEmitter.emit(
  33. UIEvents.TOGGLED_FILM_STRIP,
  34. this.isFilmStripVisible());
  35. }
  36. },
  37. isFilmStripVisible () {
  38. return !this.filmStrip.hasClass('hidden');
  39. },
  40. setupFilmStripOnly () {
  41. this.filmStrip.css({
  42. padding: "0px 0px 18px 0px",
  43. right: 0
  44. });
  45. },
  46. getFilmStripHeight () {
  47. if (this.isFilmStripVisible()) {
  48. return this.filmStrip.outerHeight();
  49. } else {
  50. return 0;
  51. }
  52. },
  53. getFilmStripWidth () {
  54. return this.filmStrip.innerWidth()
  55. - parseInt(this.filmStrip.css('paddingLeft'), 10)
  56. - parseInt(this.filmStrip.css('paddingRight'), 10);
  57. },
  58. /**
  59. * Calculates the thumbnail size.
  60. * @param videoAreaAvailableWidth the currently available video area width
  61. * that we want to take into account when calculating the film strip width.
  62. */
  63. calculateThumbnailSize (isSideBarVisible) {
  64. // Calculate the available height, which is the inner window height
  65. // minus 39px for the header minus 2px for the delimiter lines on the
  66. // top and bottom of the large video, minus the 36px space inside the
  67. // remoteVideos container used for highlighting shadow.
  68. let availableHeight = 100;
  69. let numvids = this.getThumbs(true).length;
  70. let localVideoContainer = $("#localVideoContainer");
  71. /**
  72. * If the videoAreaAvailableWidth is set we use this one to calculate
  73. * the filmStrip width, because we're probably in a state where the
  74. * film strip size hasn't been updated yet, but it will be.
  75. */
  76. let videoAreaAvailableWidth
  77. = UIUtil.getAvailableVideoWidth(isSideBarVisible)
  78. - parseInt(this.filmStrip.css('right'), 10)
  79. - parseInt(this.filmStrip.css('paddingLeft'), 10)
  80. - parseInt(this.filmStrip.css('paddingRight'), 10)
  81. - parseInt(this.filmStrip.css('borderLeftWidth'), 10)
  82. - parseInt(this.filmStrip.css('borderRightWidth'), 10) - 5;
  83. let availableWidth = Math.floor(
  84. (videoAreaAvailableWidth - numvids * (
  85. parseInt(localVideoContainer.css('borderLeftWidth'), 10)
  86. + parseInt(localVideoContainer.css('borderRightWidth'), 10)
  87. + parseInt(localVideoContainer.css('paddingLeft'), 10)
  88. + parseInt(localVideoContainer.css('paddingRight'), 10)
  89. + parseInt(localVideoContainer.css('marginLeft'), 10)
  90. + parseInt(localVideoContainer.css('marginRight'), 10)))
  91. / numvids);
  92. let maxHeight
  93. // If the MAX_HEIGHT property hasn't been specified
  94. // we have the static value.
  95. = Math.min( interfaceConfig.FILM_STRIP_MAX_HEIGHT || 160,
  96. availableHeight);
  97. availableHeight
  98. = Math.min( maxHeight,
  99. availableWidth / thumbAspectRatio,
  100. window.innerHeight - 18);
  101. if (availableHeight < availableWidth / thumbAspectRatio) {
  102. availableWidth = Math.floor(availableHeight * thumbAspectRatio);
  103. }
  104. return {
  105. thumbWidth: availableWidth,
  106. thumbHeight: availableHeight
  107. };
  108. },
  109. resizeThumbnails (thumbWidth, thumbHeight,
  110. animate = false, forceUpdate = false) {
  111. return new Promise(resolve => {
  112. this.getThumbs(!forceUpdate).animate({
  113. height: thumbHeight,
  114. width: thumbWidth
  115. }, {
  116. queue: false,
  117. duration: animate ? 500 : 0,
  118. complete: resolve
  119. });
  120. this.filmStrip.animate({
  121. // adds 2 px because of small video 1px border
  122. height: thumbHeight + 2
  123. }, {
  124. queue: false,
  125. duration: animate ? 500 : 0
  126. });
  127. if (!animate) {
  128. resolve();
  129. }
  130. });
  131. },
  132. getThumbs (only_visible = false) {
  133. let selector = 'span';
  134. if (only_visible) {
  135. selector += ':visible';
  136. }
  137. return this.filmStrip.children(selector);
  138. }
  139. };
  140. export default FilmStrip;