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.

LocalVideo.js 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /* global $, config, interfaceConfig, APP */
  2. /* eslint-disable no-unused-vars */
  3. import React, { Component } from 'react';
  4. import ReactDOM from 'react-dom';
  5. import { Provider } from 'react-redux';
  6. import { JitsiTrackEvents } from '../../../react/features/base/lib-jitsi-meet';
  7. import { VideoTrack } from '../../../react/features/base/media';
  8. /* eslint-enable no-unused-vars */
  9. const logger = require('jitsi-meet-logger').getLogger(__filename);
  10. import UIEvents from '../../../service/UI/UIEvents';
  11. import SmallVideo from './SmallVideo';
  12. /**
  13. *
  14. */
  15. function LocalVideo(VideoLayout, emitter) {
  16. this.videoSpanId = 'localVideoContainer';
  17. this.container = this.createContainer();
  18. this.$container = $(this.container);
  19. $('#filmstripLocalVideo').append(this.container);
  20. this.localVideoId = null;
  21. this.bindHoverHandler();
  22. if (config.enableLocalVideoFlip) {
  23. this._buildContextMenu();
  24. }
  25. this.isLocal = true;
  26. this.emitter = emitter;
  27. this.statsPopoverLocation = interfaceConfig.VERTICAL_FILMSTRIP
  28. ? 'left top' : 'top center';
  29. Object.defineProperty(this, 'id', {
  30. get() {
  31. return APP.conference.getMyUserId();
  32. }
  33. });
  34. this.initBrowserSpecificProperties();
  35. SmallVideo.call(this, VideoLayout);
  36. // Set default display name.
  37. this.setDisplayName();
  38. this.addAudioLevelIndicator();
  39. this.updateIndicators();
  40. }
  41. LocalVideo.prototype = Object.create(SmallVideo.prototype);
  42. LocalVideo.prototype.constructor = LocalVideo;
  43. LocalVideo.prototype.createContainer = function() {
  44. const containerSpan = document.createElement('span');
  45. containerSpan.classList.add('videocontainer');
  46. containerSpan.id = this.videoSpanId;
  47. containerSpan.innerHTML = `
  48. <div class = 'videocontainer__background'></div>
  49. <span id = 'localVideoWrapper'></span>
  50. <div class = 'videocontainer__toolbar'></div>
  51. <div class = 'videocontainer__toptoolbar'></div>
  52. <div class = 'videocontainer__hoverOverlay'></div>
  53. <div class = 'displayNameContainer'></div>
  54. <div class = 'avatar-container'></div>`;
  55. return containerSpan;
  56. };
  57. /**
  58. * Sets the display name for the given video span id.
  59. */
  60. LocalVideo.prototype.setDisplayName = function(displayName) {
  61. if (!this.container) {
  62. logger.warn(
  63. `Unable to set displayName - ${this.videoSpanId
  64. } does not exist`);
  65. return;
  66. }
  67. this.updateDisplayName({
  68. allowEditing: true,
  69. displayName,
  70. displayNameSuffix: interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME,
  71. elementID: 'localDisplayName',
  72. participantID: this.id
  73. });
  74. };
  75. LocalVideo.prototype.changeVideo = function(stream) {
  76. this.videoStream = stream;
  77. const localVideoClick = event => {
  78. // TODO Checking the classes is a workround to allow events to bubble
  79. // into the DisplayName component if it was clicked. React's synthetic
  80. // events will fire after jQuery handlers execute, so stop propogation
  81. // at this point will prevent DisplayName from getting click events.
  82. // This workaround should be removeable once LocalVideo is a React
  83. // Component because then the components share the same eventing system.
  84. const $source = $(event.target || event.srcElement);
  85. const { classList } = event.target;
  86. const clickedOnDisplayName
  87. = $source.parents('.displayNameContainer').length > 0;
  88. const clickedOnPopover
  89. = $source.parents('.connection-info').length > 0;
  90. const clickedOnPopoverTrigger
  91. = $source.parents('.popover-trigger').length > 0
  92. || classList.contains('popover-trigger');
  93. const ignoreClick = clickedOnDisplayName
  94. || clickedOnPopoverTrigger
  95. || clickedOnPopover;
  96. // FIXME: with Temasys plugin event arg is not an event, but
  97. // the clicked object itself, so we have to skip this call
  98. if (event.stopPropagation && !ignoreClick) {
  99. event.stopPropagation();
  100. }
  101. if (!ignoreClick) {
  102. this.VideoLayout.handleVideoThumbClicked(this.id);
  103. }
  104. };
  105. this.$container.off('click');
  106. this.$container.on('click', localVideoClick);
  107. this.localVideoId = `localVideo_${stream.getId()}`;
  108. const localVideoContainer = document.getElementById('localVideoWrapper');
  109. ReactDOM.render(
  110. <Provider store = { APP.store }>
  111. <VideoTrack
  112. id = { this.localVideoId }
  113. videoTrack = {{ jitsiTrack: stream }} />
  114. </Provider>,
  115. localVideoContainer
  116. );
  117. // eslint-disable-next-line eqeqeq
  118. const isVideo = stream.videoType != 'desktop';
  119. this._enableDisableContextMenu(isVideo);
  120. this.setFlipX(isVideo ? APP.settings.getLocalFlipX() : false);
  121. const endedHandler = () => {
  122. // Only remove if there is no video and not a transition state.
  123. // Previous non-react logic created a new video element with each track
  124. // removal whereas react reuses the video component so it could be the
  125. // stream ended but a new one is being used.
  126. if (this.videoStream.isEnded()) {
  127. ReactDOM.unmountComponentAtNode(localVideoContainer);
  128. }
  129. // when removing only the video element and we are on stage
  130. // update the stage
  131. if (this.isCurrentlyOnLargeVideo()) {
  132. this.VideoLayout.updateLargeVideo(this.id);
  133. }
  134. stream.off(JitsiTrackEvents.LOCAL_TRACK_STOPPED, endedHandler);
  135. };
  136. stream.on(JitsiTrackEvents.LOCAL_TRACK_STOPPED, endedHandler);
  137. };
  138. /**
  139. * Shows or hides the local video container.
  140. * @param {boolean} true to make the local video container visible, false
  141. * otherwise
  142. */
  143. LocalVideo.prototype.setVisible = function(visible) {
  144. // We toggle the hidden class as an indication to other interested parties
  145. // that this container has been hidden on purpose.
  146. this.$container.toggleClass('hidden');
  147. // We still show/hide it as we need to overwrite the style property if we
  148. // want our action to take effect. Toggling the display property through
  149. // the above css class didn't succeed in overwriting the style.
  150. if (visible) {
  151. this.$container.show();
  152. } else {
  153. this.$container.hide();
  154. }
  155. };
  156. /**
  157. * Sets the flipX state of the video.
  158. * @param val {boolean} true for flipped otherwise false;
  159. */
  160. LocalVideo.prototype.setFlipX = function(val) {
  161. this.emitter.emit(UIEvents.LOCAL_FLIPX_CHANGED, val);
  162. if (!this.localVideoId) {
  163. return;
  164. }
  165. if (val) {
  166. this.selectVideoElement().addClass('flipVideoX');
  167. } else {
  168. this.selectVideoElement().removeClass('flipVideoX');
  169. }
  170. };
  171. /**
  172. * Builds the context menu for the local video.
  173. */
  174. LocalVideo.prototype._buildContextMenu = function() {
  175. $.contextMenu({
  176. selector: `#${this.videoSpanId}`,
  177. zIndex: 10000,
  178. items: {
  179. flip: {
  180. name: 'Flip',
  181. callback: () => {
  182. const val = !APP.settings.getLocalFlipX();
  183. this.setFlipX(val);
  184. APP.settings.setLocalFlipX(val);
  185. }
  186. }
  187. },
  188. events: {
  189. show(options) {
  190. options.items.flip.name
  191. = APP.translation.generateTranslationHTML(
  192. 'videothumbnail.flip');
  193. }
  194. }
  195. });
  196. };
  197. /**
  198. * Enables or disables the context menu for the local video.
  199. * @param enable {boolean} true for enable, false for disable
  200. */
  201. LocalVideo.prototype._enableDisableContextMenu = function(enable) {
  202. if (this.$container.contextMenu) {
  203. this.$container.contextMenu(enable);
  204. }
  205. };
  206. export default LocalVideo;