2016-09-28 21:31:40 +00:00
|
|
|
/* global interfaceConfig */
|
2015-12-11 16:16:07 +00:00
|
|
|
|
2016-09-28 21:31:40 +00:00
|
|
|
import UIUtil from "../util/UIUtil";
|
2015-12-11 16:16:07 +00:00
|
|
|
/**
|
2016-09-28 21:31:40 +00:00
|
|
|
* Responsible for drawing audio levels.
|
2015-12-11 16:16:07 +00:00
|
|
|
*/
|
|
|
|
const AudioLevels = {
|
|
|
|
|
2014-07-21 10:36:11 +00:00
|
|
|
/**
|
2016-09-28 21:31:40 +00:00
|
|
|
* The number of dots per class. We have 2 classes of dots "top" and
|
|
|
|
* "bottom". The total number of dots will be twice the below value.
|
2014-07-21 10:36:11 +00:00
|
|
|
*/
|
2016-09-28 21:31:40 +00:00
|
|
|
_AUDIO_LEVEL_DOTS: 3,
|
2014-07-21 10:36:11 +00:00
|
|
|
|
2016-09-28 21:31:40 +00:00
|
|
|
/**
|
|
|
|
* Creates the audio level indicator span element.
|
|
|
|
*
|
|
|
|
* @return {Element} the document element representing audio levels
|
|
|
|
*/
|
|
|
|
createThumbnailAudioLevelIndicator() {
|
2014-07-21 10:36:11 +00:00
|
|
|
|
2016-09-28 21:31:40 +00:00
|
|
|
let audioSpan = document.createElement('span');
|
|
|
|
audioSpan.className = 'audioindicator';
|
2014-07-21 10:36:11 +00:00
|
|
|
|
2016-09-28 21:31:40 +00:00
|
|
|
for (let i = 0; i < this._AUDIO_LEVEL_DOTS*2; i++) {
|
|
|
|
var audioDot = document.createElement('span');
|
|
|
|
audioDot.className = (i < this._AUDIO_LEVEL_DOTS)
|
|
|
|
? "audiodot-top"
|
|
|
|
: "audiodot-bottom";
|
2014-07-21 10:36:11 +00:00
|
|
|
|
2016-09-28 21:31:40 +00:00
|
|
|
audioSpan.appendChild(audioDot);
|
2014-07-21 10:36:11 +00:00
|
|
|
}
|
2016-09-28 21:31:40 +00:00
|
|
|
return audioSpan;
|
2015-12-11 16:16:07 +00:00
|
|
|
},
|
2014-07-21 10:36:11 +00:00
|
|
|
|
|
|
|
/**
|
2015-12-04 15:25:24 +00:00
|
|
|
* Updates the audio level UI for the given id.
|
2014-07-21 10:36:11 +00:00
|
|
|
*
|
2015-12-04 15:25:24 +00:00
|
|
|
* @param id id of the user for whom we draw the audio level
|
2014-07-21 10:36:11 +00:00
|
|
|
* @param audioLevel the newAudio level to render
|
|
|
|
*/
|
2016-09-28 21:31:40 +00:00
|
|
|
updateThumbnailAudioLevel (id, audioLevel) {
|
|
|
|
let audioSpan = document.getElementById(id)
|
|
|
|
.getElementsByClassName("audioindicator");
|
2014-07-21 10:36:11 +00:00
|
|
|
|
2016-09-28 21:31:40 +00:00
|
|
|
if (audioSpan && audioSpan.length > 0)
|
|
|
|
audioSpan = audioSpan[0];
|
|
|
|
else
|
2014-07-24 14:14:37 +00:00
|
|
|
return;
|
2014-07-21 10:36:11 +00:00
|
|
|
|
2016-09-28 21:31:40 +00:00
|
|
|
let audioTopDots
|
|
|
|
= audioSpan.getElementsByClassName("audiodot-top");
|
|
|
|
let audioBottomDots
|
|
|
|
= audioSpan.getElementsByClassName("audiodot-bottom");
|
|
|
|
|
|
|
|
let coloredDots = Math.round(this._AUDIO_LEVEL_DOTS*audioLevel);
|
|
|
|
let topColoredDots = this._AUDIO_LEVEL_DOTS - coloredDots;
|
|
|
|
|
|
|
|
for (let i = 0; i < audioTopDots.length; i++) {
|
|
|
|
if (i < topColoredDots)
|
|
|
|
audioTopDots[i].style.opacity = 0;
|
|
|
|
else if (i === topColoredDots && topColoredDots > 0)
|
|
|
|
audioTopDots[i].style.opacity = 0.5;
|
|
|
|
else
|
|
|
|
audioTopDots[i].style.opacity = 1;
|
2014-12-10 09:52:40 +00:00
|
|
|
}
|
|
|
|
|
2016-09-28 21:31:40 +00:00
|
|
|
for (let i = 0; i < audioBottomDots.length; i++) {
|
|
|
|
if (i < coloredDots)
|
|
|
|
audioBottomDots[i].style.opacity = 1;
|
|
|
|
else if (i === coloredDots && coloredDots > 0)
|
|
|
|
audioBottomDots[i].style.opacity = 0.5;
|
|
|
|
else
|
|
|
|
audioBottomDots[i].style.opacity = 0;
|
2014-12-10 09:52:40 +00:00
|
|
|
}
|
2015-12-11 16:16:07 +00:00
|
|
|
},
|
2014-12-10 09:52:40 +00:00
|
|
|
|
2016-09-28 21:31:40 +00:00
|
|
|
/**
|
|
|
|
* Updates the audio level of the large video.
|
|
|
|
*
|
|
|
|
* @param audioLevel the new audio level to set.
|
|
|
|
*/
|
|
|
|
updateLargeVideoAudioLevel(elementId, audioLevel) {
|
|
|
|
let element = document.getElementById(elementId);
|
2016-03-03 23:38:40 +00:00
|
|
|
|
2016-09-28 21:31:40 +00:00
|
|
|
if(!UIUtil.isVisible(element))
|
2015-02-11 16:29:20 +00:00
|
|
|
return;
|
2014-12-10 09:52:40 +00:00
|
|
|
|
2016-09-28 21:31:40 +00:00
|
|
|
let level = parseFloat(audioLevel);
|
2014-12-10 09:52:40 +00:00
|
|
|
|
2016-09-28 21:31:40 +00:00
|
|
|
level = isNaN(level) ? 0 : level;
|
2015-12-25 16:55:45 +00:00
|
|
|
|
2016-09-28 21:31:40 +00:00
|
|
|
let shadowElement = element.getElementsByClassName("dynamic-shadow");
|
2016-09-15 02:20:54 +00:00
|
|
|
|
2016-09-28 21:31:40 +00:00
|
|
|
if (shadowElement && shadowElement.length > 0)
|
|
|
|
shadowElement = shadowElement[0];
|
2015-12-25 16:55:45 +00:00
|
|
|
|
2016-09-28 21:31:40 +00:00
|
|
|
shadowElement.style.boxShadow = this._updateLargeVideoShadow(level);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the large video shadow effect.
|
|
|
|
*/
|
|
|
|
_updateLargeVideoShadow (level) {
|
|
|
|
var scale = 2,
|
|
|
|
|
|
|
|
// Internal circle audio level.
|
|
|
|
int = {
|
|
|
|
level: level > 0.15 ? 20 : 0,
|
|
|
|
color: interfaceConfig.AUDIO_LEVEL_PRIMARY_COLOR
|
|
|
|
},
|
|
|
|
|
|
|
|
// External circle audio level.
|
|
|
|
ext = {
|
|
|
|
level: (int.level * scale * level + int.level).toFixed(0),
|
|
|
|
color: interfaceConfig.AUDIO_LEVEL_SECONDARY_COLOR
|
|
|
|
};
|
|
|
|
|
|
|
|
// Internal blur.
|
|
|
|
int.blur = int.level ? 2 : 0;
|
|
|
|
|
|
|
|
// External blur.
|
|
|
|
ext.blur = ext.level ? 6 : 0;
|
|
|
|
|
|
|
|
return [
|
|
|
|
`0 0 ${ int.blur }px ${ int.level }px ${ int.color }`,
|
|
|
|
`0 0 ${ ext.blur }px ${ ext.level }px ${ ext.color }`
|
|
|
|
].join(', ');
|
2015-12-14 12:26:50 +00:00
|
|
|
}
|
2015-12-11 16:16:07 +00:00
|
|
|
};
|
2015-01-07 14:54:03 +00:00
|
|
|
|
2015-12-11 16:16:07 +00:00
|
|
|
export default AudioLevels;
|