您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

FilmStrip.js 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /* global $, 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.filmStrip = $('#remoteVideos');
  12. this.eventEmitter = eventEmitter;
  13. },
  14. /**
  15. * Toggles the visibility of the film strip.
  16. *
  17. * @param visible optional {Boolean} which specifies the desired visibility
  18. * of the film strip. If not specified, the visibility will be flipped
  19. * (i.e. toggled); otherwise, the visibility will be set to the specified
  20. * value.
  21. */
  22. toggleFilmStrip (visible) {
  23. if (typeof visible === 'boolean'
  24. && this.isFilmStripVisible() == visible) {
  25. return;
  26. }
  27. this.filmStrip.toggleClass("hidden");
  28. // Emit/fire UIEvents.TOGGLED_FILM_STRIP.
  29. var eventEmitter = this.eventEmitter;
  30. if (eventEmitter) {
  31. eventEmitter.emit(
  32. UIEvents.TOGGLED_FILM_STRIP,
  33. this.isFilmStripVisible());
  34. }
  35. },
  36. isFilmStripVisible () {
  37. return !this.filmStrip.hasClass('hidden');
  38. },
  39. setupFilmStripOnly () {
  40. this.filmStrip.css({
  41. padding: "0px 0px 18px 0px",
  42. right: 0
  43. });
  44. },
  45. getFilmStripHeight () {
  46. if (this.isFilmStripVisible()) {
  47. return this.filmStrip.outerHeight();
  48. } else {
  49. return 0;
  50. }
  51. },
  52. getFilmStripWidth () {
  53. return this.filmStrip.innerWidth()
  54. - parseInt(this.filmStrip.css('paddingLeft'), 10)
  55. - parseInt(this.filmStrip.css('paddingRight'), 10);
  56. },
  57. calculateThumbnailSize() {
  58. let availableSizes = this.calculateAvailableSize();
  59. let width = availableSizes.availableWidth;
  60. let height = availableSizes.availableHeight;
  61. return this.calculateThumbnailSizeFromAvailable(width, height);
  62. },
  63. /**
  64. * Normalizes local and remote thumbnail ratios
  65. */
  66. normalizeThumbnailRatio () {
  67. let remoteHeightRatio = interfaceConfig.REMOTE_THUMBNAIL_RATIO_HEIGHT;
  68. let remoteWidthRatio = interfaceConfig.REMOTE_THUMBNAIL_RATIO_WIDTH;
  69. let localHeightRatio = interfaceConfig.LOCAL_THUMBNAIL_RATIO_HEIGHT;
  70. let localWidthRatio = interfaceConfig.LOCAL_THUMBNAIL_RATIO_WIDTH;
  71. let commonHeightRatio = remoteHeightRatio * localHeightRatio;
  72. let localRatioCoefficient = localWidthRatio / localHeightRatio;
  73. let remoteRatioCoefficient = remoteWidthRatio / remoteHeightRatio;
  74. remoteWidthRatio = commonHeightRatio * remoteRatioCoefficient;
  75. remoteHeightRatio = commonHeightRatio;
  76. localWidthRatio = commonHeightRatio * localRatioCoefficient;
  77. localHeightRatio = commonHeightRatio;
  78. let localRatio = {
  79. widthRatio: localWidthRatio,
  80. heightRatio: localHeightRatio
  81. };
  82. let remoteRatio = {
  83. widthRatio: remoteWidthRatio,
  84. heightRatio: remoteHeightRatio
  85. };
  86. return { localRatio, remoteRatio };
  87. },
  88. calculateAvailableSize() {
  89. let availableHeight = interfaceConfig.FILM_STRIP_MAX_HEIGHT;
  90. let thumbs = this.getThumbs(true);
  91. let numvids = thumbs.remoteThumbs.length;
  92. let localVideoContainer = $("#localVideoContainer");
  93. /**
  94. * If the videoAreaAvailableWidth is set we use this one to calculate
  95. * the filmStrip width, because we're probably in a state where the
  96. * film strip size hasn't been updated yet, but it will be.
  97. */
  98. let videoAreaAvailableWidth
  99. = UIUtil.getAvailableVideoWidth()
  100. - UIUtil.parseCssInt(this.filmStrip.css('right'), 10)
  101. - UIUtil.parseCssInt(this.filmStrip.css('paddingLeft'), 10)
  102. - UIUtil.parseCssInt(this.filmStrip.css('paddingRight'), 10)
  103. - UIUtil.parseCssInt(this.filmStrip.css('borderLeftWidth'), 10)
  104. - UIUtil.parseCssInt(this.filmStrip.css('borderRightWidth'), 10)
  105. - 5;
  106. let availableWidth = videoAreaAvailableWidth;
  107. // If local thumb is not hidden
  108. if(thumbs.localThumb) {
  109. availableWidth = Math.floor(
  110. (videoAreaAvailableWidth - (
  111. UIUtil.parseCssInt(
  112. localVideoContainer.css('borderLeftWidth'), 10)
  113. + UIUtil.parseCssInt(
  114. localVideoContainer.css('borderRightWidth'), 10)
  115. + UIUtil.parseCssInt(
  116. localVideoContainer.css('paddingLeft'), 10)
  117. + UIUtil.parseCssInt(
  118. localVideoContainer.css('paddingRight'), 10)
  119. + UIUtil.parseCssInt(
  120. localVideoContainer.css('marginLeft'), 10)
  121. + UIUtil.parseCssInt(
  122. localVideoContainer.css('marginRight'), 10)))
  123. );
  124. }
  125. // If the number of videos is 0 or undefined we don't need to calculate
  126. // further.
  127. if (numvids) {
  128. let remoteVideoContainer = thumbs.remoteThumbs.eq(0);
  129. availableWidth = Math.floor(
  130. (videoAreaAvailableWidth - numvids * (
  131. UIUtil.parseCssInt(
  132. remoteVideoContainer.css('borderLeftWidth'), 10)
  133. + UIUtil.parseCssInt(
  134. remoteVideoContainer.css('borderRightWidth'), 10)
  135. + UIUtil.parseCssInt(
  136. remoteVideoContainer.css('paddingLeft'), 10)
  137. + UIUtil.parseCssInt(
  138. remoteVideoContainer.css('paddingRight'), 10)
  139. + UIUtil.parseCssInt(
  140. remoteVideoContainer.css('marginLeft'), 10)
  141. + UIUtil.parseCssInt(
  142. remoteVideoContainer.css('marginRight'), 10)))
  143. );
  144. }
  145. let maxHeight
  146. // If the MAX_HEIGHT property hasn't been specified
  147. // we have the static value.
  148. = Math.min(interfaceConfig.FILM_STRIP_MAX_HEIGHT || 120,
  149. availableHeight);
  150. availableHeight
  151. = Math.min(maxHeight, window.innerHeight - 18);
  152. return { availableWidth, availableHeight };
  153. },
  154. calculateThumbnailSizeFromAvailable(availableWidth, availableHeight) {
  155. let { localRatio, remoteRatio } = this.normalizeThumbnailRatio();
  156. let { remoteThumbs } = this.getThumbs(true);
  157. let remoteProportion = remoteRatio.widthRatio * remoteThumbs.length;
  158. let widthProportion = remoteProportion + localRatio.widthRatio;
  159. let heightUnit = availableHeight / localRatio.heightRatio;
  160. let widthUnit = availableWidth / widthProportion;
  161. if (heightUnit < widthUnit) {
  162. widthUnit = heightUnit;
  163. }
  164. else
  165. heightUnit = widthUnit;
  166. let localVideo = {
  167. thumbWidth: widthUnit * localRatio.widthRatio,
  168. thumbHeight: heightUnit * localRatio.heightRatio
  169. };
  170. let remoteVideo = {
  171. thumbWidth: widthUnit * remoteRatio.widthRatio,
  172. thumbHeight: widthUnit * remoteRatio.heightRatio
  173. };
  174. return {
  175. localVideo,
  176. remoteVideo
  177. };
  178. },
  179. resizeThumbnails (local, remote,
  180. animate = false, forceUpdate = false) {
  181. return new Promise(resolve => {
  182. let thumbs = this.getThumbs(!forceUpdate);
  183. if(thumbs.localThumb)
  184. thumbs.localThumb.animate({
  185. height: local.thumbHeight,
  186. width: local.thumbWidth
  187. }, {
  188. queue: false,
  189. duration: animate ? 500 : 0,
  190. complete: resolve
  191. });
  192. if(thumbs.remoteThumbs)
  193. thumbs.remoteThumbs.animate({
  194. height: remote.thumbHeight,
  195. width: remote.thumbWidth
  196. }, {
  197. queue: false,
  198. duration: animate ? 500 : 0,
  199. complete: resolve
  200. });
  201. this.filmStrip.animate({
  202. // adds 2 px because of small video 1px border
  203. height: remote.thumbHeight + 2
  204. }, {
  205. queue: false,
  206. duration: animate ? 500 : 0
  207. });
  208. if (!animate) {
  209. resolve();
  210. }
  211. });
  212. },
  213. getThumbs (only_visible = false) {
  214. let selector = 'span';
  215. if (only_visible) {
  216. selector += ':visible';
  217. }
  218. let localThumb = $("#localVideoContainer");
  219. let remoteThumbs = this.filmStrip.children(selector)
  220. .not("#localVideoContainer");
  221. // Exclude the local video container if it has been hidden.
  222. if (localThumb.hasClass("hidden")) {
  223. return { remoteThumbs };
  224. } else {
  225. return { remoteThumbs, localThumb };
  226. }
  227. }
  228. };
  229. export default FilmStrip;