Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

LargeVideoManager.js 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /* global $, APP, interfaceConfig */
  2. /* jshint -W101 */
  3. import Avatar from "../avatar/Avatar";
  4. import {createDeferred} from '../../util/helpers';
  5. import UIUtil from "../util/UIUtil";
  6. import {VideoContainer, VIDEO_CONTAINER_TYPE} from "./VideoContainer";
  7. /**
  8. * Manager for all Large containers.
  9. */
  10. export default class LargeVideoManager {
  11. constructor (emitter) {
  12. this.containers = {};
  13. this.state = VIDEO_CONTAINER_TYPE;
  14. this.videoContainer = new VideoContainer(
  15. () => this.resizeContainer(VIDEO_CONTAINER_TYPE), emitter);
  16. this.addContainer(VIDEO_CONTAINER_TYPE, this.videoContainer);
  17. // use the same video container to handle and desktop tracks
  18. this.addContainer("desktop", this.videoContainer);
  19. this.width = 0;
  20. this.height = 0;
  21. this.$container = $('#largeVideoContainer');
  22. this.$container.css({
  23. display: 'inline-block'
  24. });
  25. if (interfaceConfig.SHOW_JITSI_WATERMARK) {
  26. let leftWatermarkDiv
  27. = this.$container.find("div.watermark.leftwatermark");
  28. leftWatermarkDiv.css({display: 'block'});
  29. UIUtil.setLinkHref(
  30. leftWatermarkDiv.parent(),
  31. interfaceConfig.JITSI_WATERMARK_LINK);
  32. }
  33. if (interfaceConfig.SHOW_BRAND_WATERMARK) {
  34. let rightWatermarkDiv
  35. = this.$container.find("div.watermark.rightwatermark");
  36. rightWatermarkDiv.css({
  37. display: 'block',
  38. backgroundImage: 'url(images/rightwatermark.png)'
  39. });
  40. UIUtil.setLinkHref(
  41. rightWatermarkDiv.parent(),
  42. interfaceConfig.BRAND_WATERMARK_LINK);
  43. }
  44. if (interfaceConfig.SHOW_POWERED_BY) {
  45. this.$container.children("a.poweredby").css({display: 'block'});
  46. }
  47. this.$container.hover(
  48. e => this.onHoverIn(e),
  49. e => this.onHoverOut(e)
  50. );
  51. }
  52. onHoverIn (e) {
  53. if (!this.state) {
  54. return;
  55. }
  56. let container = this.getContainer(this.state);
  57. container.onHoverIn(e);
  58. }
  59. onHoverOut (e) {
  60. if (!this.state) {
  61. return;
  62. }
  63. let container = this.getContainer(this.state);
  64. container.onHoverOut(e);
  65. }
  66. get id () {
  67. let container = this.getContainer(this.state);
  68. return container.id;
  69. }
  70. scheduleLargeVideoUpdate () {
  71. if (this.updateInProcess || !this.newStreamData) {
  72. return;
  73. }
  74. this.updateInProcess = true;
  75. let container = this.getContainer(this.state);
  76. // Include hide()/fadeOut only if we're switching between users
  77. let preUpdate;
  78. if (this.newStreamData.id != this.id) {
  79. preUpdate = container.hide();
  80. } else {
  81. preUpdate = Promise.resolve();
  82. }
  83. preUpdate.then(() => {
  84. let {id, stream, videoType, resolve} = this.newStreamData;
  85. this.newStreamData = null;
  86. console.info("hover in %s", id);
  87. this.state = videoType;
  88. let container = this.getContainer(this.state);
  89. container.setStream(stream, videoType);
  90. // change the avatar url on large
  91. this.updateAvatar(Avatar.getAvatarUrl(id));
  92. // If we the continer is VIDEO_CONTAINER_TYPE, we need to check
  93. // its stream whether exist and is muted to set isVideoMuted
  94. // in rest of the cases it is false
  95. let isVideoMuted = false;
  96. if (videoType == VIDEO_CONTAINER_TYPE)
  97. isVideoMuted = stream ? stream.isMuted() : true;
  98. // show the avatar on large if needed
  99. container.showAvatar(isVideoMuted);
  100. let promise;
  101. // do not show stream if video is muted
  102. // but we still should show watermark
  103. if (isVideoMuted) {
  104. this.showWatermark(true);
  105. promise = Promise.resolve();
  106. } else {
  107. promise = container.show();
  108. }
  109. // resolve updateLargeVideo promise after everything is done
  110. promise.then(resolve);
  111. return promise;
  112. }).then(() => {
  113. // after everything is done check again if there are any pending
  114. // new streams.
  115. this.updateInProcess = false;
  116. this.scheduleLargeVideoUpdate();
  117. });
  118. }
  119. /**
  120. * Update large video.
  121. * Switches to large video even if previously other container was visible.
  122. * @param userID the userID of the participant associated with the stream
  123. * @param {JitsiTrack?} stream new stream
  124. * @param {string?} videoType new video type
  125. * @returns {Promise}
  126. */
  127. updateLargeVideo (userID, stream, videoType) {
  128. if (this.newStreamData) {
  129. this.newStreamData.reject();
  130. }
  131. this.newStreamData = createDeferred();
  132. this.newStreamData.id = userID;
  133. this.newStreamData.stream = stream;
  134. this.newStreamData.videoType = videoType;
  135. this.scheduleLargeVideoUpdate();
  136. return this.newStreamData.promise;
  137. }
  138. /**
  139. * Update container size.
  140. */
  141. updateContainerSize () {
  142. this.width = UIUtil.getAvailableVideoWidth();
  143. this.height = window.innerHeight;
  144. }
  145. /**
  146. * Resize Large container of specified type.
  147. * @param {string} type type of container which should be resized.
  148. * @param {boolean} [animate=false] if resize process should be animated.
  149. */
  150. resizeContainer (type, animate = false) {
  151. let container = this.getContainer(type);
  152. container.resize(this.width, this.height, animate);
  153. }
  154. /**
  155. * Resize all Large containers.
  156. * @param {boolean} animate if resize process should be animated.
  157. */
  158. resize (animate) {
  159. // resize all containers
  160. Object.keys(this.containers)
  161. .forEach(type => this.resizeContainer(type, animate));
  162. this.$container.animate({
  163. width: this.width,
  164. height: this.height
  165. }, {
  166. queue: false,
  167. duration: animate ? 500 : 0
  168. });
  169. }
  170. /**
  171. * Enables/disables the filter indicating a video problem to the user.
  172. *
  173. * @param enable <tt>true</tt> to enable, <tt>false</tt> to disable
  174. */
  175. enableVideoProblemFilter (enable) {
  176. this.videoContainer.enableVideoProblemFilter(enable);
  177. }
  178. /**
  179. * Updates the src of the dominant speaker avatar
  180. */
  181. updateAvatar (avatarUrl) {
  182. $("#dominantSpeakerAvatar").attr('src', avatarUrl);
  183. }
  184. /**
  185. * Show or hide watermark.
  186. * @param {boolean} show
  187. */
  188. showWatermark (show) {
  189. $('.watermark').css('visibility', show ? 'visible' : 'hidden');
  190. }
  191. /**
  192. * Add container of specified type.
  193. * @param {string} type container type
  194. * @param {LargeContainer} container container to add.
  195. */
  196. addContainer (type, container) {
  197. if (this.containers[type]) {
  198. throw new Error(`container of type ${type} already exist`);
  199. }
  200. this.containers[type] = container;
  201. this.resizeContainer(type);
  202. }
  203. /**
  204. * Get Large container of specified type.
  205. * @param {string} type container type.
  206. * @returns {LargeContainer}
  207. */
  208. getContainer (type) {
  209. let container = this.containers[type];
  210. if (!container) {
  211. throw new Error(`container of type ${type} doesn't exist`);
  212. }
  213. return container;
  214. }
  215. /**
  216. * Remove Large container of specified type.
  217. * @param {string} type container type.
  218. */
  219. removeContainer (type) {
  220. if (!this.containers[type]) {
  221. throw new Error(`container of type ${type} doesn't exist`);
  222. }
  223. delete this.containers[type];
  224. }
  225. /**
  226. * Show Large container of specified type.
  227. * Does nothing if such container is already visible.
  228. * @param {string} type container type.
  229. * @returns {Promise}
  230. */
  231. showContainer (type) {
  232. if (this.state === type) {
  233. return Promise.resolve();
  234. }
  235. let oldContainer = this.containers[this.state];
  236. if (this.state === VIDEO_CONTAINER_TYPE) {
  237. this.showWatermark(false);
  238. }
  239. oldContainer.hide();
  240. this.state = type;
  241. let container = this.getContainer(type);
  242. return container.show().then(() => {
  243. if (type === VIDEO_CONTAINER_TYPE) {
  244. this.showWatermark(true);
  245. }
  246. });
  247. }
  248. /**
  249. * Changes the flipX state of the local video.
  250. * @param val {boolean} true if flipped.
  251. */
  252. onLocalFlipXChange(val) {
  253. this.videoContainer.setLocalFlipX(val);
  254. }
  255. }