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

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