您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

RemoteVideo.js 24KB

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