您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

LocalVideo.js 6.5KB

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