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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 = document.getElementById(elementID)
  19. .getElementsByClassName("audioindicator");
  20. // Make sure the audio span is still around.
  21. if (audioSpan && audioSpan.length > 0)
  22. audioSpan = audioSpan[0];
  23. else
  24. return;
  25. let audioTopDots
  26. = audioSpan.getElementsByClassName("audiodot-top");
  27. let audioDotMiddle
  28. = audioSpan.getElementsByClassName("audiodot-middle");
  29. let audioBottomDots
  30. = audioSpan.getElementsByClassName("audiodot-bottom");
  31. // First take care of the middle dot case.
  32. if (index === 0){
  33. audioDotMiddle[0].style.opacity = opacity;
  34. return;
  35. }
  36. // Index > 0 : we are setting non-middle dots.
  37. index--;
  38. audioBottomDots[index].style.opacity = opacity;
  39. audioTopDots[this.sideDotsCount - index - 1].style.opacity = opacity;
  40. },
  41. /**
  42. * Updates the audio level of the large video.
  43. *
  44. * @param audioLevel the new audio level to set.
  45. */
  46. updateLargeVideoAudioLevel(elementId, audioLevel) {
  47. let element = document.getElementById(elementId);
  48. if(!UIUtil.isVisible(element))
  49. return;
  50. let level = parseFloat(audioLevel);
  51. level = isNaN(level) ? 0 : level;
  52. let shadowElement = element.getElementsByClassName("dynamic-shadow");
  53. if (shadowElement && shadowElement.length > 0)
  54. shadowElement = shadowElement[0];
  55. shadowElement.style.boxShadow = this._updateLargeVideoShadow(level);
  56. },
  57. /**
  58. * Updates the large video shadow effect.
  59. */
  60. _updateLargeVideoShadow (level) {
  61. var scale = 2,
  62. // Internal circle audio level.
  63. int = {
  64. level: level > 0.15 ? 20 : 0,
  65. color: interfaceConfig.AUDIO_LEVEL_PRIMARY_COLOR
  66. },
  67. // External circle audio level.
  68. ext = {
  69. level: (int.level * scale * level + int.level).toFixed(0),
  70. color: interfaceConfig.AUDIO_LEVEL_SECONDARY_COLOR
  71. };
  72. // Internal blur.
  73. int.blur = int.level ? 2 : 0;
  74. // External blur.
  75. ext.blur = ext.level ? 6 : 0;
  76. return [
  77. `0 0 ${ int.blur }px ${ int.level }px ${ int.color }`,
  78. `0 0 ${ ext.blur }px ${ ext.level }px ${ ext.color }`
  79. ].join(', ');
  80. }
  81. };
  82. export default AudioLevels;