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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  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. }, error => {
  223. logger.error(error);
  224. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  225. APP.UI.messageHandler.openMessageDialog(
  226. "dialog.remoteControlTitle",
  227. "dialog.remoteControlErrorMessage",
  228. {user: this.user.getDisplayName()
  229. || interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME}
  230. );
  231. });
  232. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  233. };
  234. /**
  235. * Stops remote control session.
  236. */
  237. RemoteVideo.prototype._stopRemoteControl = function () {
  238. // send message about stopping
  239. APP.remoteControl.controller.stop();
  240. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  241. };
  242. RemoteVideo.prototype._muteHandler = function () {
  243. if (this.isAudioMuted)
  244. return;
  245. RemoteVideo.showMuteParticipantDialog().then(reason => {
  246. if(reason === MUTED_DIALOG_BUTTON_VALUES.muted) {
  247. this.emitter.emit(UIEvents.REMOTE_AUDIO_MUTED, this.id);
  248. }
  249. }).catch(e => {
  250. //currently shouldn't be called
  251. logger.error(e);
  252. });
  253. this.popover.forceHide();
  254. };
  255. RemoteVideo.prototype._kickHandler = function () {
  256. this.emitter.emit(UIEvents.USER_KICKED, this.id);
  257. this.popover.forceHide();
  258. };
  259. RemoteVideo.prototype._generatePopupMenuItem = function (opts = {}) {
  260. let {
  261. id,
  262. handler,
  263. icon,
  264. data,
  265. className
  266. } = opts;
  267. handler = handler || $.noop;
  268. let menuItem = document.createElement('li');
  269. menuItem.className = 'popupmenu__item';
  270. let linkItem = document.createElement('a');
  271. linkItem.className = 'popupmenu__link';
  272. if (className) {
  273. linkItem.className += ` ${className}`;
  274. }
  275. if (icon) {
  276. let indicator = document.createElement('span');
  277. indicator.className = 'popupmenu__icon';
  278. indicator.innerHTML = `<i class="${icon}"></i>`;
  279. linkItem.appendChild(indicator);
  280. }
  281. let textContent = document.createElement('span');
  282. textContent.className = 'popupmenu__text';
  283. if (data) {
  284. let dataKeys = Object.keys(data);
  285. dataKeys.forEach(key => {
  286. textContent.dataset[key] = data[key];
  287. });
  288. }
  289. linkItem.appendChild(textContent);
  290. linkItem.id = id;
  291. linkItem.onclick = handler;
  292. menuItem.appendChild(linkItem);
  293. return menuItem;
  294. };
  295. /**
  296. * Updates the remote video menu.
  297. *
  298. * @param isMuted the new muted state to update to
  299. * @param force to work even if popover is not visible
  300. */
  301. RemoteVideo.prototype.updateRemoteVideoMenu = function (isMuted, force) {
  302. this.isAudioMuted = isMuted;
  303. // generate content, translate it and add it to document only if
  304. // popover is visible or we force to do so.
  305. if(this.popover.popoverShown || force) {
  306. this.popover.updateContent(this._generatePopupContent());
  307. }
  308. };
  309. /**
  310. * @inheritDoc
  311. */
  312. RemoteVideo.prototype.setMutedView = function(isMuted) {
  313. SmallVideo.prototype.setMutedView.call(this, isMuted);
  314. // Update 'mutedWhileDisconnected' flag
  315. this._figureOutMutedWhileDisconnected(this.isConnectionActive() === false);
  316. };
  317. /**
  318. * Figures out the value of {@link #mutedWhileDisconnected} flag by taking into
  319. * account remote participant's network connectivity and video muted status.
  320. *
  321. * @param {boolean} isDisconnected <tt>true</tt> if the remote participant is
  322. * currently having connectivity issues or <tt>false</tt> otherwise.
  323. *
  324. * @private
  325. */
  326. RemoteVideo.prototype._figureOutMutedWhileDisconnected
  327. = function(isDisconnected) {
  328. if (isDisconnected && this.isVideoMuted) {
  329. this.mutedWhileDisconnected = true;
  330. } else if (!isDisconnected && !this.isVideoMuted) {
  331. this.mutedWhileDisconnected = false;
  332. }
  333. };
  334. /**
  335. * Adds the remote video menu element for the given <tt>id</tt> in the
  336. * given <tt>parentElement</tt>.
  337. *
  338. * @param id the id indicating the video for which we're adding a menu.
  339. * @param parentElement the parent element where this menu will be added
  340. */
  341. RemoteVideo.prototype.addRemoteVideoMenu = function () {
  342. if (interfaceConfig.filmStripOnly) {
  343. return;
  344. }
  345. var spanElement = document.createElement('span');
  346. spanElement.className = 'remotevideomenu';
  347. this.container.appendChild(spanElement);
  348. var menuElement = document.createElement('i');
  349. menuElement.className = 'icon-menu-up';
  350. menuElement.title = 'Remote user controls';
  351. spanElement.appendChild(menuElement);
  352. this._initPopupMenu(this._generatePopupContent());
  353. this.hasRemoteVideoMenu = true;
  354. };
  355. /**
  356. * Removes the remote stream element corresponding to the given stream and
  357. * parent container.
  358. *
  359. * @param stream the MediaStream
  360. * @param isVideo <tt>true</tt> if given <tt>stream</tt> is a video one.
  361. */
  362. RemoteVideo.prototype.removeRemoteStreamElement = function (stream) {
  363. if (!this.container)
  364. return false;
  365. var isVideo = stream.isVideoTrack();
  366. var elementID = SmallVideo.getStreamElementID(stream);
  367. var select = $('#' + elementID);
  368. select.remove();
  369. if (isVideo) {
  370. this.wasVideoPlayed = false;
  371. }
  372. logger.info((isVideo ? "Video" : "Audio") +
  373. " removed " + this.id, select);
  374. // when removing only the video element and we are on stage
  375. // update the stage
  376. if (isVideo && this.isCurrentlyOnLargeVideo())
  377. this.VideoLayout.updateLargeVideo(this.id);
  378. else
  379. // Missing video stream will affect display mode
  380. this.updateView();
  381. };
  382. /**
  383. * Checks whether the remote user associated with this <tt>RemoteVideo</tt>
  384. * has connectivity issues.
  385. *
  386. * @return {boolean} <tt>true</tt> if the user's connection is fine or
  387. * <tt>false</tt> otherwise.
  388. */
  389. RemoteVideo.prototype.isConnectionActive = function() {
  390. return this.user.isConnectionActive();
  391. };
  392. /**
  393. * The remote video is considered "playable" once the stream has started
  394. * according to the {@link #hasVideoStarted} result.
  395. *
  396. * @inheritdoc
  397. * @override
  398. */
  399. RemoteVideo.prototype.isVideoPlayable = function () {
  400. return SmallVideo.prototype.isVideoPlayable.call(this)
  401. && this.hasVideoStarted() && !this.mutedWhileDisconnected;
  402. };
  403. /**
  404. * @inheritDoc
  405. */
  406. RemoteVideo.prototype.updateView = function () {
  407. this.updateConnectionStatusIndicator(
  408. null /* will obtain the status from 'conference' */);
  409. // This must be called after 'updateConnectionStatusIndicator' because it
  410. // affects the display mode by modifying 'mutedWhileDisconnected' flag
  411. SmallVideo.prototype.updateView.call(this);
  412. };
  413. /**
  414. * Updates the UI to reflect user's connectivity status.
  415. * @param isActive {boolean|null} 'true' if user's connection is active or
  416. * 'false' when the use is having some connectivity issues and a warning
  417. * should be displayed. When 'null' is passed then the current value will be
  418. * obtained from the conference instance.
  419. */
  420. RemoteVideo.prototype.updateConnectionStatusIndicator = function (isActive) {
  421. // Check for initial value if 'isActive' is not defined
  422. if (typeof isActive !== "boolean") {
  423. isActive = this.isConnectionActive();
  424. if (isActive === null) {
  425. // Cancel processing at this point - no update
  426. return;
  427. }
  428. }
  429. logger.debug(this.id + " thumbnail is connection active ? " + isActive);
  430. // Update 'mutedWhileDisconnected' flag
  431. this._figureOutMutedWhileDisconnected(!isActive);
  432. if(this.connectionIndicator)
  433. this.connectionIndicator.updateConnectionStatusIndicator(isActive);
  434. // Toggle thumbnail video problem filter
  435. this.selectVideoElement().toggleClass(
  436. "videoThumbnailProblemFilter", !isActive);
  437. this.$avatar().toggleClass(
  438. "videoThumbnailProblemFilter", !isActive);
  439. };
  440. /**
  441. * Removes RemoteVideo from the page.
  442. */
  443. RemoteVideo.prototype.remove = function () {
  444. logger.log("Remove thumbnail", this.id);
  445. this.removeConnectionIndicator();
  446. // Make sure that the large video is updated if are removing its
  447. // corresponding small video.
  448. this.VideoLayout.updateAfterThumbRemoved(this.id);
  449. // Remove whole container
  450. if (this.container.parentNode) {
  451. this.container.parentNode.removeChild(this.container);
  452. }
  453. };
  454. RemoteVideo.prototype.waitForPlayback = function (streamElement, stream) {
  455. var webRtcStream = stream.getOriginalStream();
  456. var isVideo = stream.isVideoTrack();
  457. if (!isVideo || webRtcStream.id === 'mixedmslabel') {
  458. return;
  459. }
  460. var self = this;
  461. // Triggers when video playback starts
  462. var onPlayingHandler = function () {
  463. self.wasVideoPlayed = true;
  464. self.VideoLayout.remoteVideoActive(streamElement, self.id);
  465. streamElement.onplaying = null;
  466. // Refresh to show the video
  467. self.updateView();
  468. };
  469. streamElement.onplaying = onPlayingHandler;
  470. };
  471. /**
  472. * Checks whether the video stream has started for this RemoteVideo instance.
  473. *
  474. * @returns {boolean} true if this RemoteVideo has a video stream for which
  475. * the playback has been started.
  476. */
  477. RemoteVideo.prototype.hasVideoStarted = function () {
  478. return this.wasVideoPlayed;
  479. };
  480. RemoteVideo.prototype.addRemoteStreamElement = function (stream) {
  481. if (!this.container) {
  482. return;
  483. }
  484. let isVideo = stream.isVideoTrack();
  485. isVideo ? this.videoStream = stream : this.audioStream = stream;
  486. if (isVideo)
  487. this.setVideoType(stream.videoType);
  488. // Add click handler.
  489. let onClickHandler = (event) => {
  490. let source = event.target || event.srcElement;
  491. // ignore click if it was done in popup menu
  492. if ($(source).parents('.popupmenu').length === 0) {
  493. this.VideoLayout.handleVideoThumbClicked(this.id);
  494. }
  495. // On IE we need to populate this handler on video <object>
  496. // and it does not give event instance as an argument,
  497. // so we check here for methods.
  498. if (event.stopPropagation && event.preventDefault) {
  499. event.stopPropagation();
  500. event.preventDefault();
  501. }
  502. return false;
  503. };
  504. this.container.onclick = onClickHandler;
  505. if(!stream.getOriginalStream())
  506. return;
  507. let streamElement = SmallVideo.createStreamElement(stream);
  508. // Put new stream element always in front
  509. UIUtils.prependChild(this.container, streamElement);
  510. // If we hide element when Temasys plugin is used then
  511. // we'll never receive 'onplay' event and other logic won't work as expected
  512. // NOTE: hiding will not have effect when Temasys plugin is in use, as
  513. // calling attach will show it back
  514. $(streamElement).hide();
  515. // If the container is currently visible
  516. // we attach the stream to the element.
  517. if (!isVideo || (this.container.offsetParent !== null && isVideo)) {
  518. this.waitForPlayback(streamElement, stream);
  519. streamElement = stream.attach(streamElement);
  520. }
  521. $(streamElement).click(onClickHandler);
  522. };
  523. /**
  524. * Show/hide peer container for the given id.
  525. */
  526. RemoteVideo.prototype.showPeerContainer = function (state) {
  527. if (!this.container)
  528. return;
  529. var isHide = state === 'hide';
  530. var resizeThumbnails = false;
  531. if (!isHide) {
  532. if (!$(this.container).is(':visible')) {
  533. resizeThumbnails = true;
  534. $(this.container).show();
  535. }
  536. // Call updateView, so that we'll figure out if avatar
  537. // should be displayed based on video muted status and whether or not
  538. // it's in the lastN set
  539. this.updateView();
  540. }
  541. else if ($(this.container).is(':visible') && isHide)
  542. {
  543. resizeThumbnails = true;
  544. $(this.container).hide();
  545. if(this.connectionIndicator)
  546. this.connectionIndicator.hide();
  547. }
  548. if (resizeThumbnails) {
  549. this.VideoLayout.resizeThumbnails();
  550. }
  551. // We want to be able to pin a participant from the contact list, even
  552. // if he's not in the lastN set!
  553. // ContactList.setClickable(id, !isHide);
  554. };
  555. RemoteVideo.prototype.updateResolution = function (resolution) {
  556. if (this.connectionIndicator) {
  557. this.connectionIndicator.updateResolution(resolution);
  558. }
  559. };
  560. RemoteVideo.prototype.removeConnectionIndicator = function () {
  561. if (this.connectionIndicator)
  562. this.connectionIndicator.remove();
  563. };
  564. RemoteVideo.prototype.hideConnectionIndicator = function () {
  565. if (this.connectionIndicator)
  566. this.connectionIndicator.hide();
  567. };
  568. /**
  569. * Sets the display name for the given video span id.
  570. *
  571. * @param displayName the display name to set
  572. */
  573. RemoteVideo.prototype.setDisplayName = function(displayName) {
  574. if (!this.container) {
  575. logger.warn( "Unable to set displayName - " + this.videoSpanId +
  576. " does not exist");
  577. return;
  578. }
  579. var nameSpan = $('#' + this.videoSpanId + ' .displayname');
  580. // If we already have a display name for this video.
  581. if (nameSpan.length > 0) {
  582. if (displayName && displayName.length > 0) {
  583. var displaynameSpan = $('#' + this.videoSpanId + '_name');
  584. if (displaynameSpan.text() !== displayName)
  585. displaynameSpan.text(displayName);
  586. }
  587. else
  588. $('#' + this.videoSpanId + '_name').text(
  589. interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME);
  590. } else {
  591. nameSpan = document.createElement('span');
  592. nameSpan.className = 'displayname';
  593. $('#' + this.videoSpanId)[0]
  594. .appendChild(nameSpan);
  595. if (displayName && displayName.length > 0) {
  596. $(nameSpan).text(displayName);
  597. } else {
  598. nameSpan.innerHTML = interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME;
  599. }
  600. nameSpan.id = this.videoSpanId + '_name';
  601. }
  602. };
  603. /**
  604. * Removes remote video menu element from video element identified by
  605. * given <tt>videoElementId</tt>.
  606. *
  607. * @param videoElementId the id of local or remote video element.
  608. */
  609. RemoteVideo.prototype.removeRemoteVideoMenu = function() {
  610. var menuSpan = $('#' + this.videoSpanId + '> .remotevideomenu');
  611. if (menuSpan.length) {
  612. this.popover.forceHide();
  613. menuSpan.remove();
  614. this.hasRemoteVideoMenu = false;
  615. }
  616. };
  617. RemoteVideo.createContainer = function (spanId) {
  618. let container = document.createElement('span');
  619. container.id = spanId;
  620. container.className = 'videocontainer';
  621. let wrapper = document.createElement('div');
  622. wrapper.className = 'videocontainer__background';
  623. container.appendChild(wrapper);
  624. let indicatorBar = document.createElement('div');
  625. indicatorBar.className = "videocontainer__toptoolbar";
  626. container.appendChild(indicatorBar);
  627. let toolbar = document.createElement('div');
  628. toolbar.className = "videocontainer__toolbar";
  629. container.appendChild(toolbar);
  630. let overlay = document.createElement('div');
  631. overlay.className = "videocontainer__hoverOverlay";
  632. container.appendChild(overlay);
  633. var remotes = document.getElementById('remoteVideos');
  634. return remotes.appendChild(container);
  635. };
  636. /**
  637. * Shows 2 button dialog for confirmation from the user for muting remote
  638. * participant.
  639. */
  640. RemoteVideo.showMuteParticipantDialog = function () {
  641. return new Promise(resolve => {
  642. APP.UI.messageHandler.openTwoButtonDialog({
  643. titleKey : "dialog.muteParticipantTitle",
  644. msgString: "<div data-i18n='dialog.muteParticipantBody'></div>",
  645. leftButtonKey: "dialog.muteParticipantButton",
  646. dontShowAgain: {
  647. id: "dontShowMuteParticipantDialog",
  648. textKey: "dialog.doNotShowMessageAgain",
  649. checked: true,
  650. buttonValues: [true]
  651. },
  652. submitFunction: () => resolve(MUTED_DIALOG_BUTTON_VALUES.muted),
  653. closeFunction: () => resolve(MUTED_DIALOG_BUTTON_VALUES.cancel)
  654. });
  655. });
  656. };
  657. export default RemoteVideo;