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

LocalVideo.js 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* global $, interfaceConfig, APP */
  2. import ConnectionIndicator from "./ConnectionIndicator";
  3. import UIUtil from "../util/UIUtil";
  4. import UIEvents from "../../../service/UI/UIEvents";
  5. import SmallVideo from "./SmallVideo";
  6. var LargeVideo = require("./LargeVideo");
  7. var RTCBrowserType = require("../../RTC/RTCBrowserType");
  8. const TrackEvents = JitsiMeetJS.events.track;
  9. function LocalVideo(VideoLayout, emitter) {
  10. this.videoSpanId = "localVideoContainer";
  11. this.container = $("#localVideoContainer").get(0);
  12. this.bindHoverHandler();
  13. this.VideoLayout = VideoLayout;
  14. this.flipX = true;
  15. this.isLocal = true;
  16. this.emitter = emitter;
  17. }
  18. LocalVideo.prototype = Object.create(SmallVideo.prototype);
  19. LocalVideo.prototype.constructor = LocalVideo;
  20. /**
  21. * Creates the edit display name button.
  22. *
  23. * @returns {object} the edit button
  24. */
  25. function createEditDisplayNameButton() {
  26. var editButton = document.createElement('a');
  27. editButton.className = 'displayname';
  28. UIUtil.setTooltip(editButton,
  29. "videothumbnail.editnickname",
  30. "top");
  31. editButton.innerHTML = '<i class="fa fa-pencil"></i>';
  32. return editButton;
  33. }
  34. /**
  35. * Sets the display name for the given video span id.
  36. */
  37. LocalVideo.prototype.setDisplayName = function(displayName, key) {
  38. if (!this.container) {
  39. console.warn(
  40. "Unable to set displayName - " + this.videoSpanId +
  41. " does not exist");
  42. return;
  43. }
  44. var nameSpan = $('#' + this.videoSpanId + '>span.displayname');
  45. var defaultLocalDisplayName = APP.translation.generateTranslationHTML(
  46. interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME);
  47. var meHTML;
  48. // If we already have a display name for this video.
  49. if (nameSpan.length > 0) {
  50. if (nameSpan.text() !== displayName) {
  51. if (displayName && displayName.length > 0) {
  52. meHTML = APP.translation.generateTranslationHTML("me");
  53. $('#localDisplayName').html(displayName + ' (' + meHTML + ')');
  54. } else {
  55. $('#localDisplayName').html(defaultLocalDisplayName);
  56. }
  57. }
  58. } else {
  59. var editButton = createEditDisplayNameButton();
  60. nameSpan = document.createElement('span');
  61. nameSpan.className = 'displayname';
  62. $('#' + this.videoSpanId)[0].appendChild(nameSpan);
  63. if (displayName && displayName.length > 0) {
  64. meHTML = APP.translation.generateTranslationHTML("me");
  65. nameSpan.innerHTML = displayName + meHTML;
  66. }
  67. else {
  68. nameSpan.innerHTML = defaultLocalDisplayName;
  69. }
  70. nameSpan.id = 'localDisplayName';
  71. this.container.appendChild(editButton);
  72. //translates popover of edit button
  73. APP.translation.translateElement($("a.displayname"));
  74. var editableText = document.createElement('input');
  75. editableText.className = 'displayname';
  76. editableText.type = 'text';
  77. editableText.id = 'editDisplayName';
  78. if (displayName && displayName.length) {
  79. editableText.value = displayName;
  80. }
  81. var defaultNickname = APP.translation.translateString(
  82. "defaultNickname", {name: "Jane Pink"});
  83. editableText.setAttribute('style', 'display:none;');
  84. editableText.setAttribute('data-18n',
  85. '[placeholder]defaultNickname');
  86. editableText.setAttribute("data-i18n-options",
  87. JSON.stringify({name: "Jane Pink"}));
  88. editableText.setAttribute("placeholder", defaultNickname);
  89. this.container.appendChild(editableText);
  90. var self = this;
  91. $('#localVideoContainer .displayname')
  92. .bind("click", function (e) {
  93. var editDisplayName = $('#editDisplayName');
  94. e.preventDefault();
  95. e.stopPropagation();
  96. $('#localDisplayName').hide();
  97. editDisplayName.show();
  98. editDisplayName.focus();
  99. editDisplayName.select();
  100. editDisplayName.one("focusout", function (e) {
  101. self.VideoLayout.inputDisplayNameHandler(this.value);
  102. $('#editDisplayName').hide();
  103. });
  104. editDisplayName.on('keydown', function (e) {
  105. if (e.keyCode === 13) {
  106. e.preventDefault();
  107. $('#editDisplayName').hide();
  108. // focusout handler will save display name
  109. }
  110. });
  111. });
  112. }
  113. };
  114. LocalVideo.prototype.inputDisplayNameHandler = function (name) {
  115. this.emitter.emit(UIEvents.NICKNAME_CHANGED, UIUtil.escapeHtml(name));
  116. };
  117. LocalVideo.prototype.createConnectionIndicator = function() {
  118. if(this.connectionIndicator)
  119. return;
  120. this.connectionIndicator = new ConnectionIndicator(this, null);
  121. };
  122. LocalVideo.prototype.changeVideo = function (stream) {
  123. this.stream = stream;
  124. let localVideoClick = (event) => {
  125. // FIXME: with Temasys plugin event arg is not an event, but
  126. // the clicked object itself, so we have to skip this call
  127. if (event.stopPropagation) {
  128. event.stopPropagation();
  129. }
  130. this.VideoLayout.handleVideoThumbClicked(true, this.id);
  131. };
  132. let localVideoContainerSelector = $('#localVideoContainer');
  133. localVideoContainerSelector.off('click');
  134. localVideoContainerSelector.on('click', localVideoClick);
  135. this.flipX = stream.videoType != "desktop";
  136. let localVideo = document.createElement('video');
  137. localVideo.id = 'localVideo_' + stream.getId();
  138. if (!RTCBrowserType.isIExplorer()) {
  139. localVideo.autoplay = true;
  140. localVideo.volume = 0; // is it required if audio is separated ?
  141. }
  142. localVideo.oncontextmenu = function () { return false; };
  143. var localVideoContainer = document.getElementById('localVideoWrapper');
  144. // Put the new video always in front
  145. UIUtil.prependChild(localVideoContainer, localVideo);
  146. var localVideoSelector = $('#' + localVideo.id);
  147. // Add click handler to both video and video wrapper elements in case
  148. // there's no video.
  149. // onclick has to be used with Temasys plugin
  150. localVideo.onclick = localVideoClick;
  151. if (this.flipX) {
  152. localVideoSelector.addClass("flipVideoX");
  153. }
  154. // Attach WebRTC stream
  155. stream.attach(localVideoSelector);
  156. let endedHandler = () => {
  157. localVideo = $('#' + localVideo.id)[0];
  158. localVideoContainer.removeChild(localVideo);
  159. self.VideoLayout.updateRemovedVideo(self.id);
  160. stream.off(TrackEvents.TRACK_STOPPED, endedHandler);
  161. };
  162. stream.on(TrackEvents.TRACK_STOPPED, endedHandler);
  163. };
  164. LocalVideo.prototype.joined = function (id) {
  165. this.id = id;
  166. };
  167. export default LocalVideo;