Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

RemoteVideo.js 25KB

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