Skip to content

Commit d76443a

Browse files
author
Lionel Laské
committed
Merge branch 'pr/1928' into dev
2 parents f09b0c0 + 999e395 commit d76443a

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2727
- UUID v4 generation bug: incorrect bitwise operation forces variant to 8 #1840
2828
- Variable Shadowing - Overwrites Module Object #1846
2929
- Use of '=' instead of '==' in if else statement in Physics game activity.js #1870
30+
- Camera remains active when toggling off in QRCode activity (Web/Desktop) #1911
3031

3132
## [1.9.0] - 2025-03-25
3233
### Added

activities/QRCode.activity/js/activity.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ define(["sugar-web/activity/activity","sugar-web/datastore", "sugar-web/env", "l
229229
// Handle HTML5 capture
230230
var outdiv = document.getElementById("outdiv");
231231
var videostream = document.getElementById("video-stream");
232+
if (videostream) {
233+
videostream.style.visibility = "visible";
234+
}
232235
if (!photoButton.classList.contains('active')) {
233236
document.getElementById("qr-code").style.visibility = "hidden";
234237
document.getElementById("loading-spinner").style.visibility = "visible";
@@ -243,8 +246,10 @@ define(["sugar-web/activity/activity","sugar-web/datastore", "sugar-web/env", "l
243246
videostream.style.visibility = "visible";
244247
}
245248
} else {
246-
outdiv.style.visibility = "hidden";
247-
videostream.style.visibility = "hidden";
249+
if (typeof stopWebcam === "function") {
250+
stopWebcam();
251+
}
252+
photoInitialized = false;
248253
document.getElementById("loading-spinner").style.visibility = "hidden";
249254
document.getElementById("qr-code").style.visibility = "visible";
250255
userText.value = oldUserText;

activities/QRCode.activity/js/webqr.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var v=null;
1212
var qrSize = 0;
1313
var margin = 0;
1414
var scannedCallback = null;
15+
var currentStream = null;
1516

1617

1718
var vidhtml = '<video id="video-stream" autoplay></video>';
@@ -83,8 +84,8 @@ function isCanvasSupported(){
8384
return !!(elem.getContext && elem.getContext('2d'));
8485
}
8586
function success(stream)
86-
{
87-
87+
{
88+
currentStream = stream;
8889
v.srcObject = stream;
8990
v.play();
9091

@@ -184,3 +185,24 @@ function setwebcam2(options)
184185
stype=1;
185186
setTimeout(captureToCanvas, 500);
186187
}
188+
function stopWebcam() {
189+
if (currentStream) {
190+
currentStream.getTracks().forEach(function(track) {
191+
track.stop();
192+
});
193+
currentStream = null;
194+
}
195+
196+
if (v) {
197+
v.pause();
198+
v.srcObject = null;
199+
}
200+
201+
gUM = false;
202+
stype = 0;
203+
204+
var outdiv = document.getElementById("outdiv");
205+
if (outdiv) {
206+
outdiv.innerHTML = "";
207+
}
208+
}

0 commit comments

Comments
 (0)