Merge pull request #4712 from nextcloud/bugfix/4616/fix-volume-indicator-perf

Fix volume indicator performance
This commit is contained in:
Joas Schilling 2020-12-04 11:05:13 +01:00 коммит произвёл GitHub
Родитель 77b3f810ae ec8f3cf8d4
Коммит f62882568c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 24 добавлений и 8 удалений

Просмотреть файл

@ -34,8 +34,7 @@
@click="toggleAudio" />
<span v-show="model.attributes.audioAvailable"
ref="volumeIndicator"
class="volume-indicator"
:style="{ 'height': currentVolumeIndicatorHeight + 'px' }" />
class="volume-indicator" />
</div>
<button
id="hideVideo"
@ -214,7 +213,7 @@ export default {
return this.model.attributes.audioEnabled ? t('spreed', 'Mute audio') : t('spreed', 'Unmute audio')
},
currentVolumeIndicatorHeight() {
currentVolumeProportion() {
// refs can not be accessed on the initial render, only after the
// component has been mounted.
if (!this.mounted) {
@ -229,11 +228,7 @@ export default {
currentVolumeProportion = (this.model.attributes.volumeThreshold - this.model.attributes.currentVolume) / this.model.attributes.volumeThreshold
}
const volumeIndicatorStyle = window.getComputedStyle ? getComputedStyle(this.$refs.volumeIndicator, null) : this.$refs.volumeIndicator.currentStyle
const maximumVolumeIndicatorHeight = this.$refs.volumeIndicator.parentElement.clientHeight - (parseInt(volumeIndicatorStyle.bottom, 10) * 2)
return maximumVolumeIndicatorHeight * currentVolumeProportion
return currentVolumeProportion
},
videoButtonClass() {
@ -396,6 +391,13 @@ export default {
},
watch: {
currentVolumeProportion: function() {
// The volume meter is updated directly in the DOM as it is
// more efficient than relying on Vue.js to animate the style property,
// because the latter would also process all neighboring components repeatedly.
this.updateVolumeMeter()
},
senderConnectionQualityIsBad: function(senderConnectionQualityIsBad) {
if (!senderConnectionQualityIsBad) {
return
@ -423,6 +425,7 @@ export default {
mounted() {
this.mounted = true
this.updateVolumeMeter()
this.speakingWhileMutedWarner = new SpeakingWhileMutedWarner(this.model, this)
},
@ -432,6 +435,19 @@ export default {
},
methods: {
updateVolumeMeter() {
if (!this.mounted) {
return
}
const volumeIndicatorStyle = window.getComputedStyle ? getComputedStyle(this.$refs.volumeIndicator, null) : this.$refs.volumeIndicator.currentStyle
const maximumVolumeIndicatorHeight = this.$refs.volumeIndicator.parentElement.clientHeight - (parseInt(volumeIndicatorStyle.bottom, 10) * 2)
// round up to avoid property changes
const height = Math.floor(maximumVolumeIndicatorHeight * this.currentVolumeProportion)
this.$refs.volumeIndicator.style.height = height + 'px'
},
/**
* This method executes on spacebar keydown and keyup
*/