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.1KB

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