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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* global interfaceConfig */
  2. import UIUtil from "../util/UIUtil";
  3. /**
  4. * Responsible for drawing audio levels.
  5. */
  6. const AudioLevels = {
  7. /**
  8. * The number of dots per class. We have 2 classes of dots "top" and
  9. * "bottom". The total number of dots will be twice the below value.
  10. */
  11. _AUDIO_LEVEL_DOTS: 3,
  12. /**
  13. * Creates the audio level indicator span element.
  14. *
  15. * @return {Element} the document element representing audio levels
  16. */
  17. createThumbnailAudioLevelIndicator() {
  18. let audioSpan = document.createElement('span');
  19. audioSpan.className = 'audioindicator';
  20. for (let i = 0; i < this._AUDIO_LEVEL_DOTS*2; i++) {
  21. var audioDot = document.createElement('span');
  22. audioDot.className = (i < this._AUDIO_LEVEL_DOTS)
  23. ? "audiodot-top"
  24. : "audiodot-bottom";
  25. audioSpan.appendChild(audioDot);
  26. }
  27. return audioSpan;
  28. },
  29. /**
  30. * Updates the audio level UI for the given id.
  31. *
  32. * @param id id of the user for whom we draw the audio level
  33. * @param audioLevel the newAudio level to render
  34. */
  35. updateThumbnailAudioLevel (id, audioLevel) {
  36. let audioSpan = document.getElementById(id)
  37. .getElementsByClassName("audioindicator");
  38. if (audioSpan && audioSpan.length > 0)
  39. audioSpan = audioSpan[0];
  40. else
  41. return;
  42. let audioTopDots
  43. = audioSpan.getElementsByClassName("audiodot-top");
  44. let audioBottomDots
  45. = audioSpan.getElementsByClassName("audiodot-bottom");
  46. let coloredDots = Math.round(this._AUDIO_LEVEL_DOTS*audioLevel);
  47. let topColoredDots = this._AUDIO_LEVEL_DOTS - coloredDots;
  48. for (let i = 0; i < audioTopDots.length; i++) {
  49. if (i < topColoredDots)
  50. audioTopDots[i].style.opacity = 0;
  51. else if (i === topColoredDots && topColoredDots > 0)
  52. audioTopDots[i].style.opacity = 0.5;
  53. else
  54. audioTopDots[i].style.opacity = 1;
  55. }
  56. for (let i = 0; i < audioBottomDots.length; i++) {
  57. if (i < coloredDots)
  58. audioBottomDots[i].style.opacity = 1;
  59. else if (i === coloredDots && coloredDots > 0)
  60. audioBottomDots[i].style.opacity = 0.5;
  61. else
  62. audioBottomDots[i].style.opacity = 0;
  63. }
  64. },
  65. /**
  66. * Updates the audio level of the large video.
  67. *
  68. * @param audioLevel the new audio level to set.
  69. */
  70. updateLargeVideoAudioLevel(elementId, audioLevel) {
  71. let element = document.getElementById(elementId);
  72. if(!UIUtil.isVisible(element))
  73. return;
  74. let level = parseFloat(audioLevel);
  75. level = isNaN(level) ? 0 : level;
  76. let shadowElement = element.getElementsByClassName("dynamic-shadow");
  77. if (shadowElement && shadowElement.length > 0)
  78. shadowElement = shadowElement[0];
  79. shadowElement.style.boxShadow = this._updateLargeVideoShadow(level);
  80. },
  81. /**
  82. * Updates the large video shadow effect.
  83. */
  84. _updateLargeVideoShadow (level) {
  85. var scale = 2,
  86. // Internal circle audio level.
  87. int = {
  88. level: level > 0.15 ? 20 : 0,
  89. color: interfaceConfig.AUDIO_LEVEL_PRIMARY_COLOR
  90. },
  91. // External circle audio level.
  92. ext = {
  93. level: (int.level * scale * level + int.level).toFixed(0),
  94. color: interfaceConfig.AUDIO_LEVEL_SECONDARY_COLOR
  95. };
  96. // Internal blur.
  97. int.blur = int.level ? 2 : 0;
  98. // External blur.
  99. ext.blur = ext.level ? 6 : 0;
  100. return [
  101. `0 0 ${ int.blur }px ${ int.level }px ${ int.color }`,
  102. `0 0 ${ ext.blur }px ${ ext.level }px ${ ext.color }`
  103. ].join(', ');
  104. }
  105. };
  106. export default AudioLevels;