Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

LocalVideo.js 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /* global $, config, interfaceConfig, APP, JitsiMeetJS */
  2. import ConnectionIndicator from "./ConnectionIndicator";
  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. if(config.enableLocalVideoFlip)
  13. this._buildContextMenu();
  14. this.isLocal = true;
  15. this.emitter = emitter;
  16. Object.defineProperty(this, 'id', {
  17. get: function () {
  18. return APP.conference.getMyUserId();
  19. }
  20. });
  21. this.initBrowserSpecificProperties();
  22. SmallVideo.call(this, VideoLayout);
  23. // Set default display name.
  24. this.setDisplayName();
  25. this.createConnectionIndicator();
  26. this.addAudioLevelIndicator();
  27. }
  28. LocalVideo.prototype = Object.create(SmallVideo.prototype);
  29. LocalVideo.prototype.constructor = LocalVideo;
  30. /**
  31. * Sets the display name for the given video span id.
  32. */
  33. LocalVideo.prototype.setDisplayName = function(displayName) {
  34. if (!this.container) {
  35. console.warn(
  36. "Unable to set displayName - " + this.videoSpanId +
  37. " does not exist");
  38. return;
  39. }
  40. var nameSpan = $('#' + this.videoSpanId + ' .displayname');
  41. var defaultLocalDisplayName = APP.translation.generateTranslationHTML(
  42. interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME);
  43. var meHTML;
  44. // If we already have a display name for this video.
  45. if (nameSpan.length > 0) {
  46. if (nameSpan.text() !== displayName) {
  47. if (displayName && displayName.length > 0) {
  48. meHTML = APP.translation.generateTranslationHTML("me");
  49. $('#localDisplayName').html(
  50. `${UIUtil.escapeHtml(displayName)} (${meHTML})`
  51. );
  52. $('#editDisplayName').val(
  53. `${UIUtil.escapeHtml(displayName)}`
  54. );
  55. } else {
  56. $('#localDisplayName').html(defaultLocalDisplayName);
  57. }
  58. }
  59. this.updateView();
  60. } else {
  61. nameSpan = document.createElement('span');
  62. nameSpan.className = 'displayname';
  63. document.getElementById(this.videoSpanId)
  64. .appendChild(nameSpan);
  65. if (displayName && displayName.length > 0) {
  66. meHTML = APP.translation.generateTranslationHTML("me");
  67. nameSpan.innerHTML = UIUtil.escapeHtml(displayName) + meHTML;
  68. }
  69. else {
  70. nameSpan.innerHTML = defaultLocalDisplayName;
  71. }
  72. nameSpan.id = 'localDisplayName';
  73. //translates popover of edit button
  74. APP.translation.translateElement($("a.displayname"));
  75. var editableText = document.createElement('input');
  76. editableText.className = 'editdisplayname';
  77. editableText.type = 'text';
  78. editableText.id = 'editDisplayName';
  79. if (displayName && displayName.length) {
  80. editableText.value = displayName;
  81. }
  82. editableText.setAttribute('style', 'display:none;');
  83. editableText.setAttribute('data-i18n',
  84. '[placeholder]defaultNickname');
  85. editableText.setAttribute("data-i18n-options",
  86. JSON.stringify({name: "Jane Pink"}));
  87. APP.translation.translateElement($(editableText));
  88. this.container
  89. .appendChild(editableText);
  90. var self = this;
  91. $('#localVideoContainer .displayname')
  92. .bind("click", function (e) {
  93. let $editDisplayName = $('#editDisplayName');
  94. let $localDisplayName = $('#localDisplayName');
  95. e.preventDefault();
  96. e.stopPropagation();
  97. $localDisplayName.hide();
  98. $editDisplayName.show();
  99. $editDisplayName.focus();
  100. $editDisplayName.select();
  101. $editDisplayName.one("focusout", function () {
  102. self.emitter.emit(UIEvents.NICKNAME_CHANGED, this.value);
  103. $editDisplayName.hide();
  104. $localDisplayName.show();
  105. });
  106. $editDisplayName.on('keydown', function (e) {
  107. if (e.keyCode === 13) {
  108. e.preventDefault();
  109. $('#editDisplayName').hide();
  110. // focusout handler will save display name
  111. }
  112. });
  113. });
  114. }
  115. };
  116. LocalVideo.prototype.createConnectionIndicator = function() {
  117. if(this.connectionIndicator)
  118. return;
  119. this.connectionIndicator = new ConnectionIndicator(this, null);
  120. };
  121. LocalVideo.prototype.changeVideo = function (stream) {
  122. this.videoStream = stream;
  123. let localVideoClick = (event) => {
  124. // FIXME: with Temasys plugin event arg is not an event, but
  125. // the clicked object itself, so we have to skip this call
  126. if (event.stopPropagation) {
  127. event.stopPropagation();
  128. }
  129. this.VideoLayout.handleVideoThumbClicked(this.id);
  130. };
  131. let localVideoContainerSelector = $('#localVideoContainer');
  132. localVideoContainerSelector.off('click');
  133. localVideoContainerSelector.on('click', localVideoClick);
  134. let localVideo = document.createElement('video');
  135. localVideo.id = this.localVideoId = 'localVideo_' + stream.getId();
  136. RTCUIUtils.setAutoPlay(localVideo, true);
  137. RTCUIUtils.setVolume(localVideo, 0);
  138. var localVideoContainer = document.getElementById('localVideoWrapper');
  139. // Put the new video always in front
  140. UIUtil.prependChild(localVideoContainer, localVideo);
  141. // Add click handler to both video and video wrapper elements in case
  142. // there's no video.
  143. // onclick has to be used with Temasys plugin
  144. localVideo.onclick = localVideoClick;
  145. let isVideo = stream.videoType != "desktop";
  146. this._enableDisableContextMenu(isVideo);
  147. this.setFlipX(isVideo? APP.settings.getLocalFlipX() : false);
  148. // Attach WebRTC stream
  149. localVideo = stream.attach(localVideo);
  150. let endedHandler = () => {
  151. localVideoContainer.removeChild(localVideo);
  152. // when removing only the video element and we are on stage
  153. // update the stage
  154. if(this.isCurrentlyOnLargeVideo())
  155. this.VideoLayout.updateLargeVideo(this.id);
  156. stream.off(TrackEvents.LOCAL_TRACK_STOPPED, endedHandler);
  157. };
  158. stream.on(TrackEvents.LOCAL_TRACK_STOPPED, endedHandler);
  159. };
  160. /**
  161. * Shows or hides the local video container.
  162. * @param {boolean} true to make the local video container visible, false
  163. * otherwise
  164. */
  165. LocalVideo.prototype.setVisible = function(visible) {
  166. // We toggle the hidden class as an indication to other interested parties
  167. // that this container has been hidden on purpose.
  168. $("#localVideoContainer").toggleClass("hidden");
  169. // We still show/hide it as we need to overwrite the style property if we
  170. // want our action to take effect. Toggling the display property through
  171. // the above css class didn't succeed in overwriting the style.
  172. if (visible) {
  173. $("#localVideoContainer").show();
  174. }
  175. else {
  176. $("#localVideoContainer").hide();
  177. }
  178. };
  179. /**
  180. * Sets the flipX state of the video.
  181. * @param val {boolean} true for flipped otherwise false;
  182. */
  183. LocalVideo.prototype.setFlipX = function (val) {
  184. this.emitter.emit(UIEvents.LOCAL_FLIPX_CHANGED, val);
  185. if(!this.localVideoId)
  186. return;
  187. if(val) {
  188. this.selectVideoElement().addClass("flipVideoX");
  189. } else {
  190. this.selectVideoElement().removeClass("flipVideoX");
  191. }
  192. };
  193. /**
  194. * Builds the context menu for the local video.
  195. */
  196. LocalVideo.prototype._buildContextMenu = function () {
  197. $.contextMenu({
  198. selector: '#' + this.videoSpanId,
  199. zIndex: 10000,
  200. items: {
  201. flip: {
  202. name: "Flip",
  203. callback: () => {
  204. let val = !APP.settings.getLocalFlipX();
  205. this.setFlipX(val);
  206. APP.settings.setLocalFlipX(val);
  207. }
  208. }
  209. },
  210. events: {
  211. show : function(options){
  212. options.items.flip.name =
  213. APP.translation.generateTranslationHTML(
  214. "videothumbnail.flip");
  215. }
  216. }
  217. });
  218. };
  219. /**
  220. * Enables or disables the context menu for the local video.
  221. * @param enable {boolean} true for enable, false for disable
  222. */
  223. LocalVideo.prototype._enableDisableContextMenu = function (enable) {
  224. if($('#' + this.videoSpanId).contextMenu)
  225. $('#' + this.videoSpanId).contextMenu(enable);
  226. };
  227. export default LocalVideo;