Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. /* global $, APP, interfaceConfig, JitsiMeetJS */
  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. const ParticipantConnectionStatus
  13. = JitsiMeetJS.constants.participantConnectionStatus;
  14. /**
  15. * Creates new instance of the <tt>RemoteVideo</tt>.
  16. * @param user {JitsiParticipant} the user for whom remote video instance will
  17. * be created.
  18. * @param {VideoLayout} VideoLayout the video layout instance.
  19. * @param {EventEmitter} emitter the event emitter which will be used by
  20. * the new instance to emit events.
  21. * @constructor
  22. */
  23. function RemoteVideo(user, VideoLayout, emitter) {
  24. this.user = user;
  25. this.id = user.getId();
  26. this.emitter = emitter;
  27. this.videoSpanId = `participant_${this.id}`;
  28. SmallVideo.call(this, VideoLayout);
  29. this._audioStreamElement = null;
  30. this.hasRemoteVideoMenu = false;
  31. this._supportsRemoteControl = false;
  32. this.addRemoteVideoContainer();
  33. this.connectionIndicator = new ConnectionIndicator(this, this.id);
  34. this.setDisplayName();
  35. this.bindHoverHandler();
  36. this.flipX = false;
  37. this.isLocal = false;
  38. this.popupMenuIsHovered = false;
  39. /**
  40. * The flag is set to <tt>true</tt> after the 'onplay' event has been
  41. * triggered on the current video element. It goes back to <tt>false</tt>
  42. * when the stream is removed. It is used to determine whether the video
  43. * playback has ever started.
  44. * @type {boolean}
  45. */
  46. this.wasVideoPlayed = false;
  47. /**
  48. * The flag is set to <tt>true</tt> if remote participant's video gets muted
  49. * during his media connection disruption. This is to prevent black video
  50. * being render on the thumbnail, because even though once the video has
  51. * been played the image usually remains on the video element it seems that
  52. * after longer period of the video element being hidden this image can be
  53. * lost.
  54. * @type {boolean}
  55. */
  56. this.mutedWhileDisconnected = false;
  57. }
  58. RemoteVideo.prototype = Object.create(SmallVideo.prototype);
  59. RemoteVideo.prototype.constructor = RemoteVideo;
  60. RemoteVideo.prototype.addRemoteVideoContainer = function() {
  61. this.container = RemoteVideo.createContainer(this.videoSpanId);
  62. this.initBrowserSpecificProperties();
  63. if (APP.conference.isModerator || this._supportsRemoteControl) {
  64. this.addRemoteVideoMenu();
  65. }
  66. this.VideoLayout.resizeThumbnails(false, true);
  67. this.addAudioLevelIndicator();
  68. return this.container;
  69. };
  70. /**
  71. * Initializes the remote participant popup menu, by specifying previously
  72. * constructed popupMenuElement, containing all the menu items.
  73. *
  74. * @param popupMenuElement a pre-constructed element, containing the menu items
  75. * to display in the popup
  76. */
  77. RemoteVideo.prototype._initPopupMenu = function (popupMenuElement) {
  78. let options = {
  79. content: popupMenuElement.outerHTML,
  80. skin: "black",
  81. hasArrow: false,
  82. onBeforePosition: el => APP.translation.translateElement(el)
  83. };
  84. let element = $("#" + this.videoSpanId + " .remotevideomenu");
  85. this.popover = new JitsiPopover(element, options);
  86. this.popover.addOnHoverPopover(isHovered => {
  87. this.popupMenuIsHovered = isHovered;
  88. this.updateView();
  89. });
  90. // override popover show method to make sure we will update the content
  91. // before showing the popover
  92. let origShowFunc = this.popover.show;
  93. this.popover.show = function () {
  94. // update content by forcing it, to finish even if popover
  95. // is not visible
  96. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  97. // call the original show, passing its actual this
  98. origShowFunc.call(this.popover);
  99. }.bind(this);
  100. };
  101. /**
  102. * Checks whether current video is considered hovered. Currently it is hovered
  103. * if the mouse is over the video, or if the connection indicator or the popup
  104. * menu is shown(hovered).
  105. * @private
  106. * NOTE: extends SmallVideo's method
  107. */
  108. RemoteVideo.prototype._isHovered = function () {
  109. let isHovered = SmallVideo.prototype._isHovered.call(this)
  110. || this.popupMenuIsHovered;
  111. return isHovered;
  112. };
  113. /**
  114. * Generates the popup menu content.
  115. *
  116. * @returns {Element|*} the constructed element, containing popup menu items
  117. * @private
  118. */
  119. RemoteVideo.prototype._generatePopupContent = function () {
  120. let popupmenuElement = document.createElement('ul');
  121. popupmenuElement.className = 'popupmenu';
  122. popupmenuElement.id = `remote_popupmenu_${this.id}`;
  123. let menuItems = [];
  124. if(APP.conference.isModerator) {
  125. let muteTranslationKey;
  126. let muteClassName;
  127. if (this.isAudioMuted) {
  128. muteTranslationKey = 'videothumbnail.muted';
  129. muteClassName = 'mutelink disabled';
  130. } else {
  131. muteTranslationKey = 'videothumbnail.domute';
  132. muteClassName = 'mutelink';
  133. }
  134. let muteHandler = this._muteHandler.bind(this);
  135. let kickHandler = this._kickHandler.bind(this);
  136. menuItems = [
  137. {
  138. id: 'mutelink_' + this.id,
  139. handler: muteHandler,
  140. icon: 'icon-mic-disabled',
  141. className: muteClassName,
  142. data: {
  143. i18n: muteTranslationKey
  144. }
  145. }, {
  146. id: 'ejectlink_' + this.id,
  147. handler: kickHandler,
  148. icon: 'icon-kick',
  149. data: {
  150. i18n: 'videothumbnail.kick'
  151. }
  152. }
  153. ];
  154. }
  155. if(this._supportsRemoteControl) {
  156. let icon, handler, className;
  157. if(APP.remoteControl.controller.getRequestedParticipant()
  158. === this.id) {
  159. handler = () => {};
  160. className = "requestRemoteControlLink disabled";
  161. icon = "remote-control-spinner fa fa-spinner fa-spin";
  162. } else if(!APP.remoteControl.controller.isStarted()) {
  163. handler = this._requestRemoteControlPermissions.bind(this);
  164. icon = "fa fa-play";
  165. className = "requestRemoteControlLink";
  166. } else {
  167. handler = this._stopRemoteControl.bind(this);
  168. icon = "fa fa-stop";
  169. className = "requestRemoteControlLink";
  170. }
  171. menuItems.push({
  172. id: 'remoteControl_' + this.id,
  173. handler,
  174. icon,
  175. className,
  176. data: {
  177. i18n: 'videothumbnail.remoteControl'
  178. }
  179. });
  180. }
  181. menuItems.forEach(el => {
  182. let menuItem = this._generatePopupMenuItem(el);
  183. popupmenuElement.appendChild(menuItem);
  184. });
  185. // feature check for volume setting as temasys objects cannot adjust volume
  186. if (this._canSetAudioVolume()) {
  187. const volumeScale = 100;
  188. const volumeSlider = this._generatePopupMenuSliderItem({
  189. handler: this._setAudioVolume.bind(this, volumeScale),
  190. icon: 'icon-volume',
  191. initialValue: this._getAudioElement().volume * volumeScale,
  192. maxValue: volumeScale
  193. });
  194. popupmenuElement.appendChild(volumeSlider);
  195. }
  196. APP.translation.translateElement($(popupmenuElement));
  197. return popupmenuElement;
  198. };
  199. /**
  200. * Sets the remote control supported value and initializes or updates the menu
  201. * depending on the remote control is supported or not.
  202. * @param {boolean} isSupported
  203. */
  204. RemoteVideo.prototype.setRemoteControlSupport = function(isSupported = false) {
  205. if(this._supportsRemoteControl === isSupported) {
  206. return;
  207. }
  208. this._supportsRemoteControl = isSupported;
  209. if(!isSupported) {
  210. return;
  211. }
  212. if(!this.hasRemoteVideoMenu) {
  213. //create menu
  214. this.addRemoteVideoMenu();
  215. } else {
  216. //update the content
  217. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  218. }
  219. };
  220. /**
  221. * Requests permissions for remote control session.
  222. */
  223. RemoteVideo.prototype._requestRemoteControlPermissions = function () {
  224. APP.remoteControl.controller.requestPermissions(
  225. this.id, this.VideoLayout.getLargeVideoWrapper()).then(result => {
  226. if(result === null) {
  227. return;
  228. }
  229. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  230. APP.UI.messageHandler.openMessageDialog(
  231. "dialog.remoteControlTitle",
  232. (result === false) ? "dialog.remoteControlDeniedMessage"
  233. : "dialog.remoteControlAllowedMessage",
  234. {user: this.user.getDisplayName()
  235. || interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME}
  236. );
  237. if(result === true) {//the remote control permissions has been granted
  238. // pin the controlled participant
  239. let pinnedId = this.VideoLayout.getPinnedId();
  240. if(pinnedId !== this.id) {
  241. this.VideoLayout.handleVideoThumbClicked(this.id);
  242. }
  243. }
  244. }, error => {
  245. logger.error(error);
  246. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  247. APP.UI.messageHandler.openMessageDialog(
  248. "dialog.remoteControlTitle",
  249. "dialog.remoteControlErrorMessage",
  250. {user: this.user.getDisplayName()
  251. || interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME}
  252. );
  253. });
  254. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  255. };
  256. /**
  257. * Stops remote control session.
  258. */
  259. RemoteVideo.prototype._stopRemoteControl = function () {
  260. // send message about stopping
  261. APP.remoteControl.controller.stop();
  262. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  263. };
  264. RemoteVideo.prototype._muteHandler = function () {
  265. if (this.isAudioMuted)
  266. return;
  267. RemoteVideo.showMuteParticipantDialog().then(reason => {
  268. if(reason === MUTED_DIALOG_BUTTON_VALUES.muted) {
  269. this.emitter.emit(UIEvents.REMOTE_AUDIO_MUTED, this.id);
  270. }
  271. }).catch(e => {
  272. //currently shouldn't be called
  273. logger.error(e);
  274. });
  275. this.popover.forceHide();
  276. };
  277. RemoteVideo.prototype._kickHandler = function () {
  278. this.emitter.emit(UIEvents.USER_KICKED, this.id);
  279. this.popover.forceHide();
  280. };
  281. RemoteVideo.prototype._generatePopupMenuItem = function (opts = {}) {
  282. let {
  283. id,
  284. handler,
  285. icon,
  286. data,
  287. className
  288. } = opts;
  289. handler = handler || $.noop;
  290. let menuItem = document.createElement('li');
  291. menuItem.className = 'popupmenu__item';
  292. let linkItem = document.createElement('a');
  293. linkItem.className = 'popupmenu__link';
  294. if (className) {
  295. linkItem.className += ` ${className}`;
  296. }
  297. if (icon) {
  298. let indicator = document.createElement('span');
  299. indicator.className = 'popupmenu__icon';
  300. indicator.innerHTML = `<i class="${icon}"></i>`;
  301. linkItem.appendChild(indicator);
  302. }
  303. let textContent = document.createElement('span');
  304. textContent.className = 'popupmenu__text';
  305. if (data) {
  306. let dataKeys = Object.keys(data);
  307. dataKeys.forEach(key => {
  308. textContent.dataset[key] = data[key];
  309. });
  310. }
  311. linkItem.appendChild(textContent);
  312. linkItem.id = id;
  313. linkItem.onclick = handler;
  314. menuItem.appendChild(linkItem);
  315. return menuItem;
  316. };
  317. /**
  318. * Create a div element with a slider.
  319. *
  320. * @param {object} options - Configuration for the div's display and slider.
  321. * @param {string} options.icon - The classname for the icon to display.
  322. * @param {int} options.maxValue - The maximum value on the slider. The default
  323. * value is 100.
  324. * @param {int} options.initialValue - The value the slider should start at.
  325. * The default value is 0.
  326. * @param {function} options.handler - The callback for slider value changes.
  327. * @returns {Element} A div element with a slider.
  328. */
  329. RemoteVideo.prototype._generatePopupMenuSliderItem = function (options) {
  330. const template = `<div class='popupmenu__contents'>
  331. <span class='popupmenu__icon'>
  332. <i class=${options.icon}></i>
  333. </span>
  334. <div class='popupmenu__slider_container'>
  335. <input class='popupmenu__slider'
  336. type='range'
  337. min='0'
  338. max=${options.maxValue || 100}
  339. value=${options.initialValue || 0}>
  340. </input>
  341. </div>
  342. </div>`;
  343. const menuItem = document.createElement('li');
  344. menuItem.className = 'popupmenu__item';
  345. menuItem.innerHTML = template;
  346. const slider = menuItem.getElementsByClassName('popupmenu__slider')[0];
  347. slider.oninput = function () {
  348. options.handler(Number(slider.value));
  349. };
  350. return menuItem;
  351. };
  352. /**
  353. * Get the remote participant's audio element.
  354. *
  355. * @returns {Element} audio element
  356. */
  357. RemoteVideo.prototype._getAudioElement = function () {
  358. return this._audioStreamElement;
  359. };
  360. /**
  361. * Check if the remote participant's audio can have its volume adjusted.
  362. *
  363. * @returns {boolean} true if the volume can be adjusted.
  364. */
  365. RemoteVideo.prototype._canSetAudioVolume = function () {
  366. const audioElement = this._getAudioElement();
  367. return audioElement && audioElement.volume !== undefined;
  368. };
  369. /**
  370. * Change the remote participant's volume level.
  371. *
  372. * @param {int} scale - The maximum value the slider can go to.
  373. * @param {int} newVal - The value to set the slider to.
  374. */
  375. RemoteVideo.prototype._setAudioVolume = function (scale, newVal) {
  376. if (this._canSetAudioVolume()) {
  377. this._getAudioElement().volume = newVal / scale;
  378. }
  379. };
  380. /**
  381. * Updates the remote video menu.
  382. *
  383. * @param isMuted the new muted state to update to
  384. * @param force to work even if popover is not visible
  385. */
  386. RemoteVideo.prototype.updateRemoteVideoMenu = function (isMuted, force) {
  387. this.isAudioMuted = isMuted;
  388. // generate content, translate it and add it to document only if
  389. // popover is visible or we force to do so.
  390. if(this.popover.popoverShown || force) {
  391. this.popover.updateContent(this._generatePopupContent());
  392. }
  393. };
  394. /**
  395. * @inheritDoc
  396. */
  397. RemoteVideo.prototype.setMutedView = function(isMuted) {
  398. SmallVideo.prototype.setMutedView.call(this, isMuted);
  399. // Update 'mutedWhileDisconnected' flag
  400. this._figureOutMutedWhileDisconnected(this.isConnectionInterrupted());
  401. };
  402. /**
  403. * Figures out the value of {@link #mutedWhileDisconnected} flag by taking into
  404. * account remote participant's network connectivity and video muted status.
  405. *
  406. * @param {boolean} isDisconnected <tt>true</tt> if the remote participant is
  407. * currently having connectivity issues or <tt>false</tt> otherwise.
  408. *
  409. * @private
  410. */
  411. RemoteVideo.prototype._figureOutMutedWhileDisconnected
  412. = function(isDisconnected) {
  413. if (isDisconnected && this.isVideoMuted) {
  414. this.mutedWhileDisconnected = true;
  415. } else if (!isDisconnected && !this.isVideoMuted) {
  416. this.mutedWhileDisconnected = false;
  417. }
  418. };
  419. /**
  420. * Adds the remote video menu element for the given <tt>id</tt> in the
  421. * given <tt>parentElement</tt>.
  422. *
  423. * @param id the id indicating the video for which we're adding a menu.
  424. * @param parentElement the parent element where this menu will be added
  425. */
  426. RemoteVideo.prototype.addRemoteVideoMenu = function () {
  427. if (interfaceConfig.filmStripOnly) {
  428. return;
  429. }
  430. var spanElement = document.createElement('span');
  431. spanElement.className = 'remotevideomenu';
  432. this.container.appendChild(spanElement);
  433. var menuElement = document.createElement('i');
  434. menuElement.className = 'icon-menu-up';
  435. menuElement.title = 'Remote user controls';
  436. spanElement.appendChild(menuElement);
  437. this._initPopupMenu(this._generatePopupContent());
  438. this.hasRemoteVideoMenu = true;
  439. };
  440. /**
  441. * Removes the remote stream element corresponding to the given stream and
  442. * parent container.
  443. *
  444. * @param stream the MediaStream
  445. * @param isVideo <tt>true</tt> if given <tt>stream</tt> is a video one.
  446. */
  447. RemoteVideo.prototype.removeRemoteStreamElement = function (stream) {
  448. if (!this.container)
  449. return false;
  450. var isVideo = stream.isVideoTrack();
  451. var elementID = SmallVideo.getStreamElementID(stream);
  452. var select = $('#' + elementID);
  453. select.remove();
  454. if (isVideo) {
  455. this.wasVideoPlayed = false;
  456. }
  457. logger.info((isVideo ? "Video" : "Audio") +
  458. " removed " + this.id, select);
  459. // when removing only the video element and we are on stage
  460. // update the stage
  461. if (isVideo && this.isCurrentlyOnLargeVideo())
  462. this.VideoLayout.updateLargeVideo(this.id);
  463. else
  464. // Missing video stream will affect display mode
  465. this.updateView();
  466. };
  467. /**
  468. * Checks whether the remote user associated with this <tt>RemoteVideo</tt>
  469. * has connectivity issues.
  470. *
  471. * @return {boolean} <tt>true</tt> if the user's connection is fine or
  472. * <tt>false</tt> otherwise.
  473. */
  474. RemoteVideo.prototype.isConnectionActive = function() {
  475. return this.user.getConnectionStatus()
  476. === ParticipantConnectionStatus.ACTIVE;
  477. };
  478. /**
  479. * The remote video is considered "playable" once the stream has started
  480. * according to the {@link #hasVideoStarted} result.
  481. *
  482. * @inheritdoc
  483. * @override
  484. */
  485. RemoteVideo.prototype.isVideoPlayable = function () {
  486. return SmallVideo.prototype.isVideoPlayable.call(this)
  487. && this.hasVideoStarted() && !this.mutedWhileDisconnected;
  488. };
  489. /**
  490. * @inheritDoc
  491. */
  492. RemoteVideo.prototype.updateView = function () {
  493. $(this.container).toggleClass('audio-only', APP.conference.isAudioOnly());
  494. this.updateConnectionStatusIndicator();
  495. // This must be called after 'updateConnectionStatusIndicator' because it
  496. // affects the display mode by modifying 'mutedWhileDisconnected' flag
  497. SmallVideo.prototype.updateView.call(this);
  498. };
  499. /**
  500. * Updates the UI to reflect user's connectivity status.
  501. */
  502. RemoteVideo.prototype.updateConnectionStatusIndicator = function () {
  503. const isActive = this.isConnectionActive();
  504. if (isActive === null) {
  505. // Cancel processing at this point - no update
  506. return;
  507. }
  508. logger.debug(this.id + " thumbnail is connection active ? " + isActive);
  509. // Update 'mutedWhileDisconnected' flag
  510. this._figureOutMutedWhileDisconnected(!isActive);
  511. if(this.connectionIndicator)
  512. this.connectionIndicator.updateConnectionStatusIndicator(isActive);
  513. // Toggle thumbnail video problem filter
  514. this.selectVideoElement().toggleClass(
  515. "videoThumbnailProblemFilter", !isActive);
  516. this.$avatar().toggleClass(
  517. "videoThumbnailProblemFilter", !isActive);
  518. };
  519. /**
  520. * Removes RemoteVideo from the page.
  521. */
  522. RemoteVideo.prototype.remove = function () {
  523. logger.log("Remove thumbnail", this.id);
  524. this.removeConnectionIndicator();
  525. // Make sure that the large video is updated if are removing its
  526. // corresponding small video.
  527. this.VideoLayout.updateAfterThumbRemoved(this.id);
  528. // Remove whole container
  529. if (this.container.parentNode) {
  530. this.container.parentNode.removeChild(this.container);
  531. }
  532. };
  533. RemoteVideo.prototype.waitForPlayback = function (streamElement, stream) {
  534. var webRtcStream = stream.getOriginalStream();
  535. var isVideo = stream.isVideoTrack();
  536. if (!isVideo || webRtcStream.id === 'mixedmslabel') {
  537. return;
  538. }
  539. var self = this;
  540. // Triggers when video playback starts
  541. var onPlayingHandler = function () {
  542. self.wasVideoPlayed = true;
  543. self.VideoLayout.remoteVideoActive(streamElement, self.id);
  544. streamElement.onplaying = null;
  545. // Refresh to show the video
  546. self.updateView();
  547. };
  548. streamElement.onplaying = onPlayingHandler;
  549. };
  550. /**
  551. * Checks whether the video stream has started for this RemoteVideo instance.
  552. *
  553. * @returns {boolean} true if this RemoteVideo has a video stream for which
  554. * the playback has been started.
  555. */
  556. RemoteVideo.prototype.hasVideoStarted = function () {
  557. return this.wasVideoPlayed;
  558. };
  559. RemoteVideo.prototype.addRemoteStreamElement = function (stream) {
  560. if (!this.container) {
  561. return;
  562. }
  563. let isVideo = stream.isVideoTrack();
  564. isVideo ? this.videoStream = stream : this.audioStream = stream;
  565. if (isVideo)
  566. this.setVideoType(stream.videoType);
  567. // Add click handler.
  568. let onClickHandler = (event) => {
  569. let source = event.target || event.srcElement;
  570. // ignore click if it was done in popup menu
  571. if ($(source).parents('.popupmenu').length === 0) {
  572. this.VideoLayout.handleVideoThumbClicked(this.id);
  573. }
  574. // On IE we need to populate this handler on video <object>
  575. // and it does not give event instance as an argument,
  576. // so we check here for methods.
  577. if (event.stopPropagation && event.preventDefault) {
  578. event.stopPropagation();
  579. event.preventDefault();
  580. }
  581. return false;
  582. };
  583. this.container.onclick = onClickHandler;
  584. if(!stream.getOriginalStream())
  585. return;
  586. let streamElement = SmallVideo.createStreamElement(stream);
  587. // Put new stream element always in front
  588. UIUtils.prependChild(this.container, streamElement);
  589. // If we hide element when Temasys plugin is used then
  590. // we'll never receive 'onplay' event and other logic won't work as expected
  591. // NOTE: hiding will not have effect when Temasys plugin is in use, as
  592. // calling attach will show it back
  593. $(streamElement).hide();
  594. // If the container is currently visible
  595. // we attach the stream to the element.
  596. if (!isVideo || (this.container.offsetParent !== null && isVideo)) {
  597. this.waitForPlayback(streamElement, stream);
  598. streamElement = stream.attach(streamElement);
  599. }
  600. $(streamElement).click(onClickHandler);
  601. if (!isVideo) {
  602. this._audioStreamElement = streamElement;
  603. }
  604. };
  605. RemoteVideo.prototype.updateResolution = function (resolution) {
  606. if (this.connectionIndicator) {
  607. this.connectionIndicator.updateResolution(resolution);
  608. }
  609. };
  610. /**
  611. * Updates this video framerate indication.
  612. * @param framerate the value to update
  613. */
  614. RemoteVideo.prototype.updateFramerate = function (framerate) {
  615. if (this.connectionIndicator) {
  616. this.connectionIndicator.updateFramerate(framerate);
  617. }
  618. };
  619. RemoteVideo.prototype.removeConnectionIndicator = function () {
  620. if (this.connectionIndicator)
  621. this.connectionIndicator.remove();
  622. };
  623. RemoteVideo.prototype.hideConnectionIndicator = function () {
  624. if (this.connectionIndicator)
  625. this.connectionIndicator.hide();
  626. };
  627. /**
  628. * Sets the display name for the given video span id.
  629. *
  630. * @param displayName the display name to set
  631. */
  632. RemoteVideo.prototype.setDisplayName = function(displayName) {
  633. if (!this.container) {
  634. logger.warn( "Unable to set displayName - " + this.videoSpanId +
  635. " does not exist");
  636. return;
  637. }
  638. var nameSpan = $('#' + this.videoSpanId + ' .displayname');
  639. // If we already have a display name for this video.
  640. if (nameSpan.length > 0) {
  641. if (displayName && displayName.length > 0) {
  642. var displaynameSpan = $('#' + this.videoSpanId + '_name');
  643. if (displaynameSpan.text() !== displayName)
  644. displaynameSpan.text(displayName);
  645. }
  646. else
  647. $('#' + this.videoSpanId + '_name').text(
  648. interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME);
  649. } else {
  650. nameSpan = document.createElement('span');
  651. nameSpan.className = 'displayname';
  652. $('#' + this.videoSpanId)[0]
  653. .appendChild(nameSpan);
  654. if (displayName && displayName.length > 0) {
  655. $(nameSpan).text(displayName);
  656. } else {
  657. nameSpan.innerHTML = interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME;
  658. }
  659. nameSpan.id = this.videoSpanId + '_name';
  660. }
  661. };
  662. /**
  663. * Removes remote video menu element from video element identified by
  664. * given <tt>videoElementId</tt>.
  665. *
  666. * @param videoElementId the id of local or remote video element.
  667. */
  668. RemoteVideo.prototype.removeRemoteVideoMenu = function() {
  669. var menuSpan = $('#' + this.videoSpanId + '> .remotevideomenu');
  670. if (menuSpan.length) {
  671. this.popover.forceHide();
  672. menuSpan.remove();
  673. this.hasRemoteVideoMenu = false;
  674. }
  675. };
  676. RemoteVideo.createContainer = function (spanId) {
  677. let container = document.createElement('span');
  678. container.id = spanId;
  679. container.className = 'videocontainer';
  680. let wrapper = document.createElement('div');
  681. wrapper.className = 'videocontainer__background';
  682. container.appendChild(wrapper);
  683. let indicatorBar = document.createElement('div');
  684. indicatorBar.className = "videocontainer__toptoolbar";
  685. container.appendChild(indicatorBar);
  686. let toolbar = document.createElement('div');
  687. toolbar.className = "videocontainer__toolbar";
  688. container.appendChild(toolbar);
  689. let overlay = document.createElement('div');
  690. overlay.className = "videocontainer__hoverOverlay";
  691. container.appendChild(overlay);
  692. var remotes = document.getElementById('remoteVideos');
  693. return remotes.appendChild(container);
  694. };
  695. /**
  696. * Shows 2 button dialog for confirmation from the user for muting remote
  697. * participant.
  698. */
  699. RemoteVideo.showMuteParticipantDialog = function () {
  700. return new Promise(resolve => {
  701. APP.UI.messageHandler.openTwoButtonDialog({
  702. titleKey : "dialog.muteParticipantTitle",
  703. msgString: "<div data-i18n='dialog.muteParticipantBody'></div>",
  704. leftButtonKey: "dialog.muteParticipantButton",
  705. dontShowAgain: {
  706. id: "dontShowMuteParticipantDialog",
  707. textKey: "dialog.doNotShowMessageAgain",
  708. checked: true,
  709. buttonValues: [true]
  710. },
  711. submitFunction: () => resolve(MUTED_DIALOG_BUTTON_VALUES.muted),
  712. closeFunction: () => resolve(MUTED_DIALOG_BUTTON_VALUES.cancel)
  713. });
  714. });
  715. };
  716. export default RemoteVideo;