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

LocalVideo.js 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* global $, config, APP */
  2. /* eslint-disable no-unused-vars */
  3. import React, { Component } from 'react';
  4. import ReactDOM from 'react-dom';
  5. import { I18nextProvider } from 'react-i18next';
  6. import { Provider } from 'react-redux';
  7. import { i18next } from '../../../react/features/base/i18n';
  8. import { JitsiTrackEvents } from '../../../react/features/base/lib-jitsi-meet';
  9. import { VideoTrack } from '../../../react/features/base/media';
  10. import { updateSettings } from '../../../react/features/base/settings';
  11. import { getLocalVideoTrack } from '../../../react/features/base/tracks';
  12. import Thumbnail from '../../../react/features/filmstrip/components/web/Thumbnail';
  13. import { shouldDisplayTileView } from '../../../react/features/video-layout';
  14. /* eslint-enable no-unused-vars */
  15. import UIEvents from '../../../service/UI/UIEvents';
  16. import SmallVideo from './SmallVideo';
  17. /**
  18. *
  19. */
  20. export default class LocalVideo extends SmallVideo {
  21. /**
  22. *
  23. * @param {*} emitter
  24. * @param {*} streamEndedCallback
  25. */
  26. constructor(emitter, streamEndedCallback) {
  27. super();
  28. this.videoSpanId = 'localVideoContainer';
  29. this.streamEndedCallback = streamEndedCallback;
  30. this.container = this.createContainer();
  31. this.$container = $(this.container);
  32. this.isLocal = true;
  33. this._setThumbnailSize();
  34. this.updateDOMLocation();
  35. this.renderThumbnail();
  36. this.localVideoId = null;
  37. this.bindHoverHandler();
  38. if (!config.disableLocalVideoFlip) {
  39. this._buildContextMenu();
  40. }
  41. this.emitter = emitter;
  42. Object.defineProperty(this, 'id', {
  43. get() {
  44. return APP.conference.getMyUserId();
  45. }
  46. });
  47. this.initBrowserSpecificProperties();
  48. this.container.onclick = this._onContainerClick;
  49. }
  50. /**
  51. *
  52. */
  53. createContainer() {
  54. const containerSpan = document.createElement('span');
  55. containerSpan.classList.add('videocontainer');
  56. containerSpan.id = this.videoSpanId;
  57. return containerSpan;
  58. }
  59. /**
  60. * Renders the thumbnail.
  61. */
  62. renderThumbnail(isHovered = false) {
  63. ReactDOM.render(
  64. <Provider store = { APP.store }>
  65. <I18nextProvider i18n = { i18next }>
  66. <Thumbnail participantID = { this.id } isHovered = { isHovered } />
  67. </I18nextProvider>
  68. </Provider>, this.container);
  69. }
  70. /**
  71. *
  72. * @param {*} stream
  73. */
  74. changeVideo(stream) {
  75. this.localVideoId = `localVideo_${stream.getId()}`;
  76. // eslint-disable-next-line eqeqeq
  77. const isVideo = stream.videoType != 'desktop';
  78. const settings = APP.store.getState()['features/base/settings'];
  79. this._enableDisableContextMenu(isVideo);
  80. this.setFlipX(isVideo ? settings.localFlipX : false);
  81. const endedHandler = () => {
  82. this._notifyOfStreamEnded();
  83. stream.off(JitsiTrackEvents.LOCAL_TRACK_STOPPED, endedHandler);
  84. };
  85. stream.on(JitsiTrackEvents.LOCAL_TRACK_STOPPED, endedHandler);
  86. }
  87. /**
  88. * Notify any subscribers of the local video stream ending.
  89. *
  90. * @private
  91. * @returns {void}
  92. */
  93. _notifyOfStreamEnded() {
  94. if (this.streamEndedCallback) {
  95. this.streamEndedCallback(this.id);
  96. }
  97. }
  98. /**
  99. * Shows or hides the local video container.
  100. * @param {boolean} true to make the local video container visible, false
  101. * otherwise
  102. */
  103. setVisible(visible) {
  104. // We toggle the hidden class as an indication to other interested parties
  105. // that this container has been hidden on purpose.
  106. this.$container.toggleClass('hidden');
  107. // We still show/hide it as we need to overwrite the style property if we
  108. // want our action to take effect. Toggling the display property through
  109. // the above css class didn't succeed in overwriting the style.
  110. if (visible) {
  111. this.$container.show();
  112. } else {
  113. this.$container.hide();
  114. }
  115. }
  116. /**
  117. * Sets the flipX state of the video.
  118. * @param val {boolean} true for flipped otherwise false;
  119. */
  120. setFlipX(val) {
  121. this.emitter.emit(UIEvents.LOCAL_FLIPX_CHANGED, val);
  122. if (!this.localVideoId) {
  123. return;
  124. }
  125. if (val) {
  126. this.selectVideoElement().addClass('flipVideoX');
  127. } else {
  128. this.selectVideoElement().removeClass('flipVideoX');
  129. }
  130. }
  131. /**
  132. * Builds the context menu for the local video.
  133. */
  134. _buildContextMenu() {
  135. $.contextMenu({
  136. selector: `#${this.videoSpanId}`,
  137. zIndex: 10000,
  138. items: {
  139. flip: {
  140. name: 'Flip',
  141. callback: () => {
  142. const { store } = APP;
  143. const val = !store.getState()['features/base/settings']
  144. .localFlipX;
  145. this.setFlipX(val);
  146. store.dispatch(updateSettings({
  147. localFlipX: val
  148. }));
  149. }
  150. }
  151. },
  152. events: {
  153. show(options) {
  154. options.items.flip.name
  155. = APP.translation.generateTranslationHTML(
  156. 'videothumbnail.flip');
  157. }
  158. }
  159. });
  160. }
  161. /**
  162. * Enables or disables the context menu for the local video.
  163. * @param enable {boolean} true for enable, false for disable
  164. */
  165. _enableDisableContextMenu(enable) {
  166. if (this.$container.contextMenu) {
  167. this.$container.contextMenu(enable);
  168. }
  169. }
  170. /**
  171. * Places the {@code LocalVideo} in the DOM based on the current video layout.
  172. *
  173. * @returns {void}
  174. */
  175. updateDOMLocation() {
  176. if (!this.container) {
  177. return;
  178. }
  179. if (this.container.parentElement) {
  180. this.container.parentElement.removeChild(this.container);
  181. }
  182. const appendTarget = shouldDisplayTileView(APP.store.getState())
  183. ? document.getElementById('localVideoTileViewContainer')
  184. : document.getElementById('filmstripLocalVideoThumbnail');
  185. appendTarget && appendTarget.appendChild(this.container);
  186. }
  187. }