Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

LocalVideo.js 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. 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.flipX = true;
  14. this.isLocal = true;
  15. this.emitter = emitter;
  16. Object.defineProperty(this, 'id', {
  17. get: function () {
  18. return APP.conference.localId;
  19. }
  20. });
  21. SmallVideo.call(this, VideoLayout);
  22. }
  23. LocalVideo.prototype = Object.create(SmallVideo.prototype);
  24. LocalVideo.prototype.constructor = LocalVideo;
  25. /**
  26. * Creates the edit display name button.
  27. *
  28. * @returns {object} the edit button
  29. */
  30. function createEditDisplayNameButton() {
  31. var editButton = document.createElement('a');
  32. editButton.className = 'displayname';
  33. UIUtil.setTooltip(editButton,
  34. "videothumbnail.editnickname",
  35. "top");
  36. editButton.innerHTML = '<i class="fa fa-pencil"></i>';
  37. return editButton;
  38. }
  39. /**
  40. * Sets the display name for the given video span id.
  41. */
  42. LocalVideo.prototype.setDisplayName = function(displayName, key) {
  43. if (!this.container) {
  44. console.warn(
  45. "Unable to set displayName - " + this.videoSpanId +
  46. " does not exist");
  47. return;
  48. }
  49. var nameSpan = $('#' + this.videoSpanId + '>span.displayname');
  50. var defaultLocalDisplayName = APP.translation.generateTranslationHTML(
  51. interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME);
  52. var meHTML;
  53. // If we already have a display name for this video.
  54. if (nameSpan.length > 0) {
  55. if (nameSpan.text() !== displayName) {
  56. if (displayName && displayName.length > 0) {
  57. meHTML = APP.translation.generateTranslationHTML("me");
  58. $('#localDisplayName').html(
  59. UIUtil.escapeHtml(displayName) + ' (' + meHTML + ')'
  60. );
  61. } else {
  62. $('#localDisplayName').html(defaultLocalDisplayName);
  63. }
  64. }
  65. this.updateView();
  66. } else {
  67. var editButton = createEditDisplayNameButton();
  68. nameSpan = document.createElement('span');
  69. nameSpan.className = 'displayname';
  70. $('#' + this.videoSpanId)[0].appendChild(nameSpan);
  71. if (displayName && displayName.length > 0) {
  72. meHTML = APP.translation.generateTranslationHTML("me");
  73. nameSpan.innerHTML = UIUtil.escapeHtml(displayName) + meHTML;
  74. }
  75. else {
  76. nameSpan.innerHTML = defaultLocalDisplayName;
  77. }
  78. nameSpan.id = 'localDisplayName';
  79. this.container.appendChild(editButton);
  80. //translates popover of edit button
  81. APP.translation.translateElement($("a.displayname"));
  82. var editableText = document.createElement('input');
  83. editableText.className = 'displayname';
  84. editableText.type = 'text';
  85. editableText.id = 'editDisplayName';
  86. if (displayName && displayName.length) {
  87. editableText.value = displayName;
  88. }
  89. var defaultNickname = APP.translation.translateString(
  90. "defaultNickname", {name: "Jane Pink"});
  91. editableText.setAttribute('style', 'display:none;');
  92. editableText.setAttribute('data-18n',
  93. '[placeholder]defaultNickname');
  94. editableText.setAttribute("data-i18n-options",
  95. JSON.stringify({name: "Jane Pink"}));
  96. editableText.setAttribute("placeholder", defaultNickname);
  97. this.container.appendChild(editableText);
  98. var self = this;
  99. $('#localVideoContainer .displayname')
  100. .bind("click", function (e) {
  101. var editDisplayName = $('#editDisplayName');
  102. e.preventDefault();
  103. e.stopPropagation();
  104. $('#localDisplayName').hide();
  105. editDisplayName.show();
  106. editDisplayName.focus();
  107. editDisplayName.select();
  108. editDisplayName.one("focusout", function (e) {
  109. self.emitter.emit(UIEvents.NICKNAME_CHANGED, this.value);
  110. $('#editDisplayName').hide();
  111. });
  112. editDisplayName.on('keydown', function (e) {
  113. if (e.keyCode === 13) {
  114. e.preventDefault();
  115. $('#editDisplayName').hide();
  116. // focusout handler will save display name
  117. }
  118. });
  119. });
  120. }
  121. };
  122. LocalVideo.prototype.createConnectionIndicator = function() {
  123. if(this.connectionIndicator)
  124. return;
  125. this.connectionIndicator = new ConnectionIndicator(this, null);
  126. };
  127. LocalVideo.prototype.changeVideo = function (stream) {
  128. this.videoStream = stream;
  129. let localVideoClick = (event) => {
  130. // FIXME: with Temasys plugin event arg is not an event, but
  131. // the clicked object itself, so we have to skip this call
  132. if (event.stopPropagation) {
  133. event.stopPropagation();
  134. }
  135. this.VideoLayout.handleVideoThumbClicked(this.id);
  136. };
  137. let localVideoContainerSelector = $('#localVideoContainer');
  138. localVideoContainerSelector.off('click');
  139. localVideoContainerSelector.on('click', localVideoClick);
  140. this.flipX = stream.videoType != "desktop";
  141. let localVideo = document.createElement('video');
  142. localVideo.id = 'localVideo_' + stream.getId();
  143. RTCUIUtils.setAutoPlay(localVideo, true);
  144. RTCUIUtils.setVolume(localVideo, 0);
  145. var localVideoContainer = document.getElementById('localVideoWrapper');
  146. // Put the new video always in front
  147. UIUtil.prependChild(localVideoContainer, localVideo);
  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. $(localVideo).addClass("flipVideoX");
  154. }
  155. // Attach WebRTC stream
  156. localVideo = stream.attach(localVideo);
  157. let endedHandler = () => {
  158. localVideoContainer.removeChild(localVideo);
  159. // when removing only the video element and we are on stage
  160. // update the stage
  161. if(this.VideoLayout.isCurrentlyOnLarge(this.id))
  162. this.VideoLayout.updateLargeVideo(this.id);
  163. stream.off(TrackEvents.LOCAL_TRACK_STOPPED, endedHandler);
  164. };
  165. stream.on(TrackEvents.LOCAL_TRACK_STOPPED, endedHandler);
  166. };
  167. /**
  168. * Shows or hides the local video container.
  169. * @param {boolean} true to make the local video container visible, false
  170. * otherwise
  171. */
  172. LocalVideo.prototype.setVisible = function(visible) {
  173. // We toggle the hidden class as an indication to other interested parties
  174. // that this container has been hidden on purpose.
  175. $("#localVideoContainer").toggleClass("hidden");
  176. // We still show/hide it as we need to overwrite the style property if we
  177. // want our action to take effect. Toggling the display property through
  178. // the above css class didn't succeed in overwriting the style.
  179. if (visible) {
  180. $("#localVideoContainer").show();
  181. }
  182. else {
  183. $("#localVideoContainer").hide();
  184. }
  185. };
  186. export default LocalVideo;