Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

LocalVideo.js 9.1KB

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