Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

LocalVideo.js 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. 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.createConnectionIndicator();
  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. "top");
  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 + '>span.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. var editButton = createEditDisplayNameButton();
  73. nameSpan = document.createElement('span');
  74. nameSpan.className = 'displayname';
  75. $('#' + this.videoSpanId)[0].appendChild(nameSpan);
  76. if (displayName && displayName.length > 0) {
  77. meHTML = APP.translation.generateTranslationHTML("me");
  78. nameSpan.innerHTML = UIUtil.escapeHtml(displayName) + meHTML;
  79. }
  80. else {
  81. nameSpan.innerHTML = defaultLocalDisplayName;
  82. }
  83. nameSpan.id = 'localDisplayName';
  84. this.container.appendChild(editButton);
  85. //translates popover of edit button
  86. APP.translation.translateElement($("a.displayname"));
  87. var editableText = document.createElement('input');
  88. editableText.className = 'displayname';
  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.appendChild(editableText);
  103. var self = this;
  104. $('#localVideoContainer .displayname')
  105. .bind("click", function (e) {
  106. var editDisplayName = $('#editDisplayName');
  107. e.preventDefault();
  108. e.stopPropagation();
  109. $('#localDisplayName').hide();
  110. editDisplayName.show();
  111. editDisplayName.focus();
  112. editDisplayName.select();
  113. editDisplayName.one("focusout", function (e) {
  114. self.emitter.emit(UIEvents.NICKNAME_CHANGED, this.value);
  115. $('#editDisplayName').hide();
  116. });
  117. editDisplayName.on('keydown', function (e) {
  118. if (e.keyCode === 13) {
  119. e.preventDefault();
  120. $('#editDisplayName').hide();
  121. // focusout handler will save display name
  122. }
  123. });
  124. });
  125. }
  126. };
  127. LocalVideo.prototype.createConnectionIndicator = function() {
  128. if(this.connectionIndicator)
  129. return;
  130. this.connectionIndicator = new ConnectionIndicator(this, null);
  131. };
  132. LocalVideo.prototype.changeVideo = function (stream) {
  133. this.videoStream = stream;
  134. let localVideoClick = (event) => {
  135. // FIXME: with Temasys plugin event arg is not an event, but
  136. // the clicked object itself, so we have to skip this call
  137. if (event.stopPropagation) {
  138. event.stopPropagation();
  139. }
  140. this.VideoLayout.handleVideoThumbClicked(this.id);
  141. };
  142. let localVideoContainerSelector = $('#localVideoContainer');
  143. localVideoContainerSelector.off('click');
  144. localVideoContainerSelector.on('click', localVideoClick);
  145. let localVideo = document.createElement('video');
  146. localVideo.id = this.localVideoId = 'localVideo_' + stream.getId();
  147. RTCUIUtils.setAutoPlay(localVideo, true);
  148. RTCUIUtils.setVolume(localVideo, 0);
  149. var localVideoContainer = document.getElementById('localVideoWrapper');
  150. // Put the new video always in front
  151. UIUtil.prependChild(localVideoContainer, localVideo);
  152. // Add click handler to both video and video wrapper elements in case
  153. // there's no video.
  154. // onclick has to be used with Temasys plugin
  155. localVideo.onclick = localVideoClick;
  156. let isVideo = stream.videoType != "desktop";
  157. this._enableDisableContextMenu(isVideo);
  158. this.setFlipX(isVideo? APP.settings.getLocalFlipX() : false);
  159. // Attach WebRTC stream
  160. localVideo = stream.attach(localVideo);
  161. let endedHandler = () => {
  162. localVideoContainer.removeChild(localVideo);
  163. // when removing only the video element and we are on stage
  164. // update the stage
  165. if(this.VideoLayout.isCurrentlyOnLarge(this.id))
  166. this.VideoLayout.updateLargeVideo(this.id);
  167. stream.off(TrackEvents.LOCAL_TRACK_STOPPED, endedHandler);
  168. };
  169. stream.on(TrackEvents.LOCAL_TRACK_STOPPED, endedHandler);
  170. };
  171. /**
  172. * Shows or hides the local video container.
  173. * @param {boolean} true to make the local video container visible, false
  174. * otherwise
  175. */
  176. LocalVideo.prototype.setVisible = function(visible) {
  177. // We toggle the hidden class as an indication to other interested parties
  178. // that this container has been hidden on purpose.
  179. $("#localVideoContainer").toggleClass("hidden");
  180. // We still show/hide it as we need to overwrite the style property if we
  181. // want our action to take effect. Toggling the display property through
  182. // the above css class didn't succeed in overwriting the style.
  183. if (visible) {
  184. $("#localVideoContainer").show();
  185. }
  186. else {
  187. $("#localVideoContainer").hide();
  188. }
  189. };
  190. /**
  191. * Sets the flipX state of the video.
  192. * @param val {boolean} true for flipped otherwise false;
  193. */
  194. LocalVideo.prototype.setFlipX = function (val) {
  195. this.emitter.emit(UIEvents.LOCAL_FLIPX_CHANGED, val);
  196. if(!this.localVideoId)
  197. return;
  198. if(val) {
  199. this.selectVideoElement().addClass("flipVideoX");
  200. } else {
  201. this.selectVideoElement().removeClass("flipVideoX");
  202. }
  203. };
  204. /**
  205. * Builds the context menu for the local video.
  206. */
  207. LocalVideo.prototype._buildContextMenu = function () {
  208. $.contextMenu({
  209. selector: '#' + this.videoSpanId,
  210. zIndex: 10000,
  211. items: {
  212. flip: {
  213. name: "Flip",
  214. callback: () => {
  215. let val = !APP.settings.getLocalFlipX();
  216. this.setFlipX(val);
  217. APP.settings.setLocalFlipX(val);
  218. }
  219. }
  220. },
  221. events: {
  222. show : function(options){
  223. options.items.flip.name =
  224. APP.translation.translateString("videothumbnail.flip");
  225. }
  226. }
  227. });
  228. };
  229. /**
  230. * Enables or disables the context menu for the local video.
  231. * @param enable {boolean} true for enable, false for disable
  232. */
  233. LocalVideo.prototype._enableDisableContextMenu = function (enable) {
  234. if($('#' + this.videoSpanId).contextMenu)
  235. $('#' + this.videoSpanId).contextMenu(enable);
  236. };
  237. export default LocalVideo;