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.

RemoteVideo.js 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. /* global $, APP, interfaceConfig */
  2. const logger = require("jitsi-meet-logger").getLogger(__filename);
  3. import ConnectionIndicator from './ConnectionIndicator';
  4. import SmallVideo from "./SmallVideo";
  5. import UIUtils from "../util/UIUtil";
  6. import UIEvents from '../../../service/UI/UIEvents';
  7. import JitsiPopover from "../util/JitsiPopover";
  8. const MUTED_DIALOG_BUTTON_VALUES = {
  9. cancel: 0,
  10. muted: 1
  11. };
  12. /**
  13. * Creates new instance of the <tt>RemoteVideo</tt>.
  14. * @param user {JitsiParticipant} the user for whom remote video instance will
  15. * be created.
  16. * @param {VideoLayout} VideoLayout the video layout instance.
  17. * @param {EventEmitter} emitter the event emitter which will be used by
  18. * the new instance to emit events.
  19. * @constructor
  20. */
  21. function RemoteVideo(user, VideoLayout, emitter) {
  22. this.user = user;
  23. this.id = user.getId();
  24. this.emitter = emitter;
  25. this.videoSpanId = `participant_${this.id}`;
  26. SmallVideo.call(this, VideoLayout);
  27. this.hasRemoteVideoMenu = false;
  28. this._supportsRemoteControl = false;
  29. this.addRemoteVideoContainer();
  30. this.connectionIndicator = new ConnectionIndicator(this, this.id);
  31. this.setDisplayName();
  32. this.bindHoverHandler();
  33. this.flipX = false;
  34. this.isLocal = false;
  35. this.popupMenuIsHovered = false;
  36. /**
  37. * The flag is set to <tt>true</tt> after the 'onplay' event has been
  38. * triggered on the current video element. It goes back to <tt>false</tt>
  39. * when the stream is removed. It is used to determine whether the video
  40. * playback has ever started.
  41. * @type {boolean}
  42. */
  43. this.wasVideoPlayed = false;
  44. /**
  45. * The flag is set to <tt>true</tt> if remote participant's video gets muted
  46. * during his media connection disruption. This is to prevent black video
  47. * being render on the thumbnail, because even though once the video has
  48. * been played the image usually remains on the video element it seems that
  49. * after longer period of the video element being hidden this image can be
  50. * lost.
  51. * @type {boolean}
  52. */
  53. this.mutedWhileDisconnected = false;
  54. }
  55. RemoteVideo.prototype = Object.create(SmallVideo.prototype);
  56. RemoteVideo.prototype.constructor = RemoteVideo;
  57. RemoteVideo.prototype.addRemoteVideoContainer = function() {
  58. this.container = RemoteVideo.createContainer(this.videoSpanId);
  59. this.initBrowserSpecificProperties();
  60. if (APP.conference.isModerator || this._supportsRemoteControl) {
  61. this.addRemoteVideoMenu();
  62. }
  63. this.VideoLayout.resizeThumbnails(false, true);
  64. this.addAudioLevelIndicator();
  65. return this.container;
  66. };
  67. /**
  68. * Initializes the remote participant popup menu, by specifying previously
  69. * constructed popupMenuElement, containing all the menu items.
  70. *
  71. * @param popupMenuElement a pre-constructed element, containing the menu items
  72. * to display in the popup
  73. */
  74. RemoteVideo.prototype._initPopupMenu = function (popupMenuElement) {
  75. let options = {
  76. content: popupMenuElement.outerHTML,
  77. skin: "black",
  78. hasArrow: false,
  79. onBeforePosition: el => APP.translation.translateElement(el)
  80. };
  81. let element = $("#" + this.videoSpanId + " .remotevideomenu");
  82. this.popover = new JitsiPopover(element, options);
  83. this.popover.addOnHoverPopover(isHovered => {
  84. this.popupMenuIsHovered = isHovered;
  85. this.updateView();
  86. });
  87. // override popover show method to make sure we will update the content
  88. // before showing the popover
  89. let origShowFunc = this.popover.show;
  90. this.popover.show = function () {
  91. // update content by forcing it, to finish even if popover
  92. // is not visible
  93. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  94. // call the original show, passing its actual this
  95. origShowFunc.call(this.popover);
  96. }.bind(this);
  97. };
  98. /**
  99. * Checks whether current video is considered hovered. Currently it is hovered
  100. * if the mouse is over the video, or if the connection indicator or the popup
  101. * menu is shown(hovered).
  102. * @private
  103. * NOTE: extends SmallVideo's method
  104. */
  105. RemoteVideo.prototype._isHovered = function () {
  106. let isHovered = SmallVideo.prototype._isHovered.call(this)
  107. || this.popupMenuIsHovered;
  108. return isHovered;
  109. };
  110. /**
  111. * Generates the popup menu content.
  112. *
  113. * @returns {Element|*} the constructed element, containing popup menu items
  114. * @private
  115. */
  116. RemoteVideo.prototype._generatePopupContent = function () {
  117. let popupmenuElement = document.createElement('ul');
  118. popupmenuElement.className = 'popupmenu';
  119. popupmenuElement.id = `remote_popupmenu_${this.id}`;
  120. let menuItems = [];
  121. if(APP.conference.isModerator) {
  122. let muteTranslationKey;
  123. let muteClassName;
  124. if (this.isAudioMuted) {
  125. muteTranslationKey = 'videothumbnail.muted';
  126. muteClassName = 'mutelink disabled';
  127. } else {
  128. muteTranslationKey = 'videothumbnail.domute';
  129. muteClassName = 'mutelink';
  130. }
  131. let muteHandler = this._muteHandler.bind(this);
  132. let kickHandler = this._kickHandler.bind(this);
  133. menuItems = [
  134. {
  135. id: 'mutelink_' + this.id,
  136. handler: muteHandler,
  137. icon: 'icon-mic-disabled',
  138. className: muteClassName,
  139. data: {
  140. i18n: muteTranslationKey
  141. }
  142. }, {
  143. id: 'ejectlink_' + this.id,
  144. handler: kickHandler,
  145. icon: 'icon-kick',
  146. data: {
  147. i18n: 'videothumbnail.kick'
  148. }
  149. }
  150. ];
  151. }
  152. if(this._supportsRemoteControl) {
  153. let icon, handler, className;
  154. if(APP.remoteControl.controller.getRequestedParticipant()
  155. === this.id) {
  156. handler = () => {};
  157. className = "requestRemoteControlLink disabled";
  158. icon = "remote-control-spinner fa fa-spinner fa-spin";
  159. } else if(!APP.remoteControl.controller.isStarted()) {
  160. handler = this._requestRemoteControlPermissions.bind(this);
  161. icon = "fa fa-play";
  162. className = "requestRemoteControlLink";
  163. } else {
  164. handler = this._stopRemoteControl.bind(this);
  165. icon = "fa fa-stop";
  166. className = "requestRemoteControlLink";
  167. }
  168. menuItems.push({
  169. id: 'remoteControl_' + this.id,
  170. handler,
  171. icon,
  172. className,
  173. data: {
  174. i18n: 'videothumbnail.remoteControl'
  175. }
  176. });
  177. }
  178. menuItems.forEach(el => {
  179. let menuItem = this._generatePopupMenuItem(el);
  180. popupmenuElement.appendChild(menuItem);
  181. });
  182. APP.translation.translateElement($(popupmenuElement));
  183. return popupmenuElement;
  184. };
  185. /**
  186. * Sets the remote control supported value and initializes or updates the menu
  187. * depending on the remote control is supported or not.
  188. * @param {boolean} isSupported
  189. */
  190. RemoteVideo.prototype.setRemoteControlSupport = function(isSupported = false) {
  191. if(this._supportsRemoteControl === isSupported) {
  192. return;
  193. }
  194. this._supportsRemoteControl = isSupported;
  195. if(!isSupported) {
  196. return;
  197. }
  198. if(!this.hasRemoteVideoMenu) {
  199. //create menu
  200. this.addRemoteVideoMenu();
  201. } else {
  202. //update the content
  203. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  204. }
  205. };
  206. /**
  207. * Requests permissions for remote control session.
  208. */
  209. RemoteVideo.prototype._requestRemoteControlPermissions = function () {
  210. APP.remoteControl.controller.requestPermissions(this.id).then(result => {
  211. if(result === null) {
  212. return;
  213. }
  214. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  215. APP.UI.messageHandler.openMessageDialog(
  216. "dialog.remoteControlTitle",
  217. (result === false) ? "dialog.remoteControlDeniedMessage"
  218. : "dialog.remoteControlAllowedMessage",
  219. {user: this.user.getDisplayName()
  220. || interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME}
  221. );
  222. let pinnedId = this.VideoLayout.getPinnedId();
  223. if(pinnedId !== this.id) {
  224. this.VideoLayout.handleVideoThumbClicked(this.id);
  225. }
  226. }, error => {
  227. logger.error(error);
  228. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  229. APP.UI.messageHandler.openMessageDialog(
  230. "dialog.remoteControlTitle",
  231. "dialog.remoteControlErrorMessage",
  232. {user: this.user.getDisplayName()
  233. || interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME}
  234. );
  235. });
  236. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  237. };
  238. /**
  239. * Stops remote control session.
  240. */
  241. RemoteVideo.prototype._stopRemoteControl = function () {
  242. // send message about stopping
  243. APP.remoteControl.controller.stop();
  244. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  245. };
  246. RemoteVideo.prototype._muteHandler = function () {
  247. if (this.isAudioMuted)
  248. return;
  249. RemoteVideo.showMuteParticipantDialog().then(reason => {
  250. if(reason === MUTED_DIALOG_BUTTON_VALUES.muted) {
  251. this.emitter.emit(UIEvents.REMOTE_AUDIO_MUTED, this.id);
  252. }
  253. }).catch(e => {
  254. //currently shouldn't be called
  255. logger.error(e);
  256. });
  257. this.popover.forceHide();
  258. };
  259. RemoteVideo.prototype._kickHandler = function () {
  260. this.emitter.emit(UIEvents.USER_KICKED, this.id);
  261. this.popover.forceHide();
  262. };
  263. RemoteVideo.prototype._generatePopupMenuItem = function (opts = {}) {
  264. let {
  265. id,
  266. handler,
  267. icon,
  268. data,
  269. className
  270. } = opts;
  271. handler = handler || $.noop;
  272. let menuItem = document.createElement('li');
  273. menuItem.className = 'popupmenu__item';
  274. let linkItem = document.createElement('a');
  275. linkItem.className = 'popupmenu__link';
  276. if (className) {
  277. linkItem.className += ` ${className}`;
  278. }
  279. if (icon) {
  280. let indicator = document.createElement('span');
  281. indicator.className = 'popupmenu__icon';
  282. indicator.innerHTML = `<i class="${icon}"></i>`;
  283. linkItem.appendChild(indicator);
  284. }
  285. let textContent = document.createElement('span');
  286. textContent.className = 'popupmenu__text';
  287. if (data) {
  288. let dataKeys = Object.keys(data);
  289. dataKeys.forEach(key => {
  290. textContent.dataset[key] = data[key];
  291. });
  292. }
  293. linkItem.appendChild(textContent);
  294. linkItem.id = id;
  295. linkItem.onclick = handler;
  296. menuItem.appendChild(linkItem);
  297. return menuItem;
  298. };
  299. /**
  300. * Updates the remote video menu.
  301. *
  302. * @param isMuted the new muted state to update to
  303. * @param force to work even if popover is not visible
  304. */
  305. RemoteVideo.prototype.updateRemoteVideoMenu = function (isMuted, force) {
  306. this.isAudioMuted = isMuted;
  307. // generate content, translate it and add it to document only if
  308. // popover is visible or we force to do so.
  309. if(this.popover.popoverShown || force) {
  310. this.popover.updateContent(this._generatePopupContent());
  311. }
  312. };
  313. /**
  314. * @inheritDoc
  315. */
  316. RemoteVideo.prototype.setMutedView = function(isMuted) {
  317. SmallVideo.prototype.setMutedView.call(this, isMuted);
  318. // Update 'mutedWhileDisconnected' flag
  319. this._figureOutMutedWhileDisconnected(this.isConnectionActive() === false);
  320. };
  321. /**
  322. * Figures out the value of {@link #mutedWhileDisconnected} flag by taking into
  323. * account remote participant's network connectivity and video muted status.
  324. *
  325. * @param {boolean} isDisconnected <tt>true</tt> if the remote participant is
  326. * currently having connectivity issues or <tt>false</tt> otherwise.
  327. *
  328. * @private
  329. */
  330. RemoteVideo.prototype._figureOutMutedWhileDisconnected
  331. = function(isDisconnected) {
  332. if (isDisconnected && this.isVideoMuted) {
  333. this.mutedWhileDisconnected = true;
  334. } else if (!isDisconnected && !this.isVideoMuted) {
  335. this.mutedWhileDisconnected = false;
  336. }
  337. };
  338. /**
  339. * Adds the remote video menu element for the given <tt>id</tt> in the
  340. * given <tt>parentElement</tt>.
  341. *
  342. * @param id the id indicating the video for which we're adding a menu.
  343. * @param parentElement the parent element where this menu will be added
  344. */
  345. RemoteVideo.prototype.addRemoteVideoMenu = function () {
  346. if (interfaceConfig.filmStripOnly) {
  347. return;
  348. }
  349. var spanElement = document.createElement('span');
  350. spanElement.className = 'remotevideomenu';
  351. this.container.appendChild(spanElement);
  352. var menuElement = document.createElement('i');
  353. menuElement.className = 'icon-menu-up';
  354. menuElement.title = 'Remote user controls';
  355. spanElement.appendChild(menuElement);
  356. this._initPopupMenu(this._generatePopupContent());
  357. this.hasRemoteVideoMenu = true;
  358. };
  359. /**
  360. * Removes the remote stream element corresponding to the given stream and
  361. * parent container.
  362. *
  363. * @param stream the MediaStream
  364. * @param isVideo <tt>true</tt> if given <tt>stream</tt> is a video one.
  365. */
  366. RemoteVideo.prototype.removeRemoteStreamElement = function (stream) {
  367. if (!this.container)
  368. return false;
  369. var isVideo = stream.isVideoTrack();
  370. var elementID = SmallVideo.getStreamElementID(stream);
  371. var select = $('#' + elementID);
  372. select.remove();
  373. if (isVideo) {
  374. this.wasVideoPlayed = false;
  375. }
  376. logger.info((isVideo ? "Video" : "Audio") +
  377. " removed " + this.id, select);
  378. // when removing only the video element and we are on stage
  379. // update the stage
  380. if (isVideo && this.isCurrentlyOnLargeVideo())
  381. this.VideoLayout.updateLargeVideo(this.id);
  382. else
  383. // Missing video stream will affect display mode
  384. this.updateView();
  385. };
  386. /**
  387. * Checks whether the remote user associated with this <tt>RemoteVideo</tt>
  388. * has connectivity issues.
  389. *
  390. * @return {boolean} <tt>true</tt> if the user's connection is fine or
  391. * <tt>false</tt> otherwise.
  392. */
  393. RemoteVideo.prototype.isConnectionActive = function() {
  394. return this.user.isConnectionActive();
  395. };
  396. /**
  397. * The remote video is considered "playable" once the stream has started
  398. * according to the {@link #hasVideoStarted} result.
  399. *
  400. * @inheritdoc
  401. * @override
  402. */
  403. RemoteVideo.prototype.isVideoPlayable = function () {
  404. return SmallVideo.prototype.isVideoPlayable.call(this)
  405. && this.hasVideoStarted() && !this.mutedWhileDisconnected;
  406. };
  407. /**
  408. * @inheritDoc
  409. */
  410. RemoteVideo.prototype.updateView = function () {
  411. this.updateConnectionStatusIndicator(
  412. null /* will obtain the status from 'conference' */);
  413. // This must be called after 'updateConnectionStatusIndicator' because it
  414. // affects the display mode by modifying 'mutedWhileDisconnected' flag
  415. SmallVideo.prototype.updateView.call(this);
  416. };
  417. /**
  418. * Updates the UI to reflect user's connectivity status.
  419. * @param isActive {boolean|null} 'true' if user's connection is active or
  420. * 'false' when the use is having some connectivity issues and a warning
  421. * should be displayed. When 'null' is passed then the current value will be
  422. * obtained from the conference instance.
  423. */
  424. RemoteVideo.prototype.updateConnectionStatusIndicator = function (isActive) {
  425. // Check for initial value if 'isActive' is not defined
  426. if (typeof isActive !== "boolean") {
  427. isActive = this.isConnectionActive();
  428. if (isActive === null) {
  429. // Cancel processing at this point - no update
  430. return;
  431. }
  432. }
  433. logger.debug(this.id + " thumbnail is connection active ? " + isActive);
  434. // Update 'mutedWhileDisconnected' flag
  435. this._figureOutMutedWhileDisconnected(!isActive);
  436. if(this.connectionIndicator)
  437. this.connectionIndicator.updateConnectionStatusIndicator(isActive);
  438. // Toggle thumbnail video problem filter
  439. this.selectVideoElement().toggleClass(
  440. "videoThumbnailProblemFilter", !isActive);
  441. this.$avatar().toggleClass(
  442. "videoThumbnailProblemFilter", !isActive);
  443. };
  444. /**
  445. * Removes RemoteVideo from the page.
  446. */
  447. RemoteVideo.prototype.remove = function () {
  448. logger.log("Remove thumbnail", this.id);
  449. this.removeConnectionIndicator();
  450. // Make sure that the large video is updated if are removing its
  451. // corresponding small video.
  452. this.VideoLayout.updateAfterThumbRemoved(this.id);
  453. // Remove whole container
  454. if (this.container.parentNode) {
  455. this.container.parentNode.removeChild(this.container);
  456. }
  457. };
  458. RemoteVideo.prototype.waitForPlayback = function (streamElement, stream) {
  459. var webRtcStream = stream.getOriginalStream();
  460. var isVideo = stream.isVideoTrack();
  461. if (!isVideo || webRtcStream.id === 'mixedmslabel') {
  462. return;
  463. }
  464. var self = this;
  465. // Triggers when video playback starts
  466. var onPlayingHandler = function () {
  467. self.wasVideoPlayed = true;
  468. self.VideoLayout.remoteVideoActive(streamElement, self.id);
  469. streamElement.onplaying = null;
  470. // Refresh to show the video
  471. self.updateView();
  472. };
  473. streamElement.onplaying = onPlayingHandler;
  474. };
  475. /**
  476. * Checks whether the video stream has started for this RemoteVideo instance.
  477. *
  478. * @returns {boolean} true if this RemoteVideo has a video stream for which
  479. * the playback has been started.
  480. */
  481. RemoteVideo.prototype.hasVideoStarted = function () {
  482. return this.wasVideoPlayed;
  483. };
  484. RemoteVideo.prototype.addRemoteStreamElement = function (stream) {
  485. if (!this.container) {
  486. return;
  487. }
  488. let isVideo = stream.isVideoTrack();
  489. isVideo ? this.videoStream = stream : this.audioStream = stream;
  490. if (isVideo)
  491. this.setVideoType(stream.videoType);
  492. // Add click handler.
  493. let onClickHandler = (event) => {
  494. let source = event.target || event.srcElement;
  495. // ignore click if it was done in popup menu
  496. if ($(source).parents('.popupmenu').length === 0) {
  497. this.VideoLayout.handleVideoThumbClicked(this.id);
  498. }
  499. // On IE we need to populate this handler on video <object>
  500. // and it does not give event instance as an argument,
  501. // so we check here for methods.
  502. if (event.stopPropagation && event.preventDefault) {
  503. event.stopPropagation();
  504. event.preventDefault();
  505. }
  506. return false;
  507. };
  508. this.container.onclick = onClickHandler;
  509. if(!stream.getOriginalStream())
  510. return;
  511. let streamElement = SmallVideo.createStreamElement(stream);
  512. // Put new stream element always in front
  513. UIUtils.prependChild(this.container, streamElement);
  514. // If we hide element when Temasys plugin is used then
  515. // we'll never receive 'onplay' event and other logic won't work as expected
  516. // NOTE: hiding will not have effect when Temasys plugin is in use, as
  517. // calling attach will show it back
  518. $(streamElement).hide();
  519. // If the container is currently visible
  520. // we attach the stream to the element.
  521. if (!isVideo || (this.container.offsetParent !== null && isVideo)) {
  522. this.waitForPlayback(streamElement, stream);
  523. streamElement = stream.attach(streamElement);
  524. }
  525. $(streamElement).click(onClickHandler);
  526. };
  527. /**
  528. * Show/hide peer container for the given id.
  529. */
  530. RemoteVideo.prototype.showPeerContainer = function (state) {
  531. if (!this.container)
  532. return;
  533. var isHide = state === 'hide';
  534. var resizeThumbnails = false;
  535. if (!isHide) {
  536. if (!$(this.container).is(':visible')) {
  537. resizeThumbnails = true;
  538. $(this.container).show();
  539. }
  540. // Call updateView, so that we'll figure out if avatar
  541. // should be displayed based on video muted status and whether or not
  542. // it's in the lastN set
  543. this.updateView();
  544. }
  545. else if ($(this.container).is(':visible') && isHide)
  546. {
  547. resizeThumbnails = true;
  548. $(this.container).hide();
  549. if(this.connectionIndicator)
  550. this.connectionIndicator.hide();
  551. }
  552. if (resizeThumbnails) {
  553. this.VideoLayout.resizeThumbnails();
  554. }
  555. // We want to be able to pin a participant from the contact list, even
  556. // if he's not in the lastN set!
  557. // ContactList.setClickable(id, !isHide);
  558. };
  559. RemoteVideo.prototype.updateResolution = function (resolution) {
  560. if (this.connectionIndicator) {
  561. this.connectionIndicator.updateResolution(resolution);
  562. }
  563. };
  564. RemoteVideo.prototype.removeConnectionIndicator = function () {
  565. if (this.connectionIndicator)
  566. this.connectionIndicator.remove();
  567. };
  568. RemoteVideo.prototype.hideConnectionIndicator = function () {
  569. if (this.connectionIndicator)
  570. this.connectionIndicator.hide();
  571. };
  572. /**
  573. * Sets the display name for the given video span id.
  574. *
  575. * @param displayName the display name to set
  576. */
  577. RemoteVideo.prototype.setDisplayName = function(displayName) {
  578. if (!this.container) {
  579. logger.warn( "Unable to set displayName - " + this.videoSpanId +
  580. " does not exist");
  581. return;
  582. }
  583. var nameSpan = $('#' + this.videoSpanId + ' .displayname');
  584. // If we already have a display name for this video.
  585. if (nameSpan.length > 0) {
  586. if (displayName && displayName.length > 0) {
  587. var displaynameSpan = $('#' + this.videoSpanId + '_name');
  588. if (displaynameSpan.text() !== displayName)
  589. displaynameSpan.text(displayName);
  590. }
  591. else
  592. $('#' + this.videoSpanId + '_name').text(
  593. interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME);
  594. } else {
  595. nameSpan = document.createElement('span');
  596. nameSpan.className = 'displayname';
  597. $('#' + this.videoSpanId)[0]
  598. .appendChild(nameSpan);
  599. if (displayName && displayName.length > 0) {
  600. $(nameSpan).text(displayName);
  601. } else {
  602. nameSpan.innerHTML = interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME;
  603. }
  604. nameSpan.id = this.videoSpanId + '_name';
  605. }
  606. };
  607. /**
  608. * Removes remote video menu element from video element identified by
  609. * given <tt>videoElementId</tt>.
  610. *
  611. * @param videoElementId the id of local or remote video element.
  612. */
  613. RemoteVideo.prototype.removeRemoteVideoMenu = function() {
  614. var menuSpan = $('#' + this.videoSpanId + '> .remotevideomenu');
  615. if (menuSpan.length) {
  616. this.popover.forceHide();
  617. menuSpan.remove();
  618. this.hasRemoteVideoMenu = false;
  619. }
  620. };
  621. RemoteVideo.createContainer = function (spanId) {
  622. let container = document.createElement('span');
  623. container.id = spanId;
  624. container.className = 'videocontainer';
  625. let wrapper = document.createElement('div');
  626. wrapper.className = 'videocontainer__background';
  627. container.appendChild(wrapper);
  628. let indicatorBar = document.createElement('div');
  629. indicatorBar.className = "videocontainer__toptoolbar";
  630. container.appendChild(indicatorBar);
  631. let toolbar = document.createElement('div');
  632. toolbar.className = "videocontainer__toolbar";
  633. container.appendChild(toolbar);
  634. let overlay = document.createElement('div');
  635. overlay.className = "videocontainer__hoverOverlay";
  636. container.appendChild(overlay);
  637. var remotes = document.getElementById('remoteVideos');
  638. return remotes.appendChild(container);
  639. };
  640. /**
  641. * Shows 2 button dialog for confirmation from the user for muting remote
  642. * participant.
  643. */
  644. RemoteVideo.showMuteParticipantDialog = function () {
  645. return new Promise(resolve => {
  646. APP.UI.messageHandler.openTwoButtonDialog({
  647. titleKey : "dialog.muteParticipantTitle",
  648. msgString: "<div data-i18n='dialog.muteParticipantBody'></div>",
  649. leftButtonKey: "dialog.muteParticipantButton",
  650. dontShowAgain: {
  651. id: "dontShowMuteParticipantDialog",
  652. textKey: "dialog.doNotShowMessageAgain",
  653. checked: true,
  654. buttonValues: [true]
  655. },
  656. submitFunction: () => resolve(MUTED_DIALOG_BUTTON_VALUES.muted),
  657. closeFunction: () => resolve(MUTED_DIALOG_BUTTON_VALUES.cancel)
  658. });
  659. });
  660. };
  661. export default RemoteVideo;