選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

LocalVideo.js 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. const RTCUIUtils = JitsiMeetJS.util.RTCUIHelper;
  7. const TrackEvents = JitsiMeetJS.events.track;
  8. function LocalVideo(VideoLayout, emitter) {
  9. this.videoSpanId = "localVideoContainer";
  10. this.container = $("#localVideoContainer").get(0);
  11. this.localVideoId = null;
  12. if(config.enableLocalVideoFlip)
  13. this._buildContextMenu();
  14. this.isLocal = true;
  15. this.emitter = emitter;
  16. Object.defineProperty(this, 'id', {
  17. get: function () {
  18. return APP.conference.getMyUserId();
  19. }
  20. });
  21. this.initBrowserSpecificProperties();
  22. SmallVideo.call(this, VideoLayout);
  23. // Set default display name.
  24. this.setDisplayName();
  25. this.createConnectionIndicator();
  26. this.addAudioLevelIndicator();
  27. }
  28. LocalVideo.prototype = Object.create(SmallVideo.prototype);
  29. LocalVideo.prototype.constructor = LocalVideo;
  30. /**
  31. * Sets the display name for the given video span id.
  32. */
  33. LocalVideo.prototype.setDisplayName = function(displayName) {
  34. if (!this.container) {
  35. console.warn(
  36. "Unable to set displayName - " + this.videoSpanId +
  37. " does not exist");
  38. return;
  39. }
  40. var nameSpan = $('#' + this.videoSpanId + ' .displayname');
  41. var defaultLocalDisplayName = APP.translation.generateTranslationHTML(
  42. interfaceConfig.DEFAULT_LOCAL_DISPLAY_NAME);
  43. var meHTML;
  44. // If we already have a display name for this video.
  45. if (nameSpan.length > 0) {
  46. if (nameSpan.text() !== displayName) {
  47. if (displayName && displayName.length > 0) {
  48. meHTML = APP.translation.generateTranslationHTML("me");
  49. $('#localDisplayName').html(
  50. `${UIUtil.escapeHtml(displayName)} (${meHTML})`
  51. );
  52. $('#editDisplayName').val(
  53. `${UIUtil.escapeHtml(displayName)}`
  54. );
  55. } else {
  56. $('#localDisplayName').html(defaultLocalDisplayName);
  57. }
  58. }
  59. this.updateView();
  60. } else {
  61. nameSpan = document.createElement('span');
  62. nameSpan.className = 'displayname';
  63. document.getElementById(this.videoSpanId)
  64. .querySelector('.videocontainer__toolbar')
  65. .appendChild(nameSpan);
  66. if (displayName && displayName.length > 0) {
  67. meHTML = APP.translation.generateTranslationHTML("me");
  68. nameSpan.innerHTML = UIUtil.escapeHtml(displayName) + meHTML;
  69. }
  70. else {
  71. nameSpan.innerHTML = defaultLocalDisplayName;
  72. }
  73. nameSpan.id = 'localDisplayName';
  74. //translates popover of edit button
  75. APP.translation.translateElement($("a.displayname"));
  76. var editableText = document.createElement('input');
  77. editableText.className = 'editdisplayname';
  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
  92. .querySelector('.videocontainer__toolbar')
  93. .appendChild(editableText);
  94. var self = this;
  95. $('#localVideoContainer .displayname')
  96. .bind("click", function (e) {
  97. let $editDisplayName = $('#editDisplayName');
  98. let $localDisplayName = $('#localDisplayName');
  99. e.preventDefault();
  100. e.stopPropagation();
  101. $localDisplayName.hide();
  102. $editDisplayName.show();
  103. $editDisplayName.focus();
  104. $editDisplayName.select();
  105. $editDisplayName.one("focusout", function () {
  106. self.emitter.emit(UIEvents.NICKNAME_CHANGED, this.value);
  107. $editDisplayName.hide();
  108. $localDisplayName.show();
  109. });
  110. $editDisplayName.on('keydown', function (e) {
  111. if (e.keyCode === 13) {
  112. e.preventDefault();
  113. $('#editDisplayName').hide();
  114. // focusout handler will save display name
  115. }
  116. });
  117. });
  118. }
  119. };
  120. LocalVideo.prototype.createConnectionIndicator = function() {
  121. if(this.connectionIndicator)
  122. return;
  123. this.connectionIndicator = new ConnectionIndicator(this, null);
  124. };
  125. LocalVideo.prototype.changeVideo = function (stream) {
  126. this.videoStream = stream;
  127. let localVideoClick = (event) => {
  128. // FIXME: with Temasys plugin event arg is not an event, but
  129. // the clicked object itself, so we have to skip this call
  130. if (event.stopPropagation) {
  131. event.stopPropagation();
  132. }
  133. this.VideoLayout.handleVideoThumbClicked(this.id);
  134. };
  135. let localVideoContainerSelector = $('#localVideoContainer');
  136. localVideoContainerSelector.off('click');
  137. localVideoContainerSelector.on('click', localVideoClick);
  138. let localVideo = document.createElement('video');
  139. localVideo.id = this.localVideoId = 'localVideo_' + stream.getId();
  140. RTCUIUtils.setAutoPlay(localVideo, true);
  141. RTCUIUtils.setVolume(localVideo, 0);
  142. var localVideoContainer = document.getElementById('localVideoWrapper');
  143. // Put the new video always in front
  144. UIUtil.prependChild(localVideoContainer, localVideo);
  145. // Add click handler to both video and video wrapper elements in case
  146. // there's no video.
  147. // onclick has to be used with Temasys plugin
  148. localVideo.onclick = localVideoClick;
  149. let isVideo = stream.videoType != "desktop";
  150. this._enableDisableContextMenu(isVideo);
  151. this.setFlipX(isVideo? APP.settings.getLocalFlipX() : false);
  152. // Attach WebRTC stream
  153. localVideo = stream.attach(localVideo);
  154. let endedHandler = () => {
  155. localVideoContainer.removeChild(localVideo);
  156. // when removing only the video element and we are on stage
  157. // update the stage
  158. if(this.isCurrentlyOnLargeVideo())
  159. this.VideoLayout.updateLargeVideo(this.id);
  160. stream.off(TrackEvents.LOCAL_TRACK_STOPPED, endedHandler);
  161. };
  162. stream.on(TrackEvents.LOCAL_TRACK_STOPPED, endedHandler);
  163. };
  164. /**
  165. * Shows or hides the local video container.
  166. * @param {boolean} true to make the local video container visible, false
  167. * otherwise
  168. */
  169. LocalVideo.prototype.setVisible = function(visible) {
  170. // We toggle the hidden class as an indication to other interested parties
  171. // that this container has been hidden on purpose.
  172. $("#localVideoContainer").toggleClass("hidden");
  173. // We still show/hide it as we need to overwrite the style property if we
  174. // want our action to take effect. Toggling the display property through
  175. // the above css class didn't succeed in overwriting the style.
  176. if (visible) {
  177. $("#localVideoContainer").show();
  178. }
  179. else {
  180. $("#localVideoContainer").hide();
  181. }
  182. };
  183. /**
  184. * Sets the flipX state of the video.
  185. * @param val {boolean} true for flipped otherwise false;
  186. */
  187. LocalVideo.prototype.setFlipX = function (val) {
  188. this.emitter.emit(UIEvents.LOCAL_FLIPX_CHANGED, val);
  189. if(!this.localVideoId)
  190. return;
  191. if(val) {
  192. this.selectVideoElement().addClass("flipVideoX");
  193. } else {
  194. this.selectVideoElement().removeClass("flipVideoX");
  195. }
  196. };
  197. /**
  198. * Builds the context menu for the local video.
  199. */
  200. LocalVideo.prototype._buildContextMenu = function () {
  201. $.contextMenu({
  202. selector: '#' + this.videoSpanId,
  203. zIndex: 10000,
  204. items: {
  205. flip: {
  206. name: "Flip",
  207. callback: () => {
  208. let val = !APP.settings.getLocalFlipX();
  209. this.setFlipX(val);
  210. APP.settings.setLocalFlipX(val);
  211. }
  212. }
  213. },
  214. events: {
  215. show : function(options){
  216. options.items.flip.name =
  217. APP.translation.translateString("videothumbnail.flip");
  218. }
  219. }
  220. });
  221. };
  222. /**
  223. * Enables or disables the context menu for the local video.
  224. * @param enable {boolean} true for enable, false for disable
  225. */
  226. LocalVideo.prototype._enableDisableContextMenu = function (enable) {
  227. if($('#' + this.videoSpanId).contextMenu)
  228. $('#' + this.videoSpanId).contextMenu(enable);
  229. };
  230. export default LocalVideo;