1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
<!--
- @copyright Copyright (c) 2020, Daniel Calviño Sánchez (danxuliu@gmail.com)
-
- @license GNU AGPL version 3 or any later version
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-->
<template>
<div class="mediaDevicesPreview">
<MediaDevicesSelector kind="audioinput"
:devices="devices"
:device-id="audioInputId"
@update:deviceId="audioInputId = $event" />
<div class="preview preview-audio">
<div v-if="!audioPreviewAvailable"
class="preview-not-available">
<AlertCircle v-if="audioStreamError"
:size="64"
title=""
fill-color="#999" />
<MicrophoneOff v-else-if="!audioInputId"
:size="64"
title=""
fill-color="#999" />
<div v-else-if="!audioStream"
class="icon icon-loading" />
<p v-if="audioStreamErrorMessage">
{{ audioStreamErrorMessage }}
</p>
</div>
<!-- v-show has to be used instead of v-if/else to ensure that the
reference is always valid once mounted. -->
<div v-show="audioPreviewAvailable"
class="volume-indicator-wrapper">
<Microphone :size="64"
title=""
fill-color="#999" />
<span ref="volumeIndicator"
class="volume-indicator"
:style="{ 'height': currentVolumeIndicatorHeight + 'px' }" />
</div>
</div>
<MediaDevicesSelector kind="videoinput"
:devices="devices"
:device-id="videoInputId"
@update:deviceId="videoInputId = $event" />
<div class="preview preview-video">
<div v-if="!videoPreviewAvailable"
class="preview-not-available">
<AlertCircle v-if="videoStreamError"
:size="64"
title=""
fill-color="#999" />
<VideoOff v-else-if="!videoInputId"
:size="64"
title=""
fill-color="#999" />
<div v-else-if="!videoStream"
class="icon icon-loading" />
<p v-if="videoStreamErrorMessage">
{{ videoStreamErrorMessage }}
</p>
</div>
<!-- v-show has to be used instead of v-if/else to ensure that the
reference is always valid once mounted. -->
<video v-show="videoPreviewAvailable"
ref="video"
disablePictureInPicture="true"
tabindex="-1" />
</div>
</div>
</template>
<script>
import AlertCircle from 'vue-material-design-icons/AlertCircle'
import Microphone from 'vue-material-design-icons/Microphone'
import MicrophoneOff from 'vue-material-design-icons/MicrophoneOff'
import VideoOff from 'vue-material-design-icons/VideoOff'
import MediaDevicesSelector from './MediaDevicesSelector'
import { devices } from '../mixins/devices'
export default {
name: 'MediaDevicesPreview',
components: {
AlertCircle,
MediaDevicesSelector,
Microphone,
MicrophoneOff,
VideoOff,
},
mixins: [devices],
data() {
return {
mounted: false,
currentVolume: -100,
volumeThreshold: -100,
}
},
computed: {
currentVolumeIndicatorHeight() {
// refs can not be accessed on the initial render, only after the
// component has been mounted.
if (!this.mounted) {
return 0
}
// WebRTC volume goes from -100 (silence) to 0 (loudest sound in the
// system); for the volume indicator only sounds above the threshold
// are taken into account.
let currentVolumeProportion = 0
if (this.currentVolume > this.volumeThreshold) {
currentVolumeProportion = (this.volumeThreshold - this.currentVolume) / this.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
},
},
mounted() {
this.mounted = true
},
}
</script>
<style lang="scss" scoped>
.preview {
display: flex;
.icon {
background-size: 64px;
width: 64px;
height: 64px;
opacity: 0.4;
margin-left: auto;
margin-right: auto;
}
}
.preview-not-available p {
margin-bottom: 16px;
}
.preview-audio {
.preview-not-available .icon {
margin-top: 16px;
margin-bottom: 16px;
}
.volume-indicator-wrapper {
/* Make the wrapper the positioning context of the volume indicator. */
position: relative;
margin-top: 16px;
margin-bottom: 16px;
}
.volume-indicator {
position: absolute;
width: 6px;
right: 0;
/* The button height is 64px; the volume indicator button is 56px at
* maximum, but its value will be changed based on the current volume;
* the height change will reveal more or less of the gradient, which has
* absolute dimensions and thus does not change when the height
* changes. */
height: 56px;
bottom: 4px;
background: linear-gradient(0deg, green, yellow, red 54px);
opacity: 0.7;
}
}
.preview-video {
margin-top: 24px;
.preview-not-available .icon {
margin-top: 16px;
margin-bottom: 16px;
}
video {
display: block;
width: 100%;
}
}
</style>
|