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

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