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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. * @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. let availableHeight = interfaceConfig.FILM_STRIP_MAX_HEIGHT;
  65. let numvids = this.getThumbs(true).length;
  66. let localVideoContainer = $("#localVideoContainer");
  67. /**
  68. * If the videoAreaAvailableWidth is set we use this one to calculate
  69. * the filmStrip width, because we're probably in a state where the
  70. * film strip size hasn't been updated yet, but it will be.
  71. */
  72. let videoAreaAvailableWidth
  73. = UIUtil.getAvailableVideoWidth(isSideBarVisible)
  74. - parseInt(this.filmStrip.css('right'), 10)
  75. - parseInt(this.filmStrip.css('paddingLeft'), 10)
  76. - parseInt(this.filmStrip.css('paddingRight'), 10)
  77. - parseInt(this.filmStrip.css('borderLeftWidth'), 10)
  78. - parseInt(this.filmStrip.css('borderRightWidth'), 10) - 5;
  79. let availableWidth = Math.floor(
  80. (videoAreaAvailableWidth - numvids * (
  81. parseInt(localVideoContainer.css('borderLeftWidth'), 10)
  82. + parseInt(localVideoContainer.css('borderRightWidth'), 10)
  83. + parseInt(localVideoContainer.css('paddingLeft'), 10)
  84. + parseInt(localVideoContainer.css('paddingRight'), 10)
  85. + parseInt(localVideoContainer.css('marginLeft'), 10)
  86. + parseInt(localVideoContainer.css('marginRight'), 10)))
  87. / numvids);
  88. let maxHeight
  89. // If the MAX_HEIGHT property hasn't been specified
  90. // we have the static value.
  91. = Math.min( interfaceConfig.FILM_STRIP_MAX_HEIGHT || 120,
  92. availableHeight);
  93. availableHeight
  94. = Math.min( maxHeight, window.innerHeight - 18);
  95. if (availableHeight < availableWidth) {
  96. availableWidth = availableHeight;
  97. }
  98. else
  99. availableHeight = availableWidth;
  100. return {
  101. thumbWidth: availableWidth,
  102. thumbHeight: availableHeight
  103. };
  104. },
  105. resizeThumbnails (thumbWidth, thumbHeight,
  106. animate = false, forceUpdate = false) {
  107. return new Promise(resolve => {
  108. this.getThumbs(!forceUpdate).animate({
  109. height: thumbHeight,
  110. width: thumbWidth
  111. }, {
  112. queue: false,
  113. duration: animate ? 500 : 0,
  114. complete: resolve
  115. });
  116. this.filmStrip.animate({
  117. // adds 2 px because of small video 1px border
  118. height: thumbHeight + 2
  119. }, {
  120. queue: false,
  121. duration: animate ? 500 : 0
  122. });
  123. if (!animate) {
  124. resolve();
  125. }
  126. });
  127. },
  128. getThumbs (only_visible = false) {
  129. let selector = 'span';
  130. if (only_visible) {
  131. selector += ':visible';
  132. }
  133. return this.filmStrip.children(selector);
  134. }
  135. };
  136. export default FilmStrip;