Skip to content

Commit

Permalink
Fix webcam (#10327)
Browse files Browse the repository at this point in the history
  • Loading branch information
Col0ring authored Jan 10, 2025
1 parent bb11a2a commit e0cb47f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .changeset/funny-heads-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@gradio/image": patch
"gradio": patch
---

fix:Fix webcam
20 changes: 13 additions & 7 deletions js/image/shared/Webcam.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,21 @@
let webcam_accessed = false;
function record_video_or_photo(): void {
function record_video_or_photo({
destroy
}: { destroy?: boolean } = {}): void {
if (mode === "image" && streaming) {
recording = !recording;
}
if (mode === "image") {
take_picture();
} else {
take_recording();
if (!destroy) {
if (mode === "image") {
take_picture();
} else {
take_recording();
}
}
if (!recording && stream) {
dispatch("close_stream");
stream.getTracks().forEach((track) => track.stop());
Expand Down Expand Up @@ -276,7 +282,7 @@
onDestroy(() => {
if (typeof window === "undefined") return;
record_video_or_photo();
record_video_or_photo({ destroy: true });
stream?.getTracks().forEach((track) => track.stop());
});
</script>
Expand Down Expand Up @@ -306,7 +312,7 @@
{:else}
<div class="button-wrap">
<button
on:click={record_video_or_photo}
on:click={() => record_video_or_photo()}
aria-label={mode === "image" ? "capture photo" : "start recording"}
>
{#if mode === "video" || streaming}
Expand Down

0 comments on commit e0cb47f

Please sign in to comment.