|
@@ -1,20 +1,25 @@
|
1
|
1
|
/* global interfaceConfig */
|
2
|
2
|
|
3
|
3
|
import UIUtil from "../util/UIUtil";
|
|
4
|
+
|
4
|
5
|
/**
|
5
|
6
|
* Responsible for drawing audio levels.
|
6
|
7
|
*/
|
7
|
8
|
const AudioLevels = {
|
8
|
9
|
|
9
|
10
|
/**
|
10
|
|
- * The number of dots per class. We have 2 classes of dots "top" and
|
11
|
|
- * "bottom". The total number of dots will be twice the below value.
|
|
11
|
+ * The number of dots.
|
|
12
|
+ *
|
|
13
|
+ * IMPORTANT: functions below assume that this is an odd number.
|
12
|
14
|
*/
|
13
|
|
- _AUDIO_LEVEL_DOTS: 3,
|
|
15
|
+ _AUDIO_LEVEL_DOTS: 5,
|
14
|
16
|
|
15
|
17
|
/**
|
16
|
18
|
* Creates the audio level indicator span element.
|
17
|
19
|
*
|
|
20
|
+ * IMPORTANT: This function assumes that the number of dots is an
|
|
21
|
+ * odd number.
|
|
22
|
+ *
|
18
|
23
|
* @return {Element} the document element representing audio levels
|
19
|
24
|
*/
|
20
|
25
|
createThumbnailAudioLevelIndicator() {
|
|
@@ -22,9 +27,17 @@ const AudioLevels = {
|
22
|
27
|
let audioSpan = document.createElement('span');
|
23
|
28
|
audioSpan.className = 'audioindicator';
|
24
|
29
|
|
25
|
|
- for (let i = 0; i < this._AUDIO_LEVEL_DOTS*2; i++) {
|
26
|
|
- var audioDot = document.createElement('span');
|
27
|
|
- audioDot.className = (i < this._AUDIO_LEVEL_DOTS)
|
|
30
|
+ this.sideDotsCount = Math.floor(this._AUDIO_LEVEL_DOTS/2);
|
|
31
|
+
|
|
32
|
+ for (let i = 0; i < this._AUDIO_LEVEL_DOTS; i++) {
|
|
33
|
+ let audioDot = document.createElement('span');
|
|
34
|
+
|
|
35
|
+ // The median index will be equal to the number of dots on each
|
|
36
|
+ // side.
|
|
37
|
+ if (i === this.sideDotsCount)
|
|
38
|
+ audioDot.className = "audiodot-middle";
|
|
39
|
+ else
|
|
40
|
+ audioDot.className = (i < this.sideDotsCount)
|
28
|
41
|
? "audiodot-top"
|
29
|
42
|
: "audiodot-bottom";
|
30
|
43
|
|
|
@@ -36,13 +49,42 @@ const AudioLevels = {
|
36
|
49
|
/**
|
37
|
50
|
* Updates the audio level UI for the given id.
|
38
|
51
|
*
|
39
|
|
- * @param id id of the user for whom we draw the audio level
|
40
|
|
- * @param audioLevel the newAudio level to render
|
|
52
|
+ * @param {string} id id of the user for whom we draw the audio level
|
|
53
|
+ * @param {number} audioLevel the newAudio level to render
|
41
|
54
|
*/
|
42
|
55
|
updateThumbnailAudioLevel (id, audioLevel) {
|
43
|
|
- let audioSpan = document.getElementById(id)
|
44
|
|
- .getElementsByClassName("audioindicator");
|
45
|
56
|
|
|
57
|
+ // First make sure we are sensitive enough.
|
|
58
|
+ audioLevel *= 1.2;
|
|
59
|
+ audioLevel = Math.min(audioLevel, 1);
|
|
60
|
+
|
|
61
|
+ // Let's now stretch the audio level over the number of dots we have.
|
|
62
|
+ let stretchedAudioLevel = (this.sideDotsCount + 1) * audioLevel;
|
|
63
|
+ let dotLevel = 0.0;
|
|
64
|
+
|
|
65
|
+ for (let i = 0; i < (this.sideDotsCount + 1); i++) {
|
|
66
|
+
|
|
67
|
+ dotLevel = Math.min(1, Math.max(0, (stretchedAudioLevel - i)));
|
|
68
|
+ this._setDotLevel(id, i, dotLevel);
|
|
69
|
+ }
|
|
70
|
+ },
|
|
71
|
+
|
|
72
|
+ /**
|
|
73
|
+ * Fills the dot(s) with the specified "index", with as much opacity as
|
|
74
|
+ * indicated by "opacity".
|
|
75
|
+ *
|
|
76
|
+ * @param {string} elementID the parent audio indicator span element
|
|
77
|
+ * @param {number} index the index of the dots to fill, where 0 indicates
|
|
78
|
+ * the middle dot and the following increments point toward the
|
|
79
|
+ * corresponding pair of dots.
|
|
80
|
+ * @param {number} opacity the opacity to set for the specified dot.
|
|
81
|
+ */
|
|
82
|
+ _setDotLevel(elementID, index, opacity) {
|
|
83
|
+
|
|
84
|
+ let audioSpan = document.getElementById(elementID)
|
|
85
|
+ .getElementsByClassName("audioindicator");
|
|
86
|
+
|
|
87
|
+ // Make sure the audio span is still around.
|
46
|
88
|
if (audioSpan && audioSpan.length > 0)
|
47
|
89
|
audioSpan = audioSpan[0];
|
48
|
90
|
else
|
|
@@ -50,29 +92,21 @@ const AudioLevels = {
|
50
|
92
|
|
51
|
93
|
let audioTopDots
|
52
|
94
|
= audioSpan.getElementsByClassName("audiodot-top");
|
|
95
|
+ let audioDotMiddle
|
|
96
|
+ = audioSpan.getElementsByClassName("audiodot-middle");
|
53
|
97
|
let audioBottomDots
|
54
|
98
|
= audioSpan.getElementsByClassName("audiodot-bottom");
|
55
|
99
|
|
56
|
|
- let coloredDots = Math.round(this._AUDIO_LEVEL_DOTS*audioLevel);
|
57
|
|
- let topColoredDots = this._AUDIO_LEVEL_DOTS - coloredDots;
|
58
|
|
-
|
59
|
|
- for (let i = 0; i < audioTopDots.length; i++) {
|
60
|
|
- if (i < topColoredDots)
|
61
|
|
- audioTopDots[i].style.opacity = 0;
|
62
|
|
- else if (i === topColoredDots && topColoredDots > 0)
|
63
|
|
- audioTopDots[i].style.opacity = 0.5;
|
64
|
|
- else
|
65
|
|
- audioTopDots[i].style.opacity = 1;
|
|
100
|
+ // First take care of the middle dot case.
|
|
101
|
+ if (index === 0){
|
|
102
|
+ audioDotMiddle[0].style.opacity = opacity;
|
|
103
|
+ return;
|
66
|
104
|
}
|
67
|
105
|
|
68
|
|
- for (let i = 0; i < audioBottomDots.length; i++) {
|
69
|
|
- if (i < coloredDots)
|
70
|
|
- audioBottomDots[i].style.opacity = 1;
|
71
|
|
- else if (i === coloredDots && coloredDots > 0)
|
72
|
|
- audioBottomDots[i].style.opacity = 0.5;
|
73
|
|
- else
|
74
|
|
- audioBottomDots[i].style.opacity = 0;
|
75
|
|
- }
|
|
106
|
+ // Index > 0 : we are setting non-middle dots.
|
|
107
|
+ index--;
|
|
108
|
+ audioBottomDots[index].style.opacity = opacity;
|
|
109
|
+ audioTopDots[this.sideDotsCount - index - 1].style.opacity = opacity;
|
76
|
110
|
},
|
77
|
111
|
|
78
|
112
|
/**
|