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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* global $, APP, interfaceConfig, config*/
  2. import UIEvents from "../../../service/UI/UIEvents";
  3. import UIUtil from "../util/UIUtil";
  4. const thumbAspectRatio = 1 / 1;
  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. */
  61. calculateThumbnailSize () {
  62. let availableHeight = interfaceConfig.FILM_STRIP_MAX_HEIGHT;
  63. let numvids = this.getThumbs(true).length;
  64. let localVideoContainer = $("#localVideoContainer");
  65. /**
  66. * If the videoAreaAvailableWidth is set we use this one to calculate
  67. * the filmStrip width, because we're probably in a state where the
  68. * film strip size hasn't been updated yet, but it will be.
  69. */
  70. let videoAreaAvailableWidth
  71. = UIUtil.getAvailableVideoWidth()
  72. - UIUtil.parseCssInt(this.filmStrip.css('right'), 10)
  73. - UIUtil.parseCssInt(this.filmStrip.css('paddingLeft'), 10)
  74. - UIUtil.parseCssInt(this.filmStrip.css('paddingRight'), 10)
  75. - UIUtil.parseCssInt(this.filmStrip.css('borderLeftWidth'), 10)
  76. - UIUtil.parseCssInt(this.filmStrip.css('borderRightWidth'), 10)
  77. - 5;
  78. let availableWidth = videoAreaAvailableWidth;
  79. // If the number of videos is 0 or undefined we don't need to calculate
  80. // further.
  81. if (numvids)
  82. availableWidth = Math.floor(
  83. (videoAreaAvailableWidth - numvids * (
  84. UIUtil.parseCssInt(
  85. localVideoContainer.css('borderLeftWidth'), 10)
  86. + UIUtil.parseCssInt(
  87. localVideoContainer.css('borderRightWidth'), 10)
  88. + UIUtil.parseCssInt(
  89. localVideoContainer.css('paddingLeft'), 10)
  90. + UIUtil.parseCssInt(
  91. localVideoContainer.css('paddingRight'), 10)
  92. + UIUtil.parseCssInt(
  93. localVideoContainer.css('marginLeft'), 10)
  94. + UIUtil.parseCssInt(
  95. localVideoContainer.css('marginRight'), 10)))
  96. / numvids);
  97. let maxHeight
  98. // If the MAX_HEIGHT property hasn't been specified
  99. // we have the static value.
  100. = Math.min( interfaceConfig.FILM_STRIP_MAX_HEIGHT || 120,
  101. availableHeight);
  102. availableHeight
  103. = Math.min( maxHeight, window.innerHeight - 18);
  104. if (availableHeight < availableWidth) {
  105. availableWidth = availableHeight;
  106. }
  107. else
  108. availableHeight = availableWidth;
  109. return {
  110. thumbWidth: availableWidth,
  111. thumbHeight: availableHeight
  112. };
  113. },
  114. resizeThumbnails (thumbWidth, thumbHeight,
  115. animate = false, forceUpdate = false) {
  116. return new Promise(resolve => {
  117. this.getThumbs(!forceUpdate).animate({
  118. height: thumbHeight,
  119. width: thumbWidth
  120. }, {
  121. queue: false,
  122. duration: animate ? 500 : 0,
  123. complete: resolve
  124. });
  125. this.filmStrip.animate({
  126. // adds 2 px because of small video 1px border
  127. height: thumbHeight + 2
  128. }, {
  129. queue: false,
  130. duration: animate ? 500 : 0
  131. });
  132. if (!animate) {
  133. resolve();
  134. }
  135. });
  136. },
  137. getThumbs (only_visible = false) {
  138. let selector = 'span';
  139. if (only_visible) {
  140. selector += ':visible';
  141. }
  142. // Exclude the local video container if it has been hidden.
  143. if ($("#localVideoContainer").hasClass("hidden"))
  144. return this.filmStrip.children(selector)
  145. .not("#localVideoContainer");
  146. else
  147. return this.filmStrip.children(selector);
  148. }
  149. };
  150. export default FilmStrip;