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.

AudioLevels.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* global interfaceConfig */
  2. import UIUtil from '../util/UIUtil';
  3. /**
  4. * Responsible for drawing audio levels.
  5. */
  6. const AudioLevels = {
  7. /**
  8. * Fills the dot(s) with the specified "index", with as much opacity as
  9. * indicated by "opacity".
  10. *
  11. * @param {string} elementID the parent audio indicator span element
  12. * @param {number} index the index of the dots to fill, where 0 indicates
  13. * the middle dot and the following increments point toward the
  14. * corresponding pair of dots.
  15. * @param {number} opacity the opacity to set for the specified dot.
  16. */
  17. _setDotLevel(elementID, index, opacity) {
  18. let audioSpan
  19. = document.getElementById(elementID)
  20. .getElementsByClassName('audioindicator');
  21. // Make sure the audio span is still around.
  22. if (audioSpan && audioSpan.length > 0) {
  23. audioSpan = audioSpan[0];
  24. } else {
  25. return;
  26. }
  27. const audioTopDots
  28. = audioSpan.getElementsByClassName('audiodot-top');
  29. const audioDotMiddle
  30. = audioSpan.getElementsByClassName('audiodot-middle');
  31. const audioBottomDots
  32. = audioSpan.getElementsByClassName('audiodot-bottom');
  33. // First take care of the middle dot case.
  34. if (index === 0) {
  35. audioDotMiddle[0].style.opacity = opacity;
  36. return;
  37. }
  38. // Index > 0 : we are setting non-middle dots.
  39. index--;// eslint-disable-line no-param-reassign
  40. audioBottomDots[index].style.opacity = opacity;
  41. audioTopDots[this.sideDotsCount - index - 1].style.opacity = opacity;
  42. },
  43. /**
  44. * Updates the audio level of the large video.
  45. *
  46. * @param audioLevel the new audio level to set.
  47. */
  48. updateLargeVideoAudioLevel(elementId, audioLevel) {
  49. const element = document.getElementById(elementId);
  50. if (!UIUtil.isVisible(element)) {
  51. return;
  52. }
  53. let level = parseFloat(audioLevel);
  54. level = isNaN(level) ? 0 : level;
  55. let shadowElement = element.getElementsByClassName('dynamic-shadow');
  56. if (shadowElement && shadowElement.length > 0) {
  57. shadowElement = shadowElement[0];
  58. }
  59. shadowElement.style.boxShadow = this._updateLargeVideoShadow(level);
  60. },
  61. /**
  62. * Updates the large video shadow effect.
  63. */
  64. _updateLargeVideoShadow(level) {
  65. const scale = 2;
  66. // Internal circle audio level.
  67. const int = {
  68. level: level > 0.15 ? 20 : 0,
  69. color: interfaceConfig.AUDIO_LEVEL_PRIMARY_COLOR
  70. };
  71. // External circle audio level.
  72. const ext = {
  73. level: ((int.level * scale * level) + int.level).toFixed(0),
  74. color: interfaceConfig.AUDIO_LEVEL_SECONDARY_COLOR
  75. };
  76. // Internal blur.
  77. int.blur = int.level ? 2 : 0;
  78. // External blur.
  79. ext.blur = ext.level ? 6 : 0;
  80. return [
  81. `0 0 ${int.blur}px ${int.level}px ${int.color}`,
  82. `0 0 ${ext.blur}px ${ext.level}px ${ext.color}`
  83. ].join(', ');
  84. }
  85. };
  86. export default AudioLevels;