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

RemoteVideo.js 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  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. position: interfaceConfig.VERTICAL_FILMSTRIP ? 'left' : 'top'
  103. };
  104. let element = $("#" + this.videoSpanId + " .remotevideomenu");
  105. this.popover = new JitsiPopover(element, options);
  106. this.popover.addOnHoverPopover(isHovered => {
  107. this.popupMenuIsHovered = isHovered;
  108. this.updateView();
  109. });
  110. // override popover show method to make sure we will update the content
  111. // before showing the popover
  112. let origShowFunc = this.popover.show;
  113. this.popover.show = function () {
  114. // update content by forcing it, to finish even if popover
  115. // is not visible
  116. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  117. // call the original show, passing its actual this
  118. origShowFunc.call(this.popover);
  119. }.bind(this);
  120. };
  121. /**
  122. * Checks whether current video is considered hovered. Currently it is hovered
  123. * if the mouse is over the video, or if the connection indicator or the popup
  124. * menu is shown(hovered).
  125. * @private
  126. * NOTE: extends SmallVideo's method
  127. */
  128. RemoteVideo.prototype._isHovered = function () {
  129. let isHovered = SmallVideo.prototype._isHovered.call(this)
  130. || this.popupMenuIsHovered;
  131. return isHovered;
  132. };
  133. /**
  134. * Generates the popup menu content.
  135. *
  136. * @returns {Element|*} the constructed element, containing popup menu items
  137. * @private
  138. */
  139. RemoteVideo.prototype._generatePopupContent = function () {
  140. const { controller } = APP.remoteControl;
  141. let remoteControlState = null;
  142. let onRemoteControlToggle;
  143. if (this._supportsRemoteControl) {
  144. if (controller.getRequestedParticipant() === this.id) {
  145. onRemoteControlToggle = () => {};
  146. remoteControlState = REMOTE_CONTROL_MENU_STATES.REQUESTING;
  147. } else if (!controller.isStarted()) {
  148. onRemoteControlToggle = this._requestRemoteControlPermissions;
  149. remoteControlState = REMOTE_CONTROL_MENU_STATES.NOT_STARTED;
  150. } else {
  151. onRemoteControlToggle = this._stopRemoteControl;
  152. remoteControlState = REMOTE_CONTROL_MENU_STATES.STARTED;
  153. }
  154. }
  155. let initialVolumeValue, onVolumeChange;
  156. // Feature check for volume setting as temasys objects cannot adjust volume.
  157. if (this._canSetAudioVolume()) {
  158. initialVolumeValue = this._getAudioElement().volume;
  159. onVolumeChange = this._setAudioVolume;
  160. }
  161. const { isModerator } = APP.conference;
  162. const participantID = this.id;
  163. /* jshint ignore:start */
  164. return (
  165. <RemoteVideoMenu id = { participantID }>
  166. { isModerator
  167. ? <MuteButton
  168. isAudioMuted = { this.isAudioMuted }
  169. onClick = { this._muteHandler }
  170. participantID = { participantID } />
  171. : null }
  172. { isModerator
  173. ? <KickButton
  174. onClick = { this._kickHandler }
  175. participantID = { participantID } />
  176. : null }
  177. { remoteControlState
  178. ? <RemoteControlButton
  179. onClick = { onRemoteControlToggle }
  180. participantID = { participantID }
  181. remoteControlState = { remoteControlState } />
  182. : null }
  183. { onVolumeChange
  184. ? <VolumeSlider
  185. initialValue = { initialVolumeValue }
  186. onChange = { onVolumeChange } />
  187. : null }
  188. </RemoteVideoMenu>
  189. );
  190. /* jshint ignore:end */
  191. };
  192. /**
  193. * Sets the remote control supported value and initializes or updates the menu
  194. * depending on the remote control is supported or not.
  195. * @param {boolean} isSupported
  196. */
  197. RemoteVideo.prototype.setRemoteControlSupport = function(isSupported = false) {
  198. if(this._supportsRemoteControl === isSupported) {
  199. return;
  200. }
  201. this._supportsRemoteControl = isSupported;
  202. if(!isSupported) {
  203. return;
  204. }
  205. if(!this.hasRemoteVideoMenu) {
  206. //create menu
  207. this.addRemoteVideoMenu();
  208. } else {
  209. //update the content
  210. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  211. }
  212. };
  213. /**
  214. * Requests permissions for remote control session.
  215. */
  216. RemoteVideo.prototype._requestRemoteControlPermissions = function () {
  217. APP.remoteControl.controller.requestPermissions(
  218. this.id, this.VideoLayout.getLargeVideoWrapper()).then(result => {
  219. if(result === null) {
  220. return;
  221. }
  222. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  223. APP.UI.messageHandler.openMessageDialog(
  224. "dialog.remoteControlTitle",
  225. (result === false) ? "dialog.remoteControlDeniedMessage"
  226. : "dialog.remoteControlAllowedMessage",
  227. {user: this.user.getDisplayName()
  228. || interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME}
  229. );
  230. if(result === true) {//the remote control permissions has been granted
  231. // pin the controlled participant
  232. let pinnedId = this.VideoLayout.getPinnedId();
  233. if(pinnedId !== this.id) {
  234. this.VideoLayout.handleVideoThumbClicked(this.id);
  235. }
  236. }
  237. }, error => {
  238. logger.error(error);
  239. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  240. APP.UI.messageHandler.openMessageDialog(
  241. "dialog.remoteControlTitle",
  242. "dialog.remoteControlErrorMessage",
  243. {user: this.user.getDisplayName()
  244. || interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME}
  245. );
  246. });
  247. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  248. };
  249. /**
  250. * Stops remote control session.
  251. */
  252. RemoteVideo.prototype._stopRemoteControl = function () {
  253. // send message about stopping
  254. APP.remoteControl.controller.stop();
  255. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  256. };
  257. RemoteVideo.prototype._muteHandler = function () {
  258. if (this.isAudioMuted)
  259. return;
  260. RemoteVideo.showMuteParticipantDialog().then(reason => {
  261. if(reason === MUTED_DIALOG_BUTTON_VALUES.muted) {
  262. this.emitter.emit(UIEvents.REMOTE_AUDIO_MUTED, this.id);
  263. }
  264. }).catch(e => {
  265. //currently shouldn't be called
  266. logger.error(e);
  267. });
  268. this.popover.forceHide();
  269. };
  270. RemoteVideo.prototype._kickHandler = function () {
  271. this.emitter.emit(UIEvents.USER_KICKED, this.id);
  272. this.popover.forceHide();
  273. };
  274. /**
  275. * Get the remote participant's audio element.
  276. *
  277. * @returns {Element} audio element
  278. */
  279. RemoteVideo.prototype._getAudioElement = function () {
  280. return this._audioStreamElement;
  281. };
  282. /**
  283. * Check if the remote participant's audio can have its volume adjusted.
  284. *
  285. * @returns {boolean} true if the volume can be adjusted.
  286. */
  287. RemoteVideo.prototype._canSetAudioVolume = function () {
  288. const audioElement = this._getAudioElement();
  289. return audioElement && audioElement.volume !== undefined;
  290. };
  291. /**
  292. * Change the remote participant's volume level.
  293. *
  294. * @param {int} newVal - The value to set the slider to.
  295. */
  296. RemoteVideo.prototype._setAudioVolume = function (newVal) {
  297. if (this._canSetAudioVolume()) {
  298. this._getAudioElement().volume = newVal;
  299. }
  300. };
  301. /**
  302. * Updates the remote video menu.
  303. *
  304. * @param isMuted the new muted state to update to
  305. * @param force to work even if popover is not visible
  306. */
  307. RemoteVideo.prototype.updateRemoteVideoMenu = function (isMuted, force) {
  308. this.isAudioMuted = isMuted;
  309. if (!this.popover) {
  310. return;
  311. }
  312. // generate content, translate it and add it to document only if
  313. // popover is visible or we force to do so.
  314. if(this.popover.popoverShown || force) {
  315. this.popover.updateContent(this._generatePopupContent());
  316. }
  317. };
  318. /**
  319. * @inheritDoc
  320. * @override
  321. */
  322. RemoteVideo.prototype.setVideoMutedView = function(isMuted) {
  323. SmallVideo.prototype.setVideoMutedView.call(this, isMuted);
  324. // Update 'mutedWhileDisconnected' flag
  325. this._figureOutMutedWhileDisconnected();
  326. };
  327. /**
  328. * Figures out the value of {@link #mutedWhileDisconnected} flag by taking into
  329. * account remote participant's network connectivity and video muted status.
  330. *
  331. * @private
  332. */
  333. RemoteVideo.prototype._figureOutMutedWhileDisconnected = function() {
  334. const isActive = this.isConnectionActive();
  335. if (!isActive && this.isVideoMuted) {
  336. this.mutedWhileDisconnected = true;
  337. } else if (isActive && !this.isVideoMuted) {
  338. this.mutedWhileDisconnected = false;
  339. }
  340. };
  341. /**
  342. * Adds the remote video menu element for the given <tt>id</tt> in the
  343. * given <tt>parentElement</tt>.
  344. *
  345. * @param id the id indicating the video for which we're adding a menu.
  346. * @param parentElement the parent element where this menu will be added
  347. */
  348. RemoteVideo.prototype.addRemoteVideoMenu = function () {
  349. if (interfaceConfig.filmStripOnly) {
  350. return;
  351. }
  352. var spanElement = document.createElement('span');
  353. spanElement.className = 'remotevideomenu';
  354. this.container.appendChild(spanElement);
  355. var menuElement = document.createElement('i');
  356. menuElement.className = 'icon-menu-up';
  357. menuElement.title = 'Remote user controls';
  358. spanElement.appendChild(menuElement);
  359. this._initPopupMenu(this._generatePopupContent());
  360. this.hasRemoteVideoMenu = true;
  361. };
  362. /**
  363. * Removes the remote stream element corresponding to the given stream and
  364. * parent container.
  365. *
  366. * @param stream the MediaStream
  367. * @param isVideo <tt>true</tt> if given <tt>stream</tt> is a video one.
  368. */
  369. RemoteVideo.prototype.removeRemoteStreamElement = function (stream) {
  370. if (!this.container)
  371. return false;
  372. var isVideo = stream.isVideoTrack();
  373. var elementID = SmallVideo.getStreamElementID(stream);
  374. var select = $('#' + elementID);
  375. select.remove();
  376. if (isVideo) {
  377. this.wasVideoPlayed = false;
  378. }
  379. logger.info((isVideo ? "Video" : "Audio") +
  380. " removed " + this.id, select);
  381. // when removing only the video element and we are on stage
  382. // update the stage
  383. if (isVideo && this.isCurrentlyOnLargeVideo())
  384. this.VideoLayout.updateLargeVideo(this.id);
  385. else
  386. // Missing video stream will affect display mode
  387. this.updateView();
  388. };
  389. /**
  390. * Checks whether the remote user associated with this <tt>RemoteVideo</tt>
  391. * has connectivity issues.
  392. *
  393. * @return {boolean} <tt>true</tt> if the user's connection is fine or
  394. * <tt>false</tt> otherwise.
  395. */
  396. RemoteVideo.prototype.isConnectionActive = function() {
  397. return this.user.getConnectionStatus()
  398. === ParticipantConnectionStatus.ACTIVE;
  399. };
  400. /**
  401. * The remote video is considered "playable" once the stream has started
  402. * according to the {@link #hasVideoStarted} result.
  403. * It will be allowed to display video also in
  404. * {@link ParticipantConnectionStatus.INTERRUPTED} if the video was ever played
  405. * and was not muted while not in ACTIVE state. This basically means that there
  406. * is stalled video image cached that could be displayed. It's used to show
  407. * "grey video image" in user's thumbnail when there are connectivity issues.
  408. *
  409. * @inheritdoc
  410. * @override
  411. */
  412. RemoteVideo.prototype.isVideoPlayable = function () {
  413. const connectionState
  414. = APP.conference.getParticipantConnectionStatus(this.id);
  415. return SmallVideo.prototype.isVideoPlayable.call(this)
  416. && this.hasVideoStarted()
  417. && (connectionState === ParticipantConnectionStatus.ACTIVE
  418. || (connectionState === ParticipantConnectionStatus.INTERRUPTED
  419. && !this.mutedWhileDisconnected));
  420. };
  421. /**
  422. * @inheritDoc
  423. */
  424. RemoteVideo.prototype.updateView = function () {
  425. $(this.container).toggleClass('audio-only', APP.conference.isAudioOnly());
  426. this.updateConnectionStatusIndicator();
  427. // This must be called after 'updateConnectionStatusIndicator' because it
  428. // affects the display mode by modifying 'mutedWhileDisconnected' flag
  429. SmallVideo.prototype.updateView.call(this);
  430. };
  431. /**
  432. * Updates the UI to reflect user's connectivity status.
  433. */
  434. RemoteVideo.prototype.updateConnectionStatusIndicator = function () {
  435. const connectionStatus = this.user.getConnectionStatus();
  436. logger.debug(`${this.id} thumbnail connection status: ${connectionStatus}`);
  437. // FIXME rename 'mutedWhileDisconnected' to 'mutedWhileNotRendering'
  438. // Update 'mutedWhileDisconnected' flag
  439. this._figureOutMutedWhileDisconnected();
  440. if(this.connectionIndicator) {
  441. this.connectionIndicator.updateConnectionStatusIndicator(
  442. connectionStatus);
  443. }
  444. const isInterrupted
  445. = connectionStatus === ParticipantConnectionStatus.INTERRUPTED;
  446. // Toggle thumbnail video problem filter
  447. this.selectVideoElement().toggleClass(
  448. "videoThumbnailProblemFilter", isInterrupted);
  449. this.$avatar().toggleClass(
  450. "videoThumbnailProblemFilter", isInterrupted);
  451. };
  452. /**
  453. * Removes RemoteVideo from the page.
  454. */
  455. RemoteVideo.prototype.remove = function () {
  456. logger.log("Remove thumbnail", this.id);
  457. this.removeConnectionIndicator();
  458. // Make sure that the large video is updated if are removing its
  459. // corresponding small video.
  460. this.VideoLayout.updateAfterThumbRemoved(this.id);
  461. // Remove whole container
  462. if (this.container.parentNode) {
  463. this.container.parentNode.removeChild(this.container);
  464. }
  465. };
  466. RemoteVideo.prototype.waitForPlayback = function (streamElement, stream) {
  467. var webRtcStream = stream.getOriginalStream();
  468. var isVideo = stream.isVideoTrack();
  469. if (!isVideo || webRtcStream.id === 'mixedmslabel') {
  470. return;
  471. }
  472. var self = this;
  473. // Triggers when video playback starts
  474. var onPlayingHandler = function () {
  475. self.wasVideoPlayed = true;
  476. self.VideoLayout.remoteVideoActive(streamElement, self.id);
  477. streamElement.onplaying = null;
  478. // Refresh to show the video
  479. self.updateView();
  480. };
  481. streamElement.onplaying = onPlayingHandler;
  482. };
  483. /**
  484. * Checks whether the video stream has started for this RemoteVideo instance.
  485. *
  486. * @returns {boolean} true if this RemoteVideo has a video stream for which
  487. * the playback has been started.
  488. */
  489. RemoteVideo.prototype.hasVideoStarted = function () {
  490. return this.wasVideoPlayed;
  491. };
  492. RemoteVideo.prototype.addRemoteStreamElement = function (stream) {
  493. if (!this.container) {
  494. return;
  495. }
  496. let isVideo = stream.isVideoTrack();
  497. isVideo ? this.videoStream = stream : this.audioStream = stream;
  498. if (isVideo)
  499. this.setVideoType(stream.videoType);
  500. // Add click handler.
  501. let onClickHandler = (event) => {
  502. let source = event.target || event.srcElement;
  503. // ignore click if it was done in popup menu
  504. if ($(source).parents('.popupmenu').length === 0) {
  505. this.VideoLayout.handleVideoThumbClicked(this.id);
  506. }
  507. // On IE we need to populate this handler on video <object>
  508. // and it does not give event instance as an argument,
  509. // so we check here for methods.
  510. if (event.stopPropagation && event.preventDefault) {
  511. event.stopPropagation();
  512. event.preventDefault();
  513. }
  514. return false;
  515. };
  516. this.container.onclick = onClickHandler;
  517. if(!stream.getOriginalStream())
  518. return;
  519. let streamElement = SmallVideo.createStreamElement(stream);
  520. // Put new stream element always in front
  521. UIUtils.prependChild(this.container, streamElement);
  522. // If we hide element when Temasys plugin is used then
  523. // we'll never receive 'onplay' event and other logic won't work as expected
  524. // NOTE: hiding will not have effect when Temasys plugin is in use, as
  525. // calling attach will show it back
  526. $(streamElement).hide();
  527. // If the container is currently visible
  528. // we attach the stream to the element.
  529. if (!isVideo || (this.container.offsetParent !== null && isVideo)) {
  530. this.waitForPlayback(streamElement, stream);
  531. streamElement = stream.attach(streamElement);
  532. }
  533. $(streamElement).click(onClickHandler);
  534. if (!isVideo) {
  535. this._audioStreamElement = streamElement;
  536. }
  537. };
  538. RemoteVideo.prototype.updateResolution = function (resolution) {
  539. if (this.connectionIndicator) {
  540. this.connectionIndicator.updateResolution(resolution);
  541. }
  542. };
  543. /**
  544. * Updates this video framerate indication.
  545. * @param framerate the value to update
  546. */
  547. RemoteVideo.prototype.updateFramerate = function (framerate) {
  548. if (this.connectionIndicator) {
  549. this.connectionIndicator.updateFramerate(framerate);
  550. }
  551. };
  552. RemoteVideo.prototype.removeConnectionIndicator = function () {
  553. if (this.connectionIndicator)
  554. this.connectionIndicator.remove();
  555. };
  556. RemoteVideo.prototype.hideConnectionIndicator = function () {
  557. if (this.connectionIndicator)
  558. this.connectionIndicator.hide();
  559. };
  560. /**
  561. * Sets the display name for the given video span id.
  562. *
  563. * @param displayName the display name to set
  564. */
  565. RemoteVideo.prototype.setDisplayName = function(displayName) {
  566. if (!this.container) {
  567. logger.warn( "Unable to set displayName - " + this.videoSpanId +
  568. " does not exist");
  569. return;
  570. }
  571. var nameSpan = $('#' + this.videoSpanId + ' .displayname');
  572. // If we already have a display name for this video.
  573. if (nameSpan.length > 0) {
  574. if (displayName && displayName.length > 0) {
  575. var displaynameSpan = $('#' + this.videoSpanId + '_name');
  576. if (displaynameSpan.text() !== displayName)
  577. displaynameSpan.text(displayName);
  578. }
  579. else
  580. $('#' + this.videoSpanId + '_name').text(
  581. interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME);
  582. } else {
  583. nameSpan = document.createElement('span');
  584. nameSpan.className = 'displayname';
  585. $('#' + this.videoSpanId)[0]
  586. .appendChild(nameSpan);
  587. if (displayName && displayName.length > 0) {
  588. $(nameSpan).text(displayName);
  589. } else {
  590. nameSpan.innerHTML = interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME;
  591. }
  592. nameSpan.id = this.videoSpanId + '_name';
  593. }
  594. };
  595. /**
  596. * Removes remote video menu element from video element identified by
  597. * given <tt>videoElementId</tt>.
  598. *
  599. * @param videoElementId the id of local or remote video element.
  600. */
  601. RemoteVideo.prototype.removeRemoteVideoMenu = function() {
  602. var menuSpan = $('#' + this.videoSpanId + '> .remotevideomenu');
  603. if (menuSpan.length) {
  604. this.popover.forceHide();
  605. menuSpan.remove();
  606. this.hasRemoteVideoMenu = false;
  607. }
  608. };
  609. RemoteVideo.createContainer = function (spanId) {
  610. let container = document.createElement('span');
  611. container.id = spanId;
  612. container.className = 'videocontainer';
  613. let wrapper = document.createElement('div');
  614. wrapper.className = 'videocontainer__background';
  615. container.appendChild(wrapper);
  616. let indicatorBar = document.createElement('div');
  617. indicatorBar.className = "videocontainer__toptoolbar";
  618. container.appendChild(indicatorBar);
  619. let toolbar = document.createElement('div');
  620. toolbar.className = "videocontainer__toolbar";
  621. container.appendChild(toolbar);
  622. let overlay = document.createElement('div');
  623. overlay.className = "videocontainer__hoverOverlay";
  624. container.appendChild(overlay);
  625. var remotes = document.getElementById('filmstripRemoteVideosContainer');
  626. return remotes.appendChild(container);
  627. };
  628. /**
  629. * Shows 2 button dialog for confirmation from the user for muting remote
  630. * participant.
  631. */
  632. RemoteVideo.showMuteParticipantDialog = function () {
  633. return new Promise(resolve => {
  634. APP.UI.messageHandler.openTwoButtonDialog({
  635. titleKey : "dialog.muteParticipantTitle",
  636. msgString: "<div data-i18n='dialog.muteParticipantBody'></div>",
  637. leftButtonKey: "dialog.muteParticipantButton",
  638. dontShowAgain: {
  639. id: "dontShowMuteParticipantDialog",
  640. textKey: "dialog.doNotShowMessageAgain",
  641. checked: true,
  642. buttonValues: [true]
  643. },
  644. submitFunction: () => resolve(MUTED_DIALOG_BUTTON_VALUES.muted),
  645. closeFunction: () => resolve(MUTED_DIALOG_BUTTON_VALUES.cancel)
  646. });
  647. });
  648. };
  649. export default RemoteVideo;