Skip to content
This repository was archived by the owner on Sep 28, 2024. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,37 @@
document.body.classList[on ? 'add' : 'remove']('light-on');
};

var got_camera = function(camera) {
if (cameraWithFlash === null && camera.capabilities.flashModes.indexOf('torch') !== -1) {
cameraWithFlash = camera;

switch_the_light(true);
} else {
camera.release();
}
};

var version = window.navigator.userAgent.match(/Firefox\/([\d]+)/);
var usePromise = (version && version.length === 2 && version[1] >= 37)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could it be replaced with var usePromise = !(version && version.length === 2 && version[1] < 37) ? that way it should work on other browsers if they decided to implement the last version of the API


try {
var cameras = window.navigator.mozCameras.getListOfCameras();

for (var cameraId of cameras) {
var camera = window.navigator.mozCameras.getCamera({
camera: cameraId
}, function(camera) {
if (camera.capabilities.flashModes.indexOf('torch') !== -1) {
cameraWithFlash = camera;

switch_the_light(true);
}
});
if (usePromise) {
window.navigator.mozCameras.getCamera(
cameraId,
{
mode: 'unspecified'
}
).then(function(p) {
got_camera(p.camera);
});
} else {
window.navigator.mozCameras.getCamera(
cameraId, null, got_camera
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure there should be null as the second parameter? in the previous version, I only had 2 parameters, cameraId and got_camera

);
}
}
} catch (e) {
// camera api not supported
Expand Down