From 79b880d7bf97b7b5c42614c0a1d43fe9dcb4c56d Mon Sep 17 00:00:00 2001 From: Joscha Date: Wed, 26 Mar 2025 23:56:32 +0100 Subject: [PATCH] Fix camera not turning back on after using gallery --- showbits-thermal-printer-ui/src/AppPhoto.vue | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/showbits-thermal-printer-ui/src/AppPhoto.vue b/showbits-thermal-printer-ui/src/AppPhoto.vue index 5e486ff..4a1bb3d 100644 --- a/showbits-thermal-printer-ui/src/AppPhoto.vue +++ b/showbits-thermal-printer-ui/src/AppPhoto.vue @@ -19,20 +19,20 @@ function getFacingModeFromStream(stream: MediaStream): string | undefined { return video?.getSettings().facingMode; } +function deinitStream() { + if (stream.value === undefined) return; + for (const track of stream.value.getTracks()) { + track.stop(); + } + stream.value = undefined; +} + async function initStream(facingMode?: string) { assert(video.value !== null); const video_ = video.value; // If the tracks are not all stopped, getUserMedia throws an exception. - if (stream.value !== undefined) { - for (const track of stream.value.getTracks()) { - track.stop(); - } - } - - stream.value = undefined; - facing.value = undefined; - video_.srcObject = null; + deinitStream(); stream.value = await navigator.mediaDevices.getUserMedia({ video: { facingMode: { ideal: facingMode } }, @@ -69,6 +69,7 @@ async function postImage(image: Blob | File) { async function onGallery(file: File) { await postImage(file); + await initStream(facing.value); } async function onRecord() {