Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

RemoteVideo.js 24KB

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