You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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. } else {
  60. var editButton = createEditDisplayNameButton();
  61. nameSpan = document.createElement('span');
  62. nameSpan.className = 'displayname';
  63. $('#' + this.videoSpanId)[0].appendChild(nameSpan);
  64. if (displayName && displayName.length > 0) {
  65. meHTML = APP.translation.generateTranslationHTML("me");
  66. nameSpan.innerHTML = displayName + meHTML;
  67. }
  68. else {
  69. nameSpan.innerHTML = defaultLocalDisplayName;
  70. }
  71. nameSpan.id = 'localDisplayName';
  72. this.container.appendChild(editButton);
  73. //translates popover of edit button
  74. APP.translation.translateElement($("a.displayname"));
  75. var editableText = document.createElement('input');
  76. editableText.className = 'displayname';
  77. editableText.type = 'text';
  78. editableText.id = 'editDisplayName';
  79. if (displayName && displayName.length) {
  80. editableText.value = displayName;
  81. }
  82. var defaultNickname = APP.translation.translateString(
  83. "defaultNickname", {name: "Jane Pink"});
  84. editableText.setAttribute('style', 'display:none;');
  85. editableText.setAttribute('data-18n',
  86. '[placeholder]defaultNickname');
  87. editableText.setAttribute("data-i18n-options",
  88. JSON.stringify({name: "Jane Pink"}));
  89. editableText.setAttribute("placeholder", defaultNickname);
  90. this.container.appendChild(editableText);
  91. var self = this;
  92. $('#localVideoContainer .displayname')
  93. .bind("click", function (e) {
  94. var editDisplayName = $('#editDisplayName');
  95. e.preventDefault();
  96. e.stopPropagation();
  97. $('#localDisplayName').hide();
  98. editDisplayName.show();
  99. editDisplayName.focus();
  100. editDisplayName.select();
  101. editDisplayName.one("focusout", function (e) {
  102. self.VideoLayout.inputDisplayNameHandler(this.value);
  103. $('#editDisplayName').hide();
  104. });
  105. editDisplayName.on('keydown', function (e) {
  106. if (e.keyCode === 13) {
  107. e.preventDefault();
  108. $('#editDisplayName').hide();
  109. // focusout handler will save display name
  110. }
  111. });
  112. });
  113. }
  114. };
  115. LocalVideo.prototype.inputDisplayNameHandler = function (name) {
  116. this.emitter.emit(UIEvents.NICKNAME_CHANGED, UIUtil.escapeHtml(name));
  117. };
  118. LocalVideo.prototype.createConnectionIndicator = function() {
  119. if(this.connectionIndicator)
  120. return;
  121. this.connectionIndicator = new ConnectionIndicator(this, null);
  122. };
  123. LocalVideo.prototype.changeVideo = function (stream) {
  124. this.stream = stream;
  125. let localVideoClick = (event) => {
  126. // FIXME: with Temasys plugin event arg is not an event, but
  127. // the clicked object itself, so we have to skip this call
  128. if (event.stopPropagation) {
  129. event.stopPropagation();
  130. }
  131. this.VideoLayout.handleVideoThumbClicked(true, this.id);
  132. };
  133. let localVideoContainerSelector = $('#localVideoContainer');
  134. localVideoContainerSelector.off('click');
  135. localVideoContainerSelector.on('click', localVideoClick);
  136. this.flipX = stream.videoType != "desktop";
  137. let localVideo = document.createElement('video');
  138. localVideo.id = 'localVideo_' + stream.getId();
  139. if (!RTCBrowserType.isIExplorer()) {
  140. localVideo.autoplay = true;
  141. localVideo.volume = 0; // is it required if audio is separated ?
  142. }
  143. localVideo.oncontextmenu = function () { return false; };
  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. self.VideoLayout.updateRemovedVideo(self.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;