@capacitor-community/camera-preview
Advanced tools
Comparing version 1.2.0 to 1.2.1
import { WebPlugin } from "@capacitor/core"; | ||
import { CameraPreviewOptions, CameraPreviewPictureOptions, CameraPreviewPlugin, CameraPreviewFlashMode } from "./definitions"; | ||
export declare class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin { | ||
/** | ||
* track which camera is used based on start options | ||
* used in capture | ||
*/ | ||
private isBackCamera; | ||
constructor(); | ||
@@ -5,0 +10,0 @@ start(options: CameraPreviewOptions): Promise<{}>; |
@@ -20,6 +20,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return new Promise((resolve, reject) => { | ||
navigator.mediaDevices.getUserMedia({ | ||
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { | ||
yield navigator.mediaDevices.getUserMedia({ | ||
audio: !options.disableAudio, | ||
video: true | ||
}).then((stream) => { | ||
// Stop any existing stream so we can request media with different constraints based on user input | ||
stream.getTracks().forEach((track) => track.stop()); | ||
}).catch(error => { | ||
reject(error); | ||
}); | ||
@@ -32,7 +37,19 @@ const video = document.getElementById("video"); | ||
videoElement.setAttribute("class", options.className || ""); | ||
videoElement.setAttribute("style", "-webkit-transform: scaleX(-1); transform: scaleX(-1);"); | ||
// Don't flip video feed if camera is rear facing | ||
if (options.position !== 'rear') { | ||
videoElement.setAttribute("style", "-webkit-transform: scaleX(-1); transform: scaleX(-1);"); | ||
} | ||
parent.appendChild(videoElement); | ||
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) { | ||
// Not adding `{ audio: true }` since we only want video now | ||
navigator.mediaDevices.getUserMedia({ video: true }).then(function (stream) { | ||
const constraints = { | ||
video: true, | ||
}; | ||
if (options.position === 'rear') { | ||
constraints.video = { facingMode: 'environment' }; | ||
this.isBackCamera = true; | ||
} | ||
else { | ||
this.isBackCamera = false; | ||
} | ||
navigator.mediaDevices.getUserMedia(constraints).then(function (stream) { | ||
//video.src = window.URL.createObjectURL(stream); | ||
@@ -50,3 +67,3 @@ videoElement.srcObject = stream; | ||
} | ||
}); | ||
})); | ||
}); | ||
@@ -78,4 +95,7 @@ } | ||
canvas.height = video.videoHeight; | ||
context.translate(video.videoWidth, 0); | ||
context.scale(-1, 1); | ||
// flip horizontally back camera isn't used | ||
if (!this.isBackCamera) { | ||
context.translate(video.videoWidth, 0); | ||
context.scale(-1, 1); | ||
} | ||
context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight); | ||
@@ -82,0 +102,0 @@ resolve({ |
{ | ||
"name": "@capacitor-community/camera-preview", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Camera preview", | ||
@@ -9,3 +9,3 @@ "main": "dist/esm/index.js", | ||
"build": "npm run clean && tsc", | ||
"clean": "rm -rf ./dist", | ||
"clean": "rimraf './dist'", | ||
"watch": "tsc --watch", | ||
@@ -23,2 +23,3 @@ "prepublishOnly": "npm run build", | ||
"@capacitor/ios": "latest", | ||
"rimraf": "latest", | ||
"typescript": "^3.2.4" | ||
@@ -25,0 +26,0 @@ }, |
@@ -409,1 +409,3 @@ # Capacitor Camera Preview | ||
A working example can be found at [Demo](https://github.com/capacitor-community/camera-preview/tree/master/demo) | ||
To run the demo on your local network and access media devices, a secure context is needed. Add an `.env` file at the root of the demo folder with `HTTPS=true` to start react with HTTPS. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10266531
217
1678
410
4
1
30