You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RemoteVideo.js 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  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. position: interfaceConfig.VERTICAL_FILMSTRIP ? 'left' : 'top'
  84. };
  85. let element = $("#" + this.videoSpanId + " .remotevideomenu");
  86. this.popover = new JitsiPopover(element, options);
  87. this.popover.addOnHoverPopover(isHovered => {
  88. this.popupMenuIsHovered = isHovered;
  89. this.updateView();
  90. });
  91. // override popover show method to make sure we will update the content
  92. // before showing the popover
  93. let origShowFunc = this.popover.show;
  94. this.popover.show = function () {
  95. // update content by forcing it, to finish even if popover
  96. // is not visible
  97. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  98. // call the original show, passing its actual this
  99. origShowFunc.call(this.popover);
  100. }.bind(this);
  101. };
  102. /**
  103. * Checks whether current video is considered hovered. Currently it is hovered
  104. * if the mouse is over the video, or if the connection indicator or the popup
  105. * menu is shown(hovered).
  106. * @private
  107. * NOTE: extends SmallVideo's method
  108. */
  109. RemoteVideo.prototype._isHovered = function () {
  110. let isHovered = SmallVideo.prototype._isHovered.call(this)
  111. || this.popupMenuIsHovered;
  112. return isHovered;
  113. };
  114. /**
  115. * Generates the popup menu content.
  116. *
  117. * @returns {Element|*} the constructed element, containing popup menu items
  118. * @private
  119. */
  120. RemoteVideo.prototype._generatePopupContent = function () {
  121. let popupmenuElement = document.createElement('ul');
  122. popupmenuElement.className = 'popupmenu';
  123. popupmenuElement.id = `remote_popupmenu_${this.id}`;
  124. let menuItems = [];
  125. if(APP.conference.isModerator) {
  126. let muteTranslationKey;
  127. let muteClassName;
  128. if (this.isAudioMuted) {
  129. muteTranslationKey = 'videothumbnail.muted';
  130. muteClassName = 'mutelink disabled';
  131. } else {
  132. muteTranslationKey = 'videothumbnail.domute';
  133. muteClassName = 'mutelink';
  134. }
  135. let muteHandler = this._muteHandler.bind(this);
  136. let kickHandler = this._kickHandler.bind(this);
  137. menuItems = [
  138. {
  139. id: 'mutelink_' + this.id,
  140. handler: muteHandler,
  141. icon: 'icon-mic-disabled',
  142. className: muteClassName,
  143. data: {
  144. i18n: muteTranslationKey
  145. }
  146. }, {
  147. id: 'ejectlink_' + this.id,
  148. handler: kickHandler,
  149. icon: 'icon-kick',
  150. data: {
  151. i18n: 'videothumbnail.kick'
  152. }
  153. }
  154. ];
  155. }
  156. if(this._supportsRemoteControl) {
  157. let icon, handler, className;
  158. if(APP.remoteControl.controller.getRequestedParticipant()
  159. === this.id) {
  160. handler = () => {};
  161. className = "requestRemoteControlLink disabled";
  162. icon = "remote-control-spinner fa fa-spinner fa-spin";
  163. } else if(!APP.remoteControl.controller.isStarted()) {
  164. handler = this._requestRemoteControlPermissions.bind(this);
  165. icon = "fa fa-play";
  166. className = "requestRemoteControlLink";
  167. } else {
  168. handler = this._stopRemoteControl.bind(this);
  169. icon = "fa fa-stop";
  170. className = "requestRemoteControlLink";
  171. }
  172. menuItems.push({
  173. id: 'remoteControl_' + this.id,
  174. handler,
  175. icon,
  176. className,
  177. data: {
  178. i18n: 'videothumbnail.remoteControl'
  179. }
  180. });
  181. }
  182. menuItems.forEach(el => {
  183. let menuItem = this._generatePopupMenuItem(el);
  184. popupmenuElement.appendChild(menuItem);
  185. });
  186. // feature check for volume setting as temasys objects cannot adjust volume
  187. if (this._canSetAudioVolume()) {
  188. const volumeScale = 100;
  189. const volumeSlider = this._generatePopupMenuSliderItem({
  190. handler: this._setAudioVolume.bind(this, volumeScale),
  191. icon: 'icon-volume',
  192. initialValue: this._getAudioElement().volume * volumeScale,
  193. maxValue: volumeScale
  194. });
  195. popupmenuElement.appendChild(volumeSlider);
  196. }
  197. APP.translation.translateElement($(popupmenuElement));
  198. return popupmenuElement;
  199. };
  200. /**
  201. * Sets the remote control supported value and initializes or updates the menu
  202. * depending on the remote control is supported or not.
  203. * @param {boolean} isSupported
  204. */
  205. RemoteVideo.prototype.setRemoteControlSupport = function(isSupported = false) {
  206. if(this._supportsRemoteControl === isSupported) {
  207. return;
  208. }
  209. this._supportsRemoteControl = isSupported;
  210. if(!isSupported) {
  211. return;
  212. }
  213. if(!this.hasRemoteVideoMenu) {
  214. //create menu
  215. this.addRemoteVideoMenu();
  216. } else {
  217. //update the content
  218. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  219. }
  220. };
  221. /**
  222. * Requests permissions for remote control session.
  223. */
  224. RemoteVideo.prototype._requestRemoteControlPermissions = function () {
  225. APP.remoteControl.controller.requestPermissions(
  226. this.id, this.VideoLayout.getLargeVideoWrapper()).then(result => {
  227. if(result === null) {
  228. return;
  229. }
  230. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  231. APP.UI.messageHandler.openMessageDialog(
  232. "dialog.remoteControlTitle",
  233. (result === false) ? "dialog.remoteControlDeniedMessage"
  234. : "dialog.remoteControlAllowedMessage",
  235. {user: this.user.getDisplayName()
  236. || interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME}
  237. );
  238. if(result === true) {//the remote control permissions has been granted
  239. // pin the controlled participant
  240. let pinnedId = this.VideoLayout.getPinnedId();
  241. if(pinnedId !== this.id) {
  242. this.VideoLayout.handleVideoThumbClicked(this.id);
  243. }
  244. }
  245. }, error => {
  246. logger.error(error);
  247. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  248. APP.UI.messageHandler.openMessageDialog(
  249. "dialog.remoteControlTitle",
  250. "dialog.remoteControlErrorMessage",
  251. {user: this.user.getDisplayName()
  252. || interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME}
  253. );
  254. });
  255. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  256. };
  257. /**
  258. * Stops remote control session.
  259. */
  260. RemoteVideo.prototype._stopRemoteControl = function () {
  261. // send message about stopping
  262. APP.remoteControl.controller.stop();
  263. this.updateRemoteVideoMenu(this.isAudioMuted, true);
  264. };
  265. RemoteVideo.prototype._muteHandler = function () {
  266. if (this.isAudioMuted)
  267. return;
  268. RemoteVideo.showMuteParticipantDialog().then(reason => {
  269. if(reason === MUTED_DIALOG_BUTTON_VALUES.muted) {
  270. this.emitter.emit(UIEvents.REMOTE_AUDIO_MUTED, this.id);
  271. }
  272. }).catch(e => {
  273. //currently shouldn't be called
  274. logger.error(e);
  275. });
  276. this.popover.forceHide();
  277. };
  278. RemoteVideo.prototype._kickHandler = function () {
  279. this.emitter.emit(UIEvents.USER_KICKED, this.id);
  280. this.popover.forceHide();
  281. };
  282. RemoteVideo.prototype._generatePopupMenuItem = function (opts = {}) {
  283. let {
  284. id,
  285. handler,
  286. icon,
  287. data,
  288. className
  289. } = opts;
  290. handler = handler || $.noop;
  291. let menuItem = document.createElement('li');
  292. menuItem.className = 'popupmenu__item';
  293. let linkItem = document.createElement('a');
  294. linkItem.className = 'popupmenu__link';
  295. if (className) {
  296. linkItem.className += ` ${className}`;
  297. }
  298. if (icon) {
  299. let indicator = document.createElement('span');
  300. indicator.className = 'popupmenu__icon';
  301. indicator.innerHTML = `<i class="${icon}"></i>`;
  302. linkItem.appendChild(indicator);
  303. }
  304. let textContent = document.createElement('span');
  305. textContent.className = 'popupmenu__text';
  306. if (data) {
  307. let dataKeys = Object.keys(data);
  308. dataKeys.forEach(key => {
  309. textContent.dataset[key] = data[key];
  310. });
  311. }
  312. linkItem.appendChild(textContent);
  313. linkItem.id = id;
  314. linkItem.onclick = handler;
  315. menuItem.appendChild(linkItem);
  316. return menuItem;
  317. };
  318. /**
  319. * Create a div element with a slider.
  320. *
  321. * @param {object} options - Configuration for the div's display and slider.
  322. * @param {string} options.icon - The classname for the icon to display.
  323. * @param {int} options.maxValue - The maximum value on the slider. The default
  324. * value is 100.
  325. * @param {int} options.initialValue - The value the slider should start at.
  326. * The default value is 0.
  327. * @param {function} options.handler - The callback for slider value changes.
  328. * @returns {Element} A div element with a slider.
  329. */
  330. RemoteVideo.prototype._generatePopupMenuSliderItem = function (options) {
  331. const template = `<div class='popupmenu__contents'>
  332. <span class='popupmenu__icon'>
  333. <i class=${options.icon}></i>
  334. </span>
  335. <div class='popupmenu__slider_container'>
  336. <input class='popupmenu__slider'
  337. type='range'
  338. min='0'
  339. max=${options.maxValue || 100}
  340. value=${options.initialValue || 0}>
  341. </input>
  342. </div>
  343. </div>`;
  344. const menuItem = document.createElement('li');
  345. menuItem.className = 'popupmenu__item';
  346. menuItem.innerHTML = template;
  347. const slider = menuItem.getElementsByClassName('popupmenu__slider')[0];
  348. slider.oninput = function () {
  349. options.handler(Number(slider.value));
  350. };
  351. return menuItem;
  352. };
  353. /**
  354. * Get the remote participant's audio element.
  355. *
  356. * @returns {Element} audio element
  357. */
  358. RemoteVideo.prototype._getAudioElement = function () {
  359. return this._audioStreamElement;
  360. };
  361. /**
  362. * Check if the remote participant's audio can have its volume adjusted.
  363. *
  364. * @returns {boolean} true if the volume can be adjusted.
  365. */
  366. RemoteVideo.prototype._canSetAudioVolume = function () {
  367. const audioElement = this._getAudioElement();
  368. return audioElement && audioElement.volume !== undefined;
  369. };
  370. /**
  371. * Change the remote participant's volume level.
  372. *
  373. * @param {int} scale - The maximum value the slider can go to.
  374. * @param {int} newVal - The value to set the slider to.
  375. */
  376. RemoteVideo.prototype._setAudioVolume = function (scale, newVal) {
  377. if (this._canSetAudioVolume()) {
  378. this._getAudioElement().volume = newVal / scale;
  379. }
  380. };
  381. /**
  382. * Updates the remote video menu.
  383. *
  384. * @param isMuted the new muted state to update to
  385. * @param force to work even if popover is not visible
  386. */
  387. RemoteVideo.prototype.updateRemoteVideoMenu = function (isMuted, force) {
  388. this.isAudioMuted = isMuted;
  389. // generate content, translate it and add it to document only if
  390. // popover is visible or we force to do so.
  391. if(this.popover.popoverShown || force) {
  392. this.popover.updateContent(this._generatePopupContent());
  393. }
  394. };
  395. /**
  396. * @inheritDoc
  397. * @override
  398. */
  399. RemoteVideo.prototype.setVideoMutedView = function(isMuted) {
  400. SmallVideo.prototype.setVideoMutedView.call(this, isMuted);
  401. // Update 'mutedWhileDisconnected' flag
  402. this._figureOutMutedWhileDisconnected();
  403. };
  404. /**
  405. * Figures out the value of {@link #mutedWhileDisconnected} flag by taking into
  406. * account remote participant's network connectivity and video muted status.
  407. *
  408. * @private
  409. */
  410. RemoteVideo.prototype._figureOutMutedWhileDisconnected = function() {
  411. const isActive = this.isConnectionActive();
  412. if (!isActive && this.isVideoMuted) {
  413. this.mutedWhileDisconnected = true;
  414. } else if (isActive && !this.isVideoMuted) {
  415. this.mutedWhileDisconnected = false;
  416. }
  417. };
  418. /**
  419. * Adds the remote video menu element for the given <tt>id</tt> in the
  420. * given <tt>parentElement</tt>.
  421. *
  422. * @param id the id indicating the video for which we're adding a menu.
  423. * @param parentElement the parent element where this menu will be added
  424. */
  425. RemoteVideo.prototype.addRemoteVideoMenu = function () {
  426. if (interfaceConfig.filmStripOnly) {
  427. return;
  428. }
  429. var spanElement = document.createElement('span');
  430. spanElement.className = 'remotevideomenu';
  431. this.container.appendChild(spanElement);
  432. var menuElement = document.createElement('i');
  433. menuElement.className = 'icon-menu-up';
  434. menuElement.title = 'Remote user controls';
  435. spanElement.appendChild(menuElement);
  436. this._initPopupMenu(this._generatePopupContent());
  437. this.hasRemoteVideoMenu = true;
  438. };
  439. /**
  440. * Removes the remote stream element corresponding to the given stream and
  441. * parent container.
  442. *
  443. * @param stream the MediaStream
  444. * @param isVideo <tt>true</tt> if given <tt>stream</tt> is a video one.
  445. */
  446. RemoteVideo.prototype.removeRemoteStreamElement = function (stream) {
  447. if (!this.container)
  448. return false;
  449. var isVideo = stream.isVideoTrack();
  450. var elementID = SmallVideo.getStreamElementID(stream);
  451. var select = $('#' + elementID);
  452. select.remove();
  453. if (isVideo) {
  454. this.wasVideoPlayed = false;
  455. }
  456. logger.info((isVideo ? "Video" : "Audio") +
  457. " removed " + this.id, select);
  458. // when removing only the video element and we are on stage
  459. // update the stage
  460. if (isVideo && this.isCurrentlyOnLargeVideo())
  461. this.VideoLayout.updateLargeVideo(this.id);
  462. else
  463. // Missing video stream will affect display mode
  464. this.updateView();
  465. };
  466. /**
  467. * Checks whether the remote user associated with this <tt>RemoteVideo</tt>
  468. * has connectivity issues.
  469. *
  470. * @return {boolean} <tt>true</tt> if the user's connection is fine or
  471. * <tt>false</tt> otherwise.
  472. */
  473. RemoteVideo.prototype.isConnectionActive = function() {
  474. return this.user.getConnectionStatus()
  475. === ParticipantConnectionStatus.ACTIVE;
  476. };
  477. /**
  478. * The remote video is considered "playable" once the stream has started
  479. * according to the {@link #hasVideoStarted} result.
  480. *
  481. * @inheritdoc
  482. * @override
  483. */
  484. RemoteVideo.prototype.isVideoPlayable = function () {
  485. return SmallVideo.prototype.isVideoPlayable.call(this)
  486. && this.hasVideoStarted() && !this.mutedWhileDisconnected;
  487. };
  488. /**
  489. * @inheritDoc
  490. */
  491. RemoteVideo.prototype.updateView = function () {
  492. $(this.container).toggleClass('audio-only', APP.conference.isAudioOnly());
  493. this.updateConnectionStatusIndicator();
  494. // This must be called after 'updateConnectionStatusIndicator' because it
  495. // affects the display mode by modifying 'mutedWhileDisconnected' flag
  496. SmallVideo.prototype.updateView.call(this);
  497. };
  498. /**
  499. * Updates the UI to reflect user's connectivity status.
  500. */
  501. RemoteVideo.prototype.updateConnectionStatusIndicator = function () {
  502. const connectionStatus = this.user.getConnectionStatus();
  503. logger.debug(`${this.id} thumbnail connection status: ${connectionStatus}`);
  504. // FIXME rename 'mutedWhileDisconnected' to 'mutedWhileNotRendering'
  505. // Update 'mutedWhileDisconnected' flag
  506. this._figureOutMutedWhileDisconnected();
  507. if(this.connectionIndicator) {
  508. this.connectionIndicator.updateConnectionStatusIndicator(
  509. connectionStatus);
  510. }
  511. const isInterrupted
  512. = connectionStatus === ParticipantConnectionStatus.INTERRUPTED;
  513. // Toggle thumbnail video problem filter
  514. this.selectVideoElement().toggleClass(
  515. "videoThumbnailProblemFilter", isInterrupted);
  516. this.$avatar().toggleClass(
  517. "videoThumbnailProblemFilter", isInterrupted);
  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('filmstripRemoteVideosContainer');
  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;