diff --git a/src/views/home/components/Device.vue b/src/views/home/components/Device.vue index 215ce8e..c7577d7 100644 --- a/src/views/home/components/Device.vue +++ b/src/views/home/components/Device.vue @@ -56,6 +56,19 @@ export default defineComponent({ emit('update:value', data.activeDeviceId) } + const handleReverse = () => { + const index = data.deviceList.findIndex((item) => item.deviceId === data.activeDeviceId) + if (data.deviceList.length === 1) { + emit('update:value', data.activeDeviceId) + } else if (index === data.deviceList.length - 1) { + data.activeDeviceId = data.deviceList[index - 1].deviceId + emit('update:value', data.activeDeviceId) + } else { + data.activeDeviceId = data.deviceList[index + 1].deviceId + emit('update:value', data.activeDeviceId) + } + } + onMounted(() => { navigator.mediaDevices.getUserMedia({ audio: true, video: true }) .then(() => { @@ -69,7 +82,8 @@ export default defineComponent({ return { ...toRefs(data), - handleChange + handleChange, + handleReverse } } diff --git a/src/views/home/index.vue b/src/views/home/index.vue index ae97213..7ef32c9 100644 --- a/src/views/home/index.vue +++ b/src/views/home/index.vue @@ -1,7 +1,7 @@