-
Notifications
You must be signed in to change notification settings - Fork 532
Expand file tree
/
Copy pathMediaDevicesPreview.vue
More file actions
236 lines (208 loc) · 6.35 KB
/
MediaDevicesPreview.vue
File metadata and controls
236 lines (208 loc) · 6.35 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<!--
- @copyright Copyright (c) 2020 Daniel Calviño Sánchez (danxuliu@gmail.com)
-
- @license AGPL-3.0-or-later
-
- 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>
<VolumeIndicator v-else
:audio-preview-available="audioPreviewAvailable"
:audio-enabled="true"
:current-volume="currentVolume"
:volume-threshold="currentThreshold"
:size="64" />
</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 { ref } from 'vue'
import AlertCircle from 'vue-material-design-icons/AlertCircle.vue'
import MicrophoneOff from 'vue-material-design-icons/MicrophoneOff.vue'
import VideoOff from 'vue-material-design-icons/VideoOff.vue'
import MediaDevicesSelector from '../MediaSettings/MediaDevicesSelector.vue'
import VolumeIndicator from '../UIShared/VolumeIndicator.vue'
import { useDevices } from '../../composables/useDevices.js'
export default {
name: 'MediaDevicesPreview',
components: {
AlertCircle,
MediaDevicesSelector,
MicrophoneOff,
VideoOff,
VolumeIndicator,
},
setup() {
const video = ref(null)
const {
devices,
currentVolume,
currentThreshold,
audioPreviewAvailable,
videoPreviewAvailable,
audioInputId,
videoInputId,
audioStream,
audioStreamError,
videoStream,
videoStreamError,
} = useDevices(video, true)
return {
video,
devices,
currentVolume,
currentThreshold,
audioPreviewAvailable,
videoPreviewAvailable,
audioInputId,
videoInputId,
audioStream,
audioStreamError,
videoStream,
videoStreamError,
}
},
computed: {
audioStreamErrorMessage() {
if (!this.audioStreamError) {
return null
}
if (this.audioStreamError.name === 'NotSupportedError' && !window.RTCPeerConnection) {
return t('spreed', 'Calls are not supported in your browser')
}
// In newer browser versions MediaDevicesManager is not supported in
// insecure contexts; in older browser versions it is, but getting
// the user media fails with "NotAllowedError".
const isInsecureContext = 'isSecureContext' in window && !window.isSecureContext
const isInsecureContextAccordingToErrorMessage = this.audioStreamError.message && this.audioStreamError.message.includes('Only secure origins')
if ((this.audioStreamError.name === 'NotSupportedError' && isInsecureContext)
|| (this.audioStreamError.name === 'NotAllowedError' && isInsecureContextAccordingToErrorMessage)) {
return t('spreed', 'Access to microphone is only possible with HTTPS')
}
if (this.audioStreamError.name === 'NotAllowedError') {
return t('spreed', 'Access to microphone was denied')
}
return t('spreed', 'Error while accessing microphone')
},
videoStreamErrorMessage() {
if (!this.videoStreamError) {
return null
}
if (this.videoStreamError.name === 'NotSupportedError' && !window.RTCPeerConnection) {
return t('spreed', 'Calls are not supported in your browser')
}
// In newer browser versions MediaDevicesManager is not supported in
// insecure contexts; in older browser versions it is, but getting
// the user media fails with "NotAllowedError".
const isInsecureContext = 'isSecureContext' in window && !window.isSecureContext
const isInsecureContextAccordingToErrorMessage = this.videoStreamError.message && this.videoStreamError.message.includes('Only secure origins')
if ((this.videoStreamError.name === 'NotSupportedError' && isInsecureContext)
|| (this.videoStreamError.name === 'NotAllowedError' && isInsecureContextAccordingToErrorMessage)) {
return t('spreed', 'Access to camera is only possible with HTTPS')
}
if (this.videoStreamError.name === 'NotAllowedError') {
return t('spreed', 'Access to camera was denied')
}
return t('spreed', 'Error while accessing camera')
},
}
}
</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 {
margin: 16px auto;
}
}
.preview-video {
margin-top: 24px;
.preview-not-available .icon {
margin-top: 16px;
margin-bottom: 16px;
}
video {
display: block;
width: 100%;
}
}
</style>