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

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