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 6.3KB

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