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

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