Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

LocalVideo.js 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 = this.createContainer();
  15. $("#filmstripLocalVideo").append(this.container);
  16. this.localVideoId = null;
  17. this.bindHoverHandler();
  18. if(config.enableLocalVideoFlip)
  19. this._buildContextMenu();
  20. this.isLocal = true;
  21. this.emitter = emitter;
  22. this.statsPopoverLocation = interfaceConfig.VERTICAL_FILMSTRIP
  23. ? 'left bottom' : 'top center';
  24. Object.defineProperty(this, 'id', {
  25. get: function () {
  26. return APP.conference.getMyUserId();
  27. }
  28. });
  29. this.initBrowserSpecificProperties();
  30. SmallVideo.call(this, VideoLayout);
  31. // Set default display name.
  32. this.setDisplayName();
  33. this.addAudioLevelIndicator();
  34. this.updateIndicators();
  35. }
  36. LocalVideo.prototype = Object.create(SmallVideo.prototype);
  37. LocalVideo.prototype.constructor = LocalVideo;
  38. LocalVideo.prototype.createContainer = function () {
  39. const containerSpan = document.createElement('span');
  40. containerSpan.classList.add('videocontainer');
  41. containerSpan.id = this.videoSpanId;
  42. containerSpan.innerHTML = `
  43. <div class = 'videocontainer__background'></div>
  44. <span id = 'localVideoWrapper'></span>
  45. <div class = 'videocontainer__toolbar'></div>
  46. <div class = 'videocontainer__toptoolbar'></div>
  47. <div class = 'videocontainer__hoverOverlay'></div>
  48. <div class = 'displayNameContainer'></div>
  49. <div class = 'avatar-container'></div>`;
  50. return containerSpan;
  51. };
  52. /**
  53. * Sets the display name for the given video span id.
  54. */
  55. LocalVideo.prototype.setDisplayName = function(displayName) {
  56. if (!this.container) {
  57. logger.warn(
  58. "Unable to set displayName - " + this.videoSpanId +
  59. " does not exist");
  60. return;
  61. }
  62. this.updateDisplayName({
  63. allowEditing: true,
  64. displayName: displayName,
  65. displayNameSuffix: interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME,
  66. elementID: 'localDisplayName',
  67. participantID: this.id
  68. });
  69. };
  70. LocalVideo.prototype.changeVideo = function (stream) {
  71. this.videoStream = stream;
  72. let localVideoClick = (event) => {
  73. // TODO Checking the classes is a workround to allow events to bubble
  74. // into the DisplayName component if it was clicked. React's synthetic
  75. // events will fire after jQuery handlers execute, so stop propogation
  76. // at this point will prevent DisplayName from getting click events.
  77. // This workaround should be removeable once LocalVideo is a React
  78. // Component because then the components share the same eventing system.
  79. const $source = $(event.target || event.srcElement);
  80. const { classList } = event.target;
  81. const clickedOnDisplayName
  82. = $source.parents('.displayNameContainer').length > 0;
  83. const clickedOnPopover
  84. = $source.parents('.connection-info').length > 0;
  85. const clickedOnPopoverTrigger
  86. = $source.parents('.popover-trigger').length > 0
  87. || classList.contains('popover-trigger');
  88. const ignoreClick = clickedOnDisplayName
  89. || clickedOnPopoverTrigger
  90. || clickedOnPopover;
  91. // FIXME: with Temasys plugin event arg is not an event, but
  92. // the clicked object itself, so we have to skip this call
  93. if (event.stopPropagation && !ignoreClick) {
  94. event.stopPropagation();
  95. }
  96. if (!ignoreClick) {
  97. this.VideoLayout.handleVideoThumbClicked(this.id);
  98. }
  99. };
  100. let localVideoContainerSelector = $('#localVideoContainer');
  101. localVideoContainerSelector.off('click');
  102. localVideoContainerSelector.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(TrackEvents.LOCAL_TRACK_STOPPED, endedHandler);
  132. };
  133. stream.on(TrackEvents.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. $("#localVideoContainer").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. $("#localVideoContainer").show();
  149. }
  150. else {
  151. $("#localVideoContainer").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.videoSpanId).contextMenu)
  200. $('#' + this.videoSpanId).contextMenu(enable);
  201. };
  202. export default LocalVideo;