Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

LocalVideo.js 6.7KB

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