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

RemoteVideo.js 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. /* global $, APP, interfaceConfig, JitsiMeetJS */
  2. /* eslint-disable no-unused-vars */
  3. import React from 'react';
  4. import {
  5. MuteButton,
  6. KickButton,
  7. REMOTE_CONTROL_MENU_STATES,
  8. RemoteControlButton,
  9. RemoteVideoMenu,
  10. VolumeSlider
  11. } from '../../../react/features/remote-video-menu';
  12. /* eslint-enable no-unused-vars */
  13. const logger = require("jitsi-meet-logger").getLogger(__filename);
  14. import ConnectionIndicator from './ConnectionIndicator';
  15. import SmallVideo from "./SmallVideo";
  16. import UIUtils from "../util/UIUtil";
  17. import UIEvents from '../../../service/UI/UIEvents';
  18. import JitsiPopover from "../util/JitsiPopover";
  19. const MUTED_DIALOG_BUTTON_VALUES = {
  20. cancel: 0,
  21. muted: 1
  22. };
  23. const ParticipantConnectionStatus
  24. = JitsiMeetJS.constants.participantConnectionStatus;
  25. /**
  26. * Creates new instance of the <tt>RemoteVideo</tt>.
  27. * @param user {JitsiParticipant} the user for whom remote video instance will
  28. * be created.
  29. * @param {VideoLayout} VideoLayout the video layout instance.
  30. * @param {EventEmitter} emitter the event emitter which will be used by
  31. * the new instance to emit events.
  32. * @constructor
  33. */
  34. function RemoteVideo(user, VideoLayout, emitter) {
  35. this.user = user;
  36. this.id = user.getId();
  37. this.emitter = emitter;
  38. this.videoSpanId = `participant_${this.id}`;
  39. SmallVideo.call(this, VideoLayout);
  40. this._audioStreamElement = null;
  41. this.hasRemoteVideoMenu = false;
  42. this._supportsRemoteControl = false;
  43. this.addRemoteVideoContainer();
  44. this.connectionIndicator = new ConnectionIndicator(this, this.id);
  45. this.setDisplayName();
  46. this.bindHoverHandler();
  47. this.flipX = false;
  48. this.isLocal = false;
  49. this.popupMenuIsHovered = false;
  50. /**
  51. * The flag is set to <tt>true</tt> after the 'onplay' event has been
  52. * triggered on the current video element. It goes back to <tt>false</tt>
  53. * when the stream is removed. It is used to determine whether the video
  54. * playback has ever started.
  55. * @type {boolean}
  56. */
  57. this.wasVideoPlayed = false;
  58. /**
  59. * The flag is set to <tt>true</tt> if remote participant's video gets muted
  60. * during his media connection disruption. This is to prevent black video
  61. * being render on the thumbnail, because even though once the video has
  62. * been played the image usually remains on the video element it seems that
  63. * after longer period of the video element being hidden this image can be
  64. * lost.
  65. * @type {boolean}
  66. */
  67. this.mutedWhileDisconnected = false;
  68. // Bind event handlers so they are only bound once for every instance.
  69. // TODO The event handlers should be turned into actions so changes can be
  70. // handled through reducers and middleware.
  71. this._kickHandler = this._kickHandler.bind(this);
  72. this._muteHandler = this._muteHandler.bind(this);
  73. this._requestRemoteControlPermissions
  74. = this._requestRemoteControlPermissions.bind(this);
  75. this._setAudioVolume = this._setAudioVolume.bind(this);
  76. this._stopRemoteControl = this._stopRemoteControl.bind(this);
  77. }
  78. RemoteVideo.prototype = Object.create(SmallVideo.prototype);
  79. RemoteVideo.prototype.constructor = RemoteVideo;
  80. RemoteVideo.prototype.addRemoteVideoContainer = function() {
  81. this.container = RemoteVideo.createContainer(this.videoSpanId);
  82. this.initBrowserSpecificProperties();
  83. if (APP.conference.isModerator || this._supportsRemoteControl) {
  84. this.addRemoteVideoMenu();
  85. }
  86. this.VideoLayout.resizeThumbnails(false, true);
  87. this.addAudioLevelIndicator();
  88. return this.container;
  89. };
  90. /**
  91. * Initializes the remote participant popup menu, by specifying previously
  92. * constructed popupMenuElement, containing all the menu items.
  93. *
  94. * @param popupMenuElement a pre-constructed element, containing the menu items
  95. * to display in the popup
  96. */
  97. RemoteVideo.prototype._initPopupMenu = function (popupMenuElement) {
  98. let options = {
  99. content: popupMenuElement.outerHTML,
  100. skin: "black",
  101. hasArrow: false,
  102. onBeforePosition: el => APP.translation.translateElement(el),
  103. position: interfaceConfig.VERTICAL_FILMSTRIP ? 'left' : 'top'
  104. };
  105. let element = $("#" + this.videoSpanId + " .remotevideomenu");
  106. this.popover = new JitsiPopover(element, options);
  107. this.popover.addOnHoverPopover(isHovered => {
  108. this.popupMenuIsHovered = isHovered;
  109. this.updateView();
  110. });
  111. // override popover show method to make sure we will update the content
  112. // before showing the popover
  113. let origShowFunc = this.popover.show;
  114. this.popover.show = function () {
  115. // update content by forcing it, to finish even if popover
  116. // is not visible
  117. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  118. // call the original show, passing its actual this
  119. origShowFunc.call(this.popover);
  120. }.bind(this);
  121. };
  122. /**
  123. * Checks whether current video is considered hovered. Currently it is hovered
  124. * if the mouse is over the video, or if the connection indicator or the popup
  125. * menu is shown(hovered).
  126. * @private
  127. * NOTE: extends SmallVideo's method
  128. */
  129. RemoteVideo.prototype._isHovered = function () {
  130. let isHovered = SmallVideo.prototype._isHovered.call(this)
  131. || this.popupMenuIsHovered;
  132. return isHovered;
  133. };
  134. /**
  135. * Generates the popup menu content.
  136. *
  137. * @returns {Element|*} the constructed element, containing popup menu items
  138. * @private
  139. */
  140. RemoteVideo.prototype._generatePopupContent = function () {
  141. const { controller } = APP.remoteControl;
  142. let remoteControlState = null;
  143. let onRemoteControlToggle;
  144. if (this._supportsRemoteControl) {
  145. if (controller.getRequestedParticipant() === this.id) {
  146. onRemoteControlToggle = () => {};
  147. remoteControlState = REMOTE_CONTROL_MENU_STATES.REQUESTING;
  148. } else if (!controller.isStarted()) {
  149. onRemoteControlToggle = this._requestRemoteControlPermissions;
  150. remoteControlState = REMOTE_CONTROL_MENU_STATES.NOT_STARTED;
  151. } else {
  152. onRemoteControlToggle = this._stopRemoteControl;
  153. remoteControlState = REMOTE_CONTROL_MENU_STATES.STARTED;
  154. }
  155. }
  156. let initialVolumeValue, onVolumeChange;
  157. // Feature check for volume setting as temasys objects cannot adjust volume.
  158. if (this._canSetAudioVolume()) {
  159. initialVolumeValue = this._getAudioElement().volume;
  160. onVolumeChange = this._setAudioVolume;
  161. }
  162. const { isModerator } = APP.conference;
  163. const participantID = this.id;
  164. /* jshint ignore:start */
  165. return (
  166. <RemoteVideoMenu id = { participantID }>
  167. { isModerator
  168. ? <MuteButton
  169. isAudioMuted = { this.isAudioMuted }
  170. onClick = { this._muteHandler }
  171. participantID = { participantID } />
  172. : null }
  173. { isModerator
  174. ? <KickButton
  175. onClick = { this._kickHandler }
  176. participantID = { participantID } />
  177. : null }
  178. { remoteControlState
  179. ? <RemoteControlButton
  180. onClick = { onRemoteControlToggle }
  181. participantID = { participantID }
  182. remoteControlState = { remoteControlState } />
  183. : null }
  184. { onVolumeChange
  185. ? <VolumeSlider
  186. initialValue = { initialVolumeValue }
  187. onChange = { onVolumeChange } />
  188. : null }
  189. </RemoteVideoMenu>
  190. );
  191. /* jshint ignore:end */
  192. };
  193. /**
  194. * Sets the remote control supported value and initializes or updates the menu
  195. * depending on the remote control is supported or not.
  196. * @param {boolean} isSupported
  197. */
  198. RemoteVideo.prototype.setRemoteControlSupport = function(isSupported = false) {
  199. if(this._supportsRemoteControl === isSupported) {
  200. return;
  201. }
  202. this._supportsRemoteControl = isSupported;
  203. if(!isSupported) {
  204. return;
  205. }
  206. if(!this.hasRemoteVideoMenu) {
  207. //create menu
  208. this.addRemoteVideoMenu();
  209. } else {
  210. //update the content
  211. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  212. }
  213. };
  214. /**
  215. * Requests permissions for remote control session.
  216. */
  217. RemoteVideo.prototype._requestRemoteControlPermissions = function () {
  218. APP.remoteControl.controller.requestPermissions(
  219. this.id, this.VideoLayout.getLargeVideoWrapper()).then(result => {
  220. if(result === null) {
  221. return;
  222. }
  223. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  224. APP.UI.messageHandler.openMessageDialog(
  225. "dialog.remoteControlTitle",
  226. (result === false) ? "dialog.remoteControlDeniedMessage"
  227. : "dialog.remoteControlAllowedMessage",
  228. {user: this.user.getDisplayName()
  229. || interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME}
  230. );
  231. if(result === true) {//the remote control permissions has been granted
  232. // pin the controlled participant
  233. let pinnedId = this.VideoLayout.getPinnedId();
  234. if(pinnedId !== this.id) {
  235. this.VideoLayout.handleVideoThumbClicked(this.id);
  236. }
  237. }
  238. }, error => {
  239. logger.error(error);
  240. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  241. APP.UI.messageHandler.openMessageDialog(
  242. "dialog.remoteControlTitle",
  243. "dialog.remoteControlErrorMessage",
  244. {user: this.user.getDisplayName()
  245. || interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME}
  246. );
  247. });
  248. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  249. };
  250. /**
  251. * Stops remote control session.
  252. */
  253. RemoteVideo.prototype._stopRemoteControl = function () {
  254. // send message about stopping
  255. APP.remoteControl.controller.stop();
  256. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  257. };
  258. RemoteVideo.prototype._muteHandler = function () {
  259. if (this.isAudioMuted)
  260. return;
  261. RemoteVideo.showMuteParticipantDialog().then(reason => {
  262. if(reason === MUTED_DIALOG_BUTTON_VALUES.muted) {
  263. this.emitter.emit(UIEvents.REMOTE_AUDIO_MUTED, this.id);
  264. }
  265. }).catch(e => {
  266. //currently shouldn't be called
  267. logger.error(e);
  268. });
  269. this.popover.forceHide();
  270. };
  271. RemoteVideo.prototype._kickHandler = function () {
  272. this.emitter.emit(UIEvents.USER_KICKED, this.id);
  273. this.popover.forceHide();
  274. };
  275. /**
  276. * Get the remote participant's audio element.
  277. *
  278. * @returns {Element} audio element
  279. */
  280. RemoteVideo.prototype._getAudioElement = function () {
  281. return this._audioStreamElement;
  282. };
  283. /**
  284. * Check if the remote participant's audio can have its volume adjusted.
  285. *
  286. * @returns {boolean} true if the volume can be adjusted.
  287. */
  288. RemoteVideo.prototype._canSetAudioVolume = function () {
  289. const audioElement = this._getAudioElement();
  290. return audioElement && audioElement.volume !== undefined;
  291. };
  292. /**
  293. * Change the remote participant's volume level.
  294. *
  295. * @param {int} newVal - The value to set the slider to.
  296. */
  297. RemoteVideo.prototype._setAudioVolume = function (newVal) {
  298. if (this._canSetAudioVolume()) {
  299. this._getAudioElement().volume = newVal;
  300. }
  301. };
  302. /**
  303. * Updates the remote video menu.
  304. *
  305. * @param isMuted the new muted state to update to
  306. * @param force to work even if popover is not visible
  307. */
  308. RemoteVideo.prototype.updateRemoteVideoMenu = function (isMuted, force) {
  309. this.isAudioMuted = isMuted;
  310. if (!this.popover) {
  311. return;
  312. }
  313. // generate content, translate it and add it to document only if
  314. // popover is visible or we force to do so.
  315. if(this.popover.popoverShown || force) {
  316. this.popover.updateContent(this._generatePopupContent());
  317. }
  318. };
  319. /**
  320. * @inheritDoc
  321. * @override
  322. */
  323. RemoteVideo.prototype.setVideoMutedView = function(isMuted) {
  324. SmallVideo.prototype.setVideoMutedView.call(this, isMuted);
  325. // Update 'mutedWhileDisconnected' flag
  326. this._figureOutMutedWhileDisconnected();
  327. };
  328. /**
  329. * Figures out the value of {@link #mutedWhileDisconnected} flag by taking into
  330. * account remote participant's network connectivity and video muted status.
  331. *
  332. * @private
  333. */
  334. RemoteVideo.prototype._figureOutMutedWhileDisconnected = function() {
  335. const isActive = this.isConnectionActive();
  336. if (!isActive && this.isVideoMuted) {
  337. this.mutedWhileDisconnected = true;
  338. } else if (isActive && !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.getConnectionStatus()
  399. === ParticipantConnectionStatus.ACTIVE;
  400. };
  401. /**
  402. * The remote video is considered "playable" once the stream has started
  403. * according to the {@link #hasVideoStarted} result.
  404. * It will be allowed to display video also in
  405. * {@link ParticipantConnectionStatus.INTERRUPTED} if the video was ever played
  406. * and was not muted while not in ACTIVE state. This basically means that there
  407. * is stalled video image cached that could be displayed. It's used to show
  408. * "grey video image" in user's thumbnail when there are connectivity issues.
  409. *
  410. * @inheritdoc
  411. * @override
  412. */
  413. RemoteVideo.prototype.isVideoPlayable = function () {
  414. const connectionState
  415. = APP.conference.getParticipantConnectionStatus(this.id);
  416. return SmallVideo.prototype.isVideoPlayable.call(this)
  417. && this.hasVideoStarted()
  418. && (connectionState === ParticipantConnectionStatus.ACTIVE
  419. || (connectionState === ParticipantConnectionStatus.INTERRUPTED
  420. && !this.mutedWhileDisconnected));
  421. };
  422. /**
  423. * @inheritDoc
  424. */
  425. RemoteVideo.prototype.updateView = function () {
  426. $(this.container).toggleClass('audio-only', APP.conference.isAudioOnly());
  427. this.updateConnectionStatusIndicator();
  428. // This must be called after 'updateConnectionStatusIndicator' because it
  429. // affects the display mode by modifying 'mutedWhileDisconnected' flag
  430. SmallVideo.prototype.updateView.call(this);
  431. };
  432. /**
  433. * Updates the UI to reflect user's connectivity status.
  434. */
  435. RemoteVideo.prototype.updateConnectionStatusIndicator = function () {
  436. const connectionStatus = this.user.getConnectionStatus();
  437. logger.debug(`${this.id} thumbnail connection status: ${connectionStatus}`);
  438. // FIXME rename 'mutedWhileDisconnected' to 'mutedWhileNotRendering'
  439. // Update 'mutedWhileDisconnected' flag
  440. this._figureOutMutedWhileDisconnected();
  441. if(this.connectionIndicator) {
  442. this.connectionIndicator.updateConnectionStatusIndicator(
  443. connectionStatus);
  444. }
  445. const isInterrupted
  446. = connectionStatus === ParticipantConnectionStatus.INTERRUPTED;
  447. // Toggle thumbnail video problem filter
  448. this.selectVideoElement().toggleClass(
  449. "videoThumbnailProblemFilter", isInterrupted);
  450. this.$avatar().toggleClass(
  451. "videoThumbnailProblemFilter", isInterrupted);
  452. };
  453. /**
  454. * Removes RemoteVideo from the page.
  455. */
  456. RemoteVideo.prototype.remove = function () {
  457. logger.log("Remove thumbnail", this.id);
  458. this.removeConnectionIndicator();
  459. // Make sure that the large video is updated if are removing its
  460. // corresponding small video.
  461. this.VideoLayout.updateAfterThumbRemoved(this.id);
  462. // Remove whole container
  463. if (this.container.parentNode) {
  464. this.container.parentNode.removeChild(this.container);
  465. }
  466. };
  467. RemoteVideo.prototype.waitForPlayback = function (streamElement, stream) {
  468. var webRtcStream = stream.getOriginalStream();
  469. var isVideo = stream.isVideoTrack();
  470. if (!isVideo || webRtcStream.id === 'mixedmslabel') {
  471. return;
  472. }
  473. var self = this;
  474. // Triggers when video playback starts
  475. var onPlayingHandler = function () {
  476. self.wasVideoPlayed = true;
  477. self.VideoLayout.remoteVideoActive(streamElement, self.id);
  478. streamElement.onplaying = null;
  479. // Refresh to show the video
  480. self.updateView();
  481. };
  482. streamElement.onplaying = onPlayingHandler;
  483. };
  484. /**
  485. * Checks whether the video stream has started for this RemoteVideo instance.
  486. *
  487. * @returns {boolean} true if this RemoteVideo has a video stream for which
  488. * the playback has been started.
  489. */
  490. RemoteVideo.prototype.hasVideoStarted = function () {
  491. return this.wasVideoPlayed;
  492. };
  493. RemoteVideo.prototype.addRemoteStreamElement = function (stream) {
  494. if (!this.container) {
  495. return;
  496. }
  497. let isVideo = stream.isVideoTrack();
  498. isVideo ? this.videoStream = stream : this.audioStream = stream;
  499. if (isVideo)
  500. this.setVideoType(stream.videoType);
  501. // Add click handler.
  502. let onClickHandler = (event) => {
  503. let source = event.target || event.srcElement;
  504. // ignore click if it was done in popup menu
  505. if ($(source).parents('.popupmenu').length === 0) {
  506. this.VideoLayout.handleVideoThumbClicked(this.id);
  507. }
  508. // On IE we need to populate this handler on video <object>
  509. // and it does not give event instance as an argument,
  510. // so we check here for methods.
  511. if (event.stopPropagation && event.preventDefault) {
  512. event.stopPropagation();
  513. event.preventDefault();
  514. }
  515. return false;
  516. };
  517. this.container.onclick = onClickHandler;
  518. if(!stream.getOriginalStream())
  519. return;
  520. let streamElement = SmallVideo.createStreamElement(stream);
  521. // Put new stream element always in front
  522. UIUtils.prependChild(this.container, streamElement);
  523. // If we hide element when Temasys plugin is used then
  524. // we'll never receive 'onplay' event and other logic won't work as expected
  525. // NOTE: hiding will not have effect when Temasys plugin is in use, as
  526. // calling attach will show it back
  527. $(streamElement).hide();
  528. // If the container is currently visible
  529. // we attach the stream to the element.
  530. if (!isVideo || (this.container.offsetParent !== null && isVideo)) {
  531. this.waitForPlayback(streamElement, stream);
  532. streamElement = stream.attach(streamElement);
  533. }
  534. $(streamElement).click(onClickHandler);
  535. if (!isVideo) {
  536. this._audioStreamElement = streamElement;
  537. }
  538. };
  539. RemoteVideo.prototype.updateResolution = function (resolution) {
  540. if (this.connectionIndicator) {
  541. this.connectionIndicator.updateResolution(resolution);
  542. }
  543. };
  544. /**
  545. * Updates this video framerate indication.
  546. * @param framerate the value to update
  547. */
  548. RemoteVideo.prototype.updateFramerate = function (framerate) {
  549. if (this.connectionIndicator) {
  550. this.connectionIndicator.updateFramerate(framerate);
  551. }
  552. };
  553. RemoteVideo.prototype.removeConnectionIndicator = function () {
  554. if (this.connectionIndicator)
  555. this.connectionIndicator.remove();
  556. };
  557. RemoteVideo.prototype.hideConnectionIndicator = function () {
  558. if (this.connectionIndicator)
  559. this.connectionIndicator.hide();
  560. };
  561. /**
  562. * Sets the display name for the given video span id.
  563. *
  564. * @param displayName the display name to set
  565. */
  566. RemoteVideo.prototype.setDisplayName = function(displayName) {
  567. if (!this.container) {
  568. logger.warn( "Unable to set displayName - " + this.videoSpanId +
  569. " does not exist");
  570. return;
  571. }
  572. var nameSpan = $('#' + this.videoSpanId + ' .displayname');
  573. // If we already have a display name for this video.
  574. if (nameSpan.length > 0) {
  575. if (displayName && displayName.length > 0) {
  576. var displaynameSpan = $('#' + this.videoSpanId + '_name');
  577. if (displaynameSpan.text() !== displayName)
  578. displaynameSpan.text(displayName);
  579. }
  580. else
  581. $('#' + this.videoSpanId + '_name').text(
  582. interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME);
  583. } else {
  584. nameSpan = document.createElement('span');
  585. nameSpan.className = 'displayname';
  586. $('#' + this.videoSpanId)[0]
  587. .appendChild(nameSpan);
  588. if (displayName && displayName.length > 0) {
  589. $(nameSpan).text(displayName);
  590. } else {
  591. nameSpan.innerHTML = interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME;
  592. }
  593. nameSpan.id = this.videoSpanId + '_name';
  594. }
  595. };
  596. /**
  597. * Removes remote video menu element from video element identified by
  598. * given <tt>videoElementId</tt>.
  599. *
  600. * @param videoElementId the id of local or remote video element.
  601. */
  602. RemoteVideo.prototype.removeRemoteVideoMenu = function() {
  603. var menuSpan = $('#' + this.videoSpanId + '> .remotevideomenu');
  604. if (menuSpan.length) {
  605. this.popover.forceHide();
  606. menuSpan.remove();
  607. this.hasRemoteVideoMenu = false;
  608. }
  609. };
  610. RemoteVideo.createContainer = function (spanId) {
  611. let container = document.createElement('span');
  612. container.id = spanId;
  613. container.className = 'videocontainer';
  614. let wrapper = document.createElement('div');
  615. wrapper.className = 'videocontainer__background';
  616. container.appendChild(wrapper);
  617. let indicatorBar = document.createElement('div');
  618. indicatorBar.className = "videocontainer__toptoolbar";
  619. container.appendChild(indicatorBar);
  620. let toolbar = document.createElement('div');
  621. toolbar.className = "videocontainer__toolbar";
  622. container.appendChild(toolbar);
  623. let overlay = document.createElement('div');
  624. overlay.className = "videocontainer__hoverOverlay";
  625. container.appendChild(overlay);
  626. var remotes = document.getElementById('filmstripRemoteVideosContainer');
  627. return remotes.appendChild(container);
  628. };
  629. /**
  630. * Shows 2 button dialog for confirmation from the user for muting remote
  631. * participant.
  632. */
  633. RemoteVideo.showMuteParticipantDialog = function () {
  634. return new Promise(resolve => {
  635. APP.UI.messageHandler.openTwoButtonDialog({
  636. titleKey : "dialog.muteParticipantTitle",
  637. msgString: "<div data-i18n='dialog.muteParticipantBody'></div>",
  638. leftButtonKey: "dialog.muteParticipantButton",
  639. dontShowAgain: {
  640. id: "dontShowMuteParticipantDialog",
  641. textKey: "dialog.doNotShowMessageAgain",
  642. checked: true,
  643. buttonValues: [true]
  644. },
  645. submitFunction: () => resolve(MUTED_DIALOG_BUTTON_VALUES.muted),
  646. closeFunction: () => resolve(MUTED_DIALOG_BUTTON_VALUES.cancel)
  647. });
  648. });
  649. };
  650. export default RemoteVideo;