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

RemoteVideo.js 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  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. null /* will obtain the status from 'conference' */);
  490. // This must be called after 'updateConnectionStatusIndicator' because it
  491. // affects the display mode by modifying 'mutedWhileDisconnected' flag
  492. SmallVideo.prototype.updateView.call(this);
  493. };
  494. /**
  495. * Updates the UI to reflect user's connectivity status.
  496. * @param isActive {boolean|null} 'true' if user's connection is active or
  497. * 'false' when the use is having some connectivity issues and a warning
  498. * should be displayed. When 'null' is passed then the current value will be
  499. * obtained from the conference instance.
  500. */
  501. RemoteVideo.prototype.updateConnectionStatusIndicator = function (isActive) {
  502. // Check for initial value if 'isActive' is not defined
  503. if (typeof isActive !== "boolean") {
  504. isActive = this.isConnectionActive();
  505. if (isActive === null) {
  506. // Cancel processing at this point - no update
  507. return;
  508. }
  509. }
  510. logger.debug(this.id + " thumbnail is connection active ? " + isActive);
  511. // Update 'mutedWhileDisconnected' flag
  512. this._figureOutMutedWhileDisconnected(!isActive);
  513. if(this.connectionIndicator)
  514. this.connectionIndicator.updateConnectionStatusIndicator(isActive);
  515. // Toggle thumbnail video problem filter
  516. this.selectVideoElement().toggleClass(
  517. "videoThumbnailProblemFilter", !isActive);
  518. this.$avatar().toggleClass(
  519. "videoThumbnailProblemFilter", !isActive);
  520. };
  521. /**
  522. * Removes RemoteVideo from the page.
  523. */
  524. RemoteVideo.prototype.remove = function () {
  525. logger.log("Remove thumbnail", this.id);
  526. this.removeConnectionIndicator();
  527. // Make sure that the large video is updated if are removing its
  528. // corresponding small video.
  529. this.VideoLayout.updateAfterThumbRemoved(this.id);
  530. // Remove whole container
  531. if (this.container.parentNode) {
  532. this.container.parentNode.removeChild(this.container);
  533. }
  534. };
  535. RemoteVideo.prototype.waitForPlayback = function (streamElement, stream) {
  536. var webRtcStream = stream.getOriginalStream();
  537. var isVideo = stream.isVideoTrack();
  538. if (!isVideo || webRtcStream.id === 'mixedmslabel') {
  539. return;
  540. }
  541. var self = this;
  542. // Triggers when video playback starts
  543. var onPlayingHandler = function () {
  544. self.wasVideoPlayed = true;
  545. self.VideoLayout.remoteVideoActive(streamElement, self.id);
  546. streamElement.onplaying = null;
  547. // Refresh to show the video
  548. self.updateView();
  549. };
  550. streamElement.onplaying = onPlayingHandler;
  551. };
  552. /**
  553. * Checks whether the video stream has started for this RemoteVideo instance.
  554. *
  555. * @returns {boolean} true if this RemoteVideo has a video stream for which
  556. * the playback has been started.
  557. */
  558. RemoteVideo.prototype.hasVideoStarted = function () {
  559. return this.wasVideoPlayed;
  560. };
  561. RemoteVideo.prototype.addRemoteStreamElement = function (stream) {
  562. if (!this.container) {
  563. return;
  564. }
  565. let isVideo = stream.isVideoTrack();
  566. isVideo ? this.videoStream = stream : this.audioStream = stream;
  567. if (isVideo)
  568. this.setVideoType(stream.videoType);
  569. // Add click handler.
  570. let onClickHandler = (event) => {
  571. let source = event.target || event.srcElement;
  572. // ignore click if it was done in popup menu
  573. if ($(source).parents('.popupmenu').length === 0) {
  574. this.VideoLayout.handleVideoThumbClicked(this.id);
  575. }
  576. // On IE we need to populate this handler on video <object>
  577. // and it does not give event instance as an argument,
  578. // so we check here for methods.
  579. if (event.stopPropagation && event.preventDefault) {
  580. event.stopPropagation();
  581. event.preventDefault();
  582. }
  583. return false;
  584. };
  585. this.container.onclick = onClickHandler;
  586. if(!stream.getOriginalStream())
  587. return;
  588. let streamElement = SmallVideo.createStreamElement(stream);
  589. // Put new stream element always in front
  590. UIUtils.prependChild(this.container, streamElement);
  591. // If we hide element when Temasys plugin is used then
  592. // we'll never receive 'onplay' event and other logic won't work as expected
  593. // NOTE: hiding will not have effect when Temasys plugin is in use, as
  594. // calling attach will show it back
  595. $(streamElement).hide();
  596. // If the container is currently visible
  597. // we attach the stream to the element.
  598. if (!isVideo || (this.container.offsetParent !== null && isVideo)) {
  599. this.waitForPlayback(streamElement, stream);
  600. streamElement = stream.attach(streamElement);
  601. }
  602. $(streamElement).click(onClickHandler);
  603. if (!isVideo) {
  604. this._audioStreamElement = streamElement;
  605. }
  606. };
  607. /**
  608. * Show/hide peer container for the given id.
  609. */
  610. RemoteVideo.prototype.showPeerContainer = function (state) {
  611. if (!this.container)
  612. return;
  613. var isHide = state === 'hide';
  614. var resizeThumbnails = false;
  615. if (!isHide) {
  616. if (!$(this.container).is(':visible')) {
  617. resizeThumbnails = true;
  618. $(this.container).show();
  619. }
  620. // Call updateView, so that we'll figure out if avatar
  621. // should be displayed based on video muted status and whether or not
  622. // it's in the lastN set
  623. this.updateView();
  624. }
  625. else if ($(this.container).is(':visible') && isHide)
  626. {
  627. resizeThumbnails = true;
  628. $(this.container).hide();
  629. if(this.connectionIndicator)
  630. this.connectionIndicator.hide();
  631. }
  632. if (resizeThumbnails) {
  633. this.VideoLayout.resizeThumbnails();
  634. }
  635. // We want to be able to pin a participant from the contact list, even
  636. // if he's not in the lastN set!
  637. // ContactList.setClickable(id, !isHide);
  638. };
  639. RemoteVideo.prototype.updateResolution = function (resolution) {
  640. if (this.connectionIndicator) {
  641. this.connectionIndicator.updateResolution(resolution);
  642. }
  643. };
  644. RemoteVideo.prototype.removeConnectionIndicator = function () {
  645. if (this.connectionIndicator)
  646. this.connectionIndicator.remove();
  647. };
  648. RemoteVideo.prototype.hideConnectionIndicator = function () {
  649. if (this.connectionIndicator)
  650. this.connectionIndicator.hide();
  651. };
  652. /**
  653. * Sets the display name for the given video span id.
  654. *
  655. * @param displayName the display name to set
  656. */
  657. RemoteVideo.prototype.setDisplayName = function(displayName) {
  658. if (!this.container) {
  659. logger.warn( "Unable to set displayName - " + this.videoSpanId +
  660. " does not exist");
  661. return;
  662. }
  663. var nameSpan = $('#' + this.videoSpanId + ' .displayname');
  664. // If we already have a display name for this video.
  665. if (nameSpan.length > 0) {
  666. if (displayName && displayName.length > 0) {
  667. var displaynameSpan = $('#' + this.videoSpanId + '_name');
  668. if (displaynameSpan.text() !== displayName)
  669. displaynameSpan.text(displayName);
  670. }
  671. else
  672. $('#' + this.videoSpanId + '_name').text(
  673. interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME);
  674. } else {
  675. nameSpan = document.createElement('span');
  676. nameSpan.className = 'displayname';
  677. $('#' + this.videoSpanId)[0]
  678. .appendChild(nameSpan);
  679. if (displayName && displayName.length > 0) {
  680. $(nameSpan).text(displayName);
  681. } else {
  682. nameSpan.innerHTML = interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME;
  683. }
  684. nameSpan.id = this.videoSpanId + '_name';
  685. }
  686. };
  687. /**
  688. * Removes remote video menu element from video element identified by
  689. * given <tt>videoElementId</tt>.
  690. *
  691. * @param videoElementId the id of local or remote video element.
  692. */
  693. RemoteVideo.prototype.removeRemoteVideoMenu = function() {
  694. var menuSpan = $('#' + this.videoSpanId + '> .remotevideomenu');
  695. if (menuSpan.length) {
  696. this.popover.forceHide();
  697. menuSpan.remove();
  698. this.hasRemoteVideoMenu = false;
  699. }
  700. };
  701. RemoteVideo.createContainer = function (spanId) {
  702. let container = document.createElement('span');
  703. container.id = spanId;
  704. container.className = 'videocontainer';
  705. let wrapper = document.createElement('div');
  706. wrapper.className = 'videocontainer__background';
  707. container.appendChild(wrapper);
  708. let indicatorBar = document.createElement('div');
  709. indicatorBar.className = "videocontainer__toptoolbar";
  710. container.appendChild(indicatorBar);
  711. let toolbar = document.createElement('div');
  712. toolbar.className = "videocontainer__toolbar";
  713. container.appendChild(toolbar);
  714. let overlay = document.createElement('div');
  715. overlay.className = "videocontainer__hoverOverlay";
  716. container.appendChild(overlay);
  717. var remotes = document.getElementById('remoteVideos');
  718. return remotes.appendChild(container);
  719. };
  720. /**
  721. * Shows 2 button dialog for confirmation from the user for muting remote
  722. * participant.
  723. */
  724. RemoteVideo.showMuteParticipantDialog = function () {
  725. return new Promise(resolve => {
  726. APP.UI.messageHandler.openTwoButtonDialog({
  727. titleKey : "dialog.muteParticipantTitle",
  728. msgString: "<div data-i18n='dialog.muteParticipantBody'></div>",
  729. leftButtonKey: "dialog.muteParticipantButton",
  730. dontShowAgain: {
  731. id: "dontShowMuteParticipantDialog",
  732. textKey: "dialog.doNotShowMessageAgain",
  733. checked: true,
  734. buttonValues: [true]
  735. },
  736. submitFunction: () => resolve(MUTED_DIALOG_BUTTON_VALUES.muted),
  737. closeFunction: () => resolve(MUTED_DIALOG_BUTTON_VALUES.cancel)
  738. });
  739. });
  740. };
  741. export default RemoteVideo;