Skip to content

Commit

Permalink
feat(media): manually refresh devices list
Browse files Browse the repository at this point in the history
- event listener tracks only change of physical devices (USB-connected)
- allow to get in the list such inputs as bluetooth, mini-jack, virtual devices

Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Apr 10, 2024
1 parent a380416 commit 7b45081
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/components/MediaSettings/MediaDevicesSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,33 @@
:clearable="false"
:placeholder="deviceSelectorPlaceholder"
:disabled="!enabled || !deviceOptionsAvailable" />

<NcButton type="tertiary-no-background"
:title="t('spreed', 'Refresh devices list')"
:aria-lebel="t('spreed', 'Refresh devices list')"
@click="$emit('refresh')">
<RefreshIcon :size="20" />
</NcButton>
</div>
</template>

<script>
import Microphone from 'vue-material-design-icons/Microphone.vue'
import RefreshIcon from 'vue-material-design-icons/Refresh.vue'
import VideoIcon from 'vue-material-design-icons/Video.vue'

import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js'

export default {

name: 'MediaDevicesSelector',

components: {
NcButton,
NcSelect,
Microphone,
RefreshIcon,
VideoIcon,
},

Expand All @@ -77,7 +88,7 @@ export default {
},
},

emits: ['update:deviceId'],
emits: ['refresh', 'update:deviceId'],

data() {
return {
Expand Down
4 changes: 4 additions & 0 deletions src/components/MediaSettings/MediaSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@
<MediaDevicesSelector kind="audioinput"
:devices="devices"
:device-id="audioInputId"
@refresh="updateDevices"
@update:deviceId="audioInputId = $event" />
<MediaDevicesSelector kind="videoinput"
:devices="devices"
:device-id="videoInputId"
@refresh="updateDevices"
@update:deviceId="videoInputId = $event" />
<MediaDevicesSpeakerTest />
</div>
Expand Down Expand Up @@ -282,6 +284,7 @@ export default {

const {
devices,
updateDevices,
currentVolume,
currentThreshold,
audioPreviewAvailable,
Expand All @@ -301,6 +304,7 @@ export default {
video,
// useDevices
devices,
updateDevices,
currentVolume,
currentThreshold,
audioPreviewAvailable,
Expand Down
4 changes: 4 additions & 0 deletions src/components/SettingsDialog/MediaDevicesPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<MediaDevicesSelector kind="audioinput"
:devices="devices"
:device-id="audioInputId"
@refresh="updateDevices"
@update:deviceId="audioInputId = $event" />
<div class="preview preview-audio">
<div v-if="!audioPreviewAvailable"
Expand Down Expand Up @@ -51,6 +52,7 @@
<MediaDevicesSelector kind="videoinput"
:devices="devices"
:device-id="videoInputId"
@refresh="updateDevices"
@update:deviceId="videoInputId = $event" />
<div class="preview preview-video">
<div v-if="!videoPreviewAvailable"
Expand Down Expand Up @@ -107,6 +109,7 @@ export default {
const video = ref(null)
const {
devices,
updateDevices,
currentVolume,
currentThreshold,
audioPreviewAvailable,
Expand All @@ -122,6 +125,7 @@ export default {
return {
video,
devices,
updateDevices,
currentVolume,
currentThreshold,
audioPreviewAvailable,
Expand Down
9 changes: 9 additions & 0 deletions src/composables/useDevices.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ export function useDevices(video, initializeOnMounted) {
updateVideoStream()
}

/**
* Force enumerate devices (audio and video)
* @public
*/
function updateDevices() {
mediaDevicesManager._updateDevices()
}

/**
* Stop tracking device events (audio and video)
* @public
Expand Down Expand Up @@ -369,6 +377,7 @@ export function useDevices(video, initializeOnMounted) {

return {
devices,
updateDevices,
currentVolume,
currentThreshold,
audioPreviewAvailable,
Expand Down

0 comments on commit 7b45081

Please sign in to comment.