Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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