change device

This commit is contained in:
zhangtao 2022-10-28 10:16:26 +08:00
parent c3d3e737b7
commit ac94990547
2 changed files with 9 additions and 6 deletions

View File

@ -10,7 +10,7 @@ export default defineComponent({
props: { props: {
}, },
emits: ['init'], emits: ['init', 'switch'],
setup(props, { emit }) { setup(props, { emit }) {
const data = reactive({ const data = reactive({
videoList: [], videoList: [],
@ -30,10 +30,11 @@ export default defineComponent({
}) })
} }
const handleReverse = () => { const handleCameraReverse = () => {
const index = data.videoList.findIndex((item) => item.deviceId === data.videoDeviceId) const index = data.videoList.findIndex((item) => item.deviceId === data.videoDeviceId)
const len = data.videoList.length const len = data.videoList.length
if (len === 1) { alert(len)
if (len <= 1) {
return return
} else if (index === 0) { } else if (index === 0) {
data.videoDeviceId = data.videoList[len - 1].deviceId data.videoDeviceId = data.videoList[len - 1].deviceId
@ -41,12 +42,14 @@ export default defineComponent({
cameraId: data.videoDeviceId, cameraId: data.videoDeviceId,
microphoneId: data.audioDeviceId microphoneId: data.audioDeviceId
}) })
emit('switch', { type: 'video', deviceId: data.cameraId })
} else { } else {
data.videoDeviceId = data.deviceList[0].deviceId data.videoDeviceId = data.videoList[0].deviceId
emit('init', { emit('init', {
cameraId: data.videoDeviceId, cameraId: data.videoDeviceId,
microphoneId: data.audioDeviceId microphoneId: data.audioDeviceId
}) })
emit('switch', { type: 'video', deviceId: data.cameraId })
} }
} }
@ -63,7 +66,7 @@ export default defineComponent({
return { return {
...toRefs(data), ...toRefs(data),
handleReverse handleCameraReverse
} }
} }

View File

@ -504,7 +504,7 @@ export default {
*/ */
const handelCameraReverse = () => { const handelCameraReverse = () => {
if (!status.isMutedVideo) { if (!status.isMutedVideo) {
cameraRef.value.handleReverse() cameraRef.value.handleCameraReverse()
} }
} }