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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. stream.off(TrackEvents.LOCAL_TRACK_STOPPED, endedHandler);
  96. };
  97. stream.on(TrackEvents.LOCAL_TRACK_STOPPED, endedHandler);
  98. };
  99. /**
  100. * Shows or hides the local video container.
  101. * @param {boolean} true to make the local video container visible, false
  102. * otherwise
  103. */
  104. LocalVideo.prototype.setVisible = function(visible) {
  105. // We toggle the hidden class as an indication to other interested parties
  106. // that this container has been hidden on purpose.
  107. $("#localVideoContainer").toggleClass("hidden");
  108. // We still show/hide it as we need to overwrite the style property if we
  109. // want our action to take effect. Toggling the display property through
  110. // the above css class didn't succeed in overwriting the style.
  111. if (visible) {
  112. $("#localVideoContainer").show();
  113. }
  114. else {
  115. $("#localVideoContainer").hide();
  116. }
  117. };
  118. /**
  119. * Sets the flipX state of the video.
  120. * @param val {boolean} true for flipped otherwise false;
  121. */
  122. LocalVideo.prototype.setFlipX = function (val) {
  123. this.emitter.emit(UIEvents.LOCAL_FLIPX_CHANGED, val);
  124. if(!this.localVideoId)
  125. return;
  126. if(val) {
  127. this.selectVideoElement().addClass("flipVideoX");
  128. } else {
  129. this.selectVideoElement().removeClass("flipVideoX");
  130. }
  131. };
  132. /**
  133. * Builds the context menu for the local video.
  134. */
  135. LocalVideo.prototype._buildContextMenu = function () {
  136. $.contextMenu({
  137. selector: '#' + this.videoSpanId,
  138. zIndex: 10000,
  139. items: {
  140. flip: {
  141. name: "Flip",
  142. callback: () => {
  143. let val = !APP.settings.getLocalFlipX();
  144. this.setFlipX(val);
  145. APP.settings.setLocalFlipX(val);
  146. }
  147. }
  148. },
  149. events: {
  150. show : function(options){
  151. options.items.flip.name =
  152. APP.translation.generateTranslationHTML(
  153. "videothumbnail.flip");
  154. }
  155. }
  156. });
  157. };
  158. /**
  159. * Enables or disables the context menu for the local video.
  160. * @param enable {boolean} true for enable, false for disable
  161. */
  162. LocalVideo.prototype._enableDisableContextMenu = function (enable) {
  163. if($('#' + this.videoSpanId).contextMenu)
  164. $('#' + this.videoSpanId).contextMenu(enable);
  165. };
  166. export default LocalVideo;