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.8KB

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