您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

LocalVideo.js 6.4KB

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