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

RemoteVideo.js 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  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. */
  398. RemoteVideo.prototype.setMutedView = function(isMuted) {
  399. SmallVideo.prototype.setMutedView.call(this, isMuted);
  400. // Update 'mutedWhileDisconnected' flag
  401. this._figureOutMutedWhileDisconnected(this.isConnectionInterrupted());
  402. };
  403. /**
  404. * Figures out the value of {@link #mutedWhileDisconnected} flag by taking into
  405. * account remote participant's network connectivity and video muted status.
  406. *
  407. * @param {boolean} isDisconnected <tt>true</tt> if the remote participant is
  408. * currently having connectivity issues or <tt>false</tt> otherwise.
  409. *
  410. * @private
  411. */
  412. RemoteVideo.prototype._figureOutMutedWhileDisconnected
  413. = function(isDisconnected) {
  414. if (isDisconnected && this.isVideoMuted) {
  415. this.mutedWhileDisconnected = true;
  416. } else if (!isDisconnected && !this.isVideoMuted) {
  417. this.mutedWhileDisconnected = false;
  418. }
  419. };
  420. /**
  421. * Adds the remote video menu element for the given <tt>id</tt> in the
  422. * given <tt>parentElement</tt>.
  423. *
  424. * @param id the id indicating the video for which we're adding a menu.
  425. * @param parentElement the parent element where this menu will be added
  426. */
  427. RemoteVideo.prototype.addRemoteVideoMenu = function () {
  428. if (interfaceConfig.filmStripOnly) {
  429. return;
  430. }
  431. var spanElement = document.createElement('span');
  432. spanElement.className = 'remotevideomenu';
  433. this.container.appendChild(spanElement);
  434. var menuElement = document.createElement('i');
  435. menuElement.className = 'icon-menu-up';
  436. menuElement.title = 'Remote user controls';
  437. spanElement.appendChild(menuElement);
  438. this._initPopupMenu(this._generatePopupContent());
  439. this.hasRemoteVideoMenu = true;
  440. };
  441. /**
  442. * Removes the remote stream element corresponding to the given stream and
  443. * parent container.
  444. *
  445. * @param stream the MediaStream
  446. * @param isVideo <tt>true</tt> if given <tt>stream</tt> is a video one.
  447. */
  448. RemoteVideo.prototype.removeRemoteStreamElement = function (stream) {
  449. if (!this.container)
  450. return false;
  451. var isVideo = stream.isVideoTrack();
  452. var elementID = SmallVideo.getStreamElementID(stream);
  453. var select = $('#' + elementID);
  454. select.remove();
  455. if (isVideo) {
  456. this.wasVideoPlayed = false;
  457. }
  458. logger.info((isVideo ? "Video" : "Audio") +
  459. " removed " + this.id, select);
  460. // when removing only the video element and we are on stage
  461. // update the stage
  462. if (isVideo && this.isCurrentlyOnLargeVideo())
  463. this.VideoLayout.updateLargeVideo(this.id);
  464. else
  465. // Missing video stream will affect display mode
  466. this.updateView();
  467. };
  468. /**
  469. * Checks whether the remote user associated with this <tt>RemoteVideo</tt>
  470. * has connectivity issues.
  471. *
  472. * @return {boolean} <tt>true</tt> if the user's connection is fine or
  473. * <tt>false</tt> otherwise.
  474. */
  475. RemoteVideo.prototype.isConnectionActive = function() {
  476. return this.user.getConnectionStatus()
  477. === ParticipantConnectionStatus.ACTIVE;
  478. };
  479. /**
  480. * The remote video is considered "playable" once the stream has started
  481. * according to the {@link #hasVideoStarted} result.
  482. *
  483. * @inheritdoc
  484. * @override
  485. */
  486. RemoteVideo.prototype.isVideoPlayable = function () {
  487. return SmallVideo.prototype.isVideoPlayable.call(this)
  488. && this.hasVideoStarted() && !this.mutedWhileDisconnected;
  489. };
  490. /**
  491. * @inheritDoc
  492. */
  493. RemoteVideo.prototype.updateView = function () {
  494. $(this.container).toggleClass('audio-only', APP.conference.isAudioOnly());
  495. this.updateConnectionStatusIndicator();
  496. // This must be called after 'updateConnectionStatusIndicator' because it
  497. // affects the display mode by modifying 'mutedWhileDisconnected' flag
  498. SmallVideo.prototype.updateView.call(this);
  499. };
  500. /**
  501. * Updates the UI to reflect user's connectivity status.
  502. */
  503. RemoteVideo.prototype.updateConnectionStatusIndicator = function () {
  504. const isActive = this.isConnectionActive();
  505. if (isActive === null) {
  506. // Cancel processing at this point - no update
  507. return;
  508. }
  509. logger.debug(this.id + " thumbnail is connection active ? " + isActive);
  510. // Update 'mutedWhileDisconnected' flag
  511. this._figureOutMutedWhileDisconnected(!isActive);
  512. if(this.connectionIndicator)
  513. this.connectionIndicator.updateConnectionStatusIndicator(isActive);
  514. // Toggle thumbnail video problem filter
  515. this.selectVideoElement().toggleClass(
  516. "videoThumbnailProblemFilter", !isActive);
  517. this.$avatar().toggleClass(
  518. "videoThumbnailProblemFilter", !isActive);
  519. };
  520. /**
  521. * Removes RemoteVideo from the page.
  522. */
  523. RemoteVideo.prototype.remove = function () {
  524. logger.log("Remove thumbnail", this.id);
  525. this.removeConnectionIndicator();
  526. // Make sure that the large video is updated if are removing its
  527. // corresponding small video.
  528. this.VideoLayout.updateAfterThumbRemoved(this.id);
  529. // Remove whole container
  530. if (this.container.parentNode) {
  531. this.container.parentNode.removeChild(this.container);
  532. }
  533. };
  534. RemoteVideo.prototype.waitForPlayback = function (streamElement, stream) {
  535. var webRtcStream = stream.getOriginalStream();
  536. var isVideo = stream.isVideoTrack();
  537. if (!isVideo || webRtcStream.id === 'mixedmslabel') {
  538. return;
  539. }
  540. var self = this;
  541. // Triggers when video playback starts
  542. var onPlayingHandler = function () {
  543. self.wasVideoPlayed = true;
  544. self.VideoLayout.remoteVideoActive(streamElement, self.id);
  545. streamElement.onplaying = null;
  546. // Refresh to show the video
  547. self.updateView();
  548. };
  549. streamElement.onplaying = onPlayingHandler;
  550. };
  551. /**
  552. * Checks whether the video stream has started for this RemoteVideo instance.
  553. *
  554. * @returns {boolean} true if this RemoteVideo has a video stream for which
  555. * the playback has been started.
  556. */
  557. RemoteVideo.prototype.hasVideoStarted = function () {
  558. return this.wasVideoPlayed;
  559. };
  560. RemoteVideo.prototype.addRemoteStreamElement = function (stream) {
  561. if (!this.container) {
  562. return;
  563. }
  564. let isVideo = stream.isVideoTrack();
  565. isVideo ? this.videoStream = stream : this.audioStream = stream;
  566. if (isVideo)
  567. this.setVideoType(stream.videoType);
  568. // Add click handler.
  569. let onClickHandler = (event) => {
  570. let source = event.target || event.srcElement;
  571. // ignore click if it was done in popup menu
  572. if ($(source).parents('.popupmenu').length === 0) {
  573. this.VideoLayout.handleVideoThumbClicked(this.id);
  574. }
  575. // On IE we need to populate this handler on video <object>
  576. // and it does not give event instance as an argument,
  577. // so we check here for methods.
  578. if (event.stopPropagation && event.preventDefault) {
  579. event.stopPropagation();
  580. event.preventDefault();
  581. }
  582. return false;
  583. };
  584. this.container.onclick = onClickHandler;
  585. if(!stream.getOriginalStream())
  586. return;
  587. let streamElement = SmallVideo.createStreamElement(stream);
  588. // Put new stream element always in front
  589. UIUtils.prependChild(this.container, streamElement);
  590. // If we hide element when Temasys plugin is used then
  591. // we'll never receive 'onplay' event and other logic won't work as expected
  592. // NOTE: hiding will not have effect when Temasys plugin is in use, as
  593. // calling attach will show it back
  594. $(streamElement).hide();
  595. // If the container is currently visible
  596. // we attach the stream to the element.
  597. if (!isVideo || (this.container.offsetParent !== null && isVideo)) {
  598. this.waitForPlayback(streamElement, stream);
  599. streamElement = stream.attach(streamElement);
  600. }
  601. $(streamElement).click(onClickHandler);
  602. if (!isVideo) {
  603. this._audioStreamElement = streamElement;
  604. }
  605. };
  606. RemoteVideo.prototype.updateResolution = function (resolution) {
  607. if (this.connectionIndicator) {
  608. this.connectionIndicator.updateResolution(resolution);
  609. }
  610. };
  611. /**
  612. * Updates this video framerate indication.
  613. * @param framerate the value to update
  614. */
  615. RemoteVideo.prototype.updateFramerate = function (framerate) {
  616. if (this.connectionIndicator) {
  617. this.connectionIndicator.updateFramerate(framerate);
  618. }
  619. };
  620. RemoteVideo.prototype.removeConnectionIndicator = function () {
  621. if (this.connectionIndicator)
  622. this.connectionIndicator.remove();
  623. };
  624. RemoteVideo.prototype.hideConnectionIndicator = function () {
  625. if (this.connectionIndicator)
  626. this.connectionIndicator.hide();
  627. };
  628. /**
  629. * Sets the display name for the given video span id.
  630. *
  631. * @param displayName the display name to set
  632. */
  633. RemoteVideo.prototype.setDisplayName = function(displayName) {
  634. if (!this.container) {
  635. logger.warn( "Unable to set displayName - " + this.videoSpanId +
  636. " does not exist");
  637. return;
  638. }
  639. var nameSpan = $('#' + this.videoSpanId + ' .displayname');
  640. // If we already have a display name for this video.
  641. if (nameSpan.length > 0) {
  642. if (displayName && displayName.length > 0) {
  643. var displaynameSpan = $('#' + this.videoSpanId + '_name');
  644. if (displaynameSpan.text() !== displayName)
  645. displaynameSpan.text(displayName);
  646. }
  647. else
  648. $('#' + this.videoSpanId + '_name').text(
  649. interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME);
  650. } else {
  651. nameSpan = document.createElement('span');
  652. nameSpan.className = 'displayname';
  653. $('#' + this.videoSpanId)[0]
  654. .appendChild(nameSpan);
  655. if (displayName && displayName.length > 0) {
  656. $(nameSpan).text(displayName);
  657. } else {
  658. nameSpan.innerHTML = interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME;
  659. }
  660. nameSpan.id = this.videoSpanId + '_name';
  661. }
  662. };
  663. /**
  664. * Removes remote video menu element from video element identified by
  665. * given <tt>videoElementId</tt>.
  666. *
  667. * @param videoElementId the id of local or remote video element.
  668. */
  669. RemoteVideo.prototype.removeRemoteVideoMenu = function() {
  670. var menuSpan = $('#' + this.videoSpanId + '> .remotevideomenu');
  671. if (menuSpan.length) {
  672. this.popover.forceHide();
  673. menuSpan.remove();
  674. this.hasRemoteVideoMenu = false;
  675. }
  676. };
  677. RemoteVideo.createContainer = function (spanId) {
  678. let container = document.createElement('span');
  679. container.id = spanId;
  680. container.className = 'videocontainer';
  681. let wrapper = document.createElement('div');
  682. wrapper.className = 'videocontainer__background';
  683. container.appendChild(wrapper);
  684. let indicatorBar = document.createElement('div');
  685. indicatorBar.className = "videocontainer__toptoolbar";
  686. container.appendChild(indicatorBar);
  687. let toolbar = document.createElement('div');
  688. toolbar.className = "videocontainer__toolbar";
  689. container.appendChild(toolbar);
  690. let overlay = document.createElement('div');
  691. overlay.className = "videocontainer__hoverOverlay";
  692. container.appendChild(overlay);
  693. var remotes = document.getElementById('filmstripRemoteVideosContainer');
  694. return remotes.appendChild(container);
  695. };
  696. /**
  697. * Shows 2 button dialog for confirmation from the user for muting remote
  698. * participant.
  699. */
  700. RemoteVideo.showMuteParticipantDialog = function () {
  701. return new Promise(resolve => {
  702. APP.UI.messageHandler.openTwoButtonDialog({
  703. titleKey : "dialog.muteParticipantTitle",
  704. msgString: "<div data-i18n='dialog.muteParticipantBody'></div>",
  705. leftButtonKey: "dialog.muteParticipantButton",
  706. dontShowAgain: {
  707. id: "dontShowMuteParticipantDialog",
  708. textKey: "dialog.doNotShowMessageAgain",
  709. checked: true,
  710. buttonValues: [true]
  711. },
  712. submitFunction: () => resolve(MUTED_DIALOG_BUTTON_VALUES.muted),
  713. closeFunction: () => resolve(MUTED_DIALOG_BUTTON_VALUES.cancel)
  714. });
  715. });
  716. };
  717. export default RemoteVideo;