Browse Source

Fixes audio level algorithm.

master
yanas 8 years ago
parent
commit
b58556b6c3
3 changed files with 82 additions and 38 deletions
  1. 1
    1
      css/_variables.scss
  2. 19
    9
      css/_videolayout_default.scss
  3. 62
    28
      modules/UI/audio_levels/AudioLevels.js

+ 1
- 1
css/_variables.scss View File

47
 $dominantSpeakerBg: #165ecc;
47
 $dominantSpeakerBg: #165ecc;
48
 $raiseHandBg: #D6D61E;
48
 $raiseHandBg: #D6D61E;
49
 $audioLevelBg: #44A5FF;
49
 $audioLevelBg: #44A5FF;
50
-$audioLevelBorder: rgba(14, 56, 121, .5);
50
+$audioLevelShadow: rgba(9, 36, 77, 0.9);
51
 
51
 
52
 $rateStarDefault: #ccc;
52
 $rateStarDefault: #ccc;
53
 $rateStarActivity: #165ecc;
53
 $rateStarActivity: #165ecc;

+ 19
- 9
css/_videolayout_default.scss View File

371
     display: inline-block;
371
     display: inline-block;
372
     left: 6px;
372
     left: 6px;
373
     top: 50%;
373
     top: 50%;
374
-    margin-top: -21px;
374
+    margin-top: -17px;
375
     width: 6px;
375
     width: 6px;
376
-    height: 42px;
376
+    height: 35px;
377
     z-index: 2;
377
     z-index: 2;
378
     border: none;
378
     border: none;
379
 
379
 
380
     .audiodot-top,
380
     .audiodot-top,
381
-    .audiodot-bottom {
381
+    .audiodot-bottom,
382
+    .audiodot-middle {
382
         opacity: 0;
383
         opacity: 0;
383
         display: inline-block;
384
         display: inline-block;
384
-        @include circle(4px);
385
-        background: $audioLevelBg;
385
+        @include circle(5px);
386
+        background: $audioLevelShadow;
386
         margin: 1px 0 1px 0;
387
         margin: 1px 0 1px 0;
387
-        -webkit-filter: blur(0.5px);
388
-        filter: blur(0.5px);
389
-        border: 1px solid rgba(0, 0, 0, .5);
390
         transition: opacity .25s ease-in-out;
388
         transition: opacity .25s ease-in-out;
391
         -moz-transition: opacity .25s ease-in-out;
389
         -moz-transition: opacity .25s ease-in-out;
392
-        z-index: 2;
390
+    }
391
+
392
+    span.audiodot-top::after,
393
+    span.audiodot-bottom::after,
394
+    span.audiodot-middle::after {
395
+        content: "";
396
+        display: inline-block;
397
+        width: 5px;
398
+        height: 5px;
399
+        border-radius: 50%;
400
+        -webkit-filter: blur(0.5px);
401
+        filter: blur(0.5px);
402
+        background: $audioLevelBg;
393
     }
403
     }
394
 }
404
 }
395
 
405
 

+ 62
- 28
modules/UI/audio_levels/AudioLevels.js View File

1
 /* global interfaceConfig */
1
 /* global interfaceConfig */
2
 
2
 
3
 import UIUtil from "../util/UIUtil";
3
 import UIUtil from "../util/UIUtil";
4
+
4
 /**
5
 /**
5
  * Responsible for drawing audio levels.
6
  * Responsible for drawing audio levels.
6
  */
7
  */
7
 const AudioLevels = {
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
      * Creates the audio level indicator span element.
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
      * @return {Element} the document element representing audio levels
23
      * @return {Element} the document element representing audio levels
19
      */
24
      */
20
     createThumbnailAudioLevelIndicator() {
25
     createThumbnailAudioLevelIndicator() {
22
         let audioSpan = document.createElement('span');
27
         let audioSpan = document.createElement('span');
23
         audioSpan.className = 'audioindicator';
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
                                     ? "audiodot-top"
41
                                     ? "audiodot-top"
29
                                     : "audiodot-bottom";
42
                                     : "audiodot-bottom";
30
 
43
 
36
     /**
49
     /**
37
      * Updates the audio level UI for the given id.
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
     updateThumbnailAudioLevel (id, audioLevel) {
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
         if (audioSpan && audioSpan.length > 0)
88
         if (audioSpan && audioSpan.length > 0)
47
             audioSpan = audioSpan[0];
89
             audioSpan = audioSpan[0];
48
         else
90
         else
50
 
92
 
51
         let audioTopDots
93
         let audioTopDots
52
             = audioSpan.getElementsByClassName("audiodot-top");
94
             = audioSpan.getElementsByClassName("audiodot-top");
95
+        let audioDotMiddle
96
+            = audioSpan.getElementsByClassName("audiodot-middle");
53
         let audioBottomDots
97
         let audioBottomDots
54
             = audioSpan.getElementsByClassName("audiodot-bottom");
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
     /**

Loading…
Cancel
Save