@carviz/capacitor-camera-preview 7.0.2 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraActivity.java +101 -0
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +40 -0
- package/dist/esm/definitions.d.ts +10 -0
- package/dist/esm/web.d.ts +3 -1
- package/dist/esm/web.js +6 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +6 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +6 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CameraController.swift +52 -3
- package/ios/Plugin/Plugin.swift +44 -0
- package/package.json +1 -1
|
@@ -828,4 +828,105 @@ public class CameraActivity extends Fragment {
|
|
|
828
828
|
float y = event.getY(0) - event.getY(1);
|
|
829
829
|
return (float) Math.sqrt(x * x + y * y);
|
|
830
830
|
}
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* Set the zoom level of the camera
|
|
834
|
+
* @param zoomLevel The zoom level to set (1.0 = no zoom, higher values = more zoom)
|
|
835
|
+
* @return true if zoom was set successfully, false otherwise
|
|
836
|
+
*/
|
|
837
|
+
public boolean setZoom(float zoomLevel) {
|
|
838
|
+
if (mCamera == null) {
|
|
839
|
+
Log.e(TAG, "Camera is null, cannot set zoom");
|
|
840
|
+
return false;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
try {
|
|
844
|
+
Camera.Parameters params = mCamera.getParameters();
|
|
845
|
+
if (!params.isZoomSupported()) {
|
|
846
|
+
Log.e(TAG, "Zoom is not supported on this device");
|
|
847
|
+
return false;
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
int maxZoom = params.getMaxZoom();
|
|
851
|
+
|
|
852
|
+
// Convert zoom level (1.0-based) to zoom index (0-based)
|
|
853
|
+
// Zoom level 1.0 = zoom index 0 (no zoom)
|
|
854
|
+
// Higher zoom levels map proportionally to the max zoom index
|
|
855
|
+
int zoomIndex;
|
|
856
|
+
if (zoomLevel <= 1.0f) {
|
|
857
|
+
zoomIndex = 0;
|
|
858
|
+
} else {
|
|
859
|
+
// Map zoom level linearly to zoom index range
|
|
860
|
+
zoomIndex = Math.round((zoomLevel - 1.0f) * maxZoom / (getMaxZoomLevel() - 1.0f));
|
|
861
|
+
zoomIndex = Math.min(zoomIndex, maxZoom);
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
params.setZoom(zoomIndex);
|
|
865
|
+
mCamera.setParameters(params);
|
|
866
|
+
|
|
867
|
+
Log.d(TAG, "Zoom set to level: " + zoomLevel + " (index: " + zoomIndex + ")");
|
|
868
|
+
return true;
|
|
869
|
+
} catch (Exception e) {
|
|
870
|
+
Log.e(TAG, "Error setting zoom: " + e.getMessage());
|
|
871
|
+
return false;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* Get the current zoom level of the camera
|
|
877
|
+
* @return The current zoom level (1.0 = no zoom, higher values = more zoom)
|
|
878
|
+
*/
|
|
879
|
+
public float getZoom() {
|
|
880
|
+
if (mCamera == null) {
|
|
881
|
+
Log.e(TAG, "Camera is null, cannot get zoom");
|
|
882
|
+
return 1.0f;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
try {
|
|
886
|
+
Camera.Parameters params = mCamera.getParameters();
|
|
887
|
+
if (!params.isZoomSupported()) {
|
|
888
|
+
Log.d(TAG, "Zoom is not supported on this device");
|
|
889
|
+
return 1.0f;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
int currentZoomIndex = params.getZoom();
|
|
893
|
+
int maxZoom = params.getMaxZoom();
|
|
894
|
+
|
|
895
|
+
// Convert zoom index (0-based) to zoom level (1.0-based)
|
|
896
|
+
if (currentZoomIndex == 0) {
|
|
897
|
+
return 1.0f;
|
|
898
|
+
} else {
|
|
899
|
+
// Map zoom index linearly to zoom level range
|
|
900
|
+
float zoomLevel = 1.0f + (currentZoomIndex * (getMaxZoomLevel() - 1.0f) / maxZoom);
|
|
901
|
+
return zoomLevel;
|
|
902
|
+
}
|
|
903
|
+
} catch (Exception e) {
|
|
904
|
+
Log.e(TAG, "Error getting zoom: " + e.getMessage());
|
|
905
|
+
return 1.0f;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
/**
|
|
910
|
+
* Get the maximum zoom level supported by the camera
|
|
911
|
+
* @return The maximum zoom level
|
|
912
|
+
*/
|
|
913
|
+
private float getMaxZoomLevel() {
|
|
914
|
+
if (mCamera == null) {
|
|
915
|
+
return 1.0f;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
try {
|
|
919
|
+
Camera.Parameters params = mCamera.getParameters();
|
|
920
|
+
if (!params.isZoomSupported()) {
|
|
921
|
+
return 1.0f;
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// Most Android cameras support up to 10x zoom, but we'll use a reasonable default
|
|
925
|
+
// This can be adjusted based on specific device capabilities
|
|
926
|
+
return 10.0f;
|
|
927
|
+
} catch (Exception e) {
|
|
928
|
+
Log.e(TAG, "Error getting max zoom level: " + e.getMessage());
|
|
929
|
+
return 1.0f;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
831
932
|
}
|
|
@@ -188,6 +188,46 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
188
188
|
call.resolve();
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
@PluginMethod
|
|
192
|
+
public void setZoom(PluginCall call) {
|
|
193
|
+
if (!this.hasCamera(call)) {
|
|
194
|
+
call.reject("Camera is not running");
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
Double zoomValue = call.getDouble("zoom");
|
|
199
|
+
if (zoomValue == null) {
|
|
200
|
+
call.reject("zoom parameter is missing");
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
float zoomLevel = zoomValue.floatValue();
|
|
205
|
+
if (zoomLevel < 1.0f) {
|
|
206
|
+
call.reject("zoom level must be >= 1.0");
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
boolean success = fragment.setZoom(zoomLevel);
|
|
211
|
+
if (success) {
|
|
212
|
+
call.resolve();
|
|
213
|
+
} else {
|
|
214
|
+
call.reject("Failed to set zoom level");
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
@PluginMethod
|
|
219
|
+
public void getZoom(PluginCall call) {
|
|
220
|
+
if (!this.hasCamera(call)) {
|
|
221
|
+
call.reject("Camera is not running");
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
float currentZoom = fragment.getZoom();
|
|
226
|
+
JSObject result = new JSObject();
|
|
227
|
+
result.put("zoom", currentZoom);
|
|
228
|
+
call.resolve(result);
|
|
229
|
+
}
|
|
230
|
+
|
|
191
231
|
@PermissionCallback
|
|
192
232
|
private void handleCameraPermissionResult(PluginCall call) {
|
|
193
233
|
if (PermissionState.GRANTED.equals(getPermissionState(CAMERA_PERMISSION_ALIAS))) {
|
|
@@ -54,6 +54,10 @@ export interface CameraOpacityOptions {
|
|
|
54
54
|
/** The percent opacity to set for camera view, default 1 */
|
|
55
55
|
opacity?: number;
|
|
56
56
|
}
|
|
57
|
+
export interface CameraZoomOptions {
|
|
58
|
+
/** The zoom level to set, where 1.0 is the default (no zoom) */
|
|
59
|
+
zoom: number;
|
|
60
|
+
}
|
|
57
61
|
export interface CameraPreviewPlugin {
|
|
58
62
|
/** Starts the camera preview instance */
|
|
59
63
|
start(options: CameraPreviewOptions): Promise<{}>;
|
|
@@ -79,6 +83,12 @@ export interface CameraPreviewPlugin {
|
|
|
79
83
|
flip(): Promise<void>;
|
|
80
84
|
/** Changes the opacity of the shown camera preview - Android / Web only */
|
|
81
85
|
setOpacity(options: CameraOpacityOptions): Promise<{}>;
|
|
86
|
+
/** Set the zoom level of the camera - Android / iOS only */
|
|
87
|
+
setZoom(options: CameraZoomOptions): Promise<void>;
|
|
88
|
+
/** Get the current zoom level of the camera - Android / iOS only */
|
|
89
|
+
getZoom(): Promise<{
|
|
90
|
+
zoom: number;
|
|
91
|
+
}>;
|
|
82
92
|
/** Check camera permission */
|
|
83
93
|
checkPermissions(): Promise<PermissionState>;
|
|
84
94
|
/** Request camera permission */
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
-
import type { CameraPreviewOptions, CameraPreviewPictureOptions, CameraPreviewPlugin, CameraPreviewFlashMode, CameraSampleOptions, CameraOpacityOptions } from './definitions';
|
|
2
|
+
import type { CameraPreviewOptions, CameraPreviewPictureOptions, CameraPreviewPlugin, CameraPreviewFlashMode, CameraSampleOptions, CameraOpacityOptions, CameraZoomOptions } from './definitions';
|
|
3
3
|
export declare class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin {
|
|
4
4
|
/**
|
|
5
5
|
* track which camera is used based on start options
|
|
@@ -19,6 +19,8 @@ export declare class CameraPreviewWeb extends WebPlugin implements CameraPreview
|
|
|
19
19
|
}): Promise<void>;
|
|
20
20
|
flip(): Promise<void>;
|
|
21
21
|
setOpacity(_options: CameraOpacityOptions): Promise<any>;
|
|
22
|
+
setZoom(_options: CameraZoomOptions): Promise<any>;
|
|
23
|
+
getZoom(): Promise<any>;
|
|
22
24
|
checkPermissions(): Promise<PermissionState>;
|
|
23
25
|
requestPermissions(): Promise<PermissionState>;
|
|
24
26
|
}
|
package/dist/esm/web.js
CHANGED
|
@@ -110,6 +110,12 @@ export class CameraPreviewWeb extends WebPlugin {
|
|
|
110
110
|
video.style.setProperty('opacity', _options['opacity'].toString());
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
+
async setZoom(_options) {
|
|
114
|
+
throw new Error('setZoom not supported under the web platform');
|
|
115
|
+
}
|
|
116
|
+
async getZoom() {
|
|
117
|
+
throw new Error('getZoom not supported under the web platform');
|
|
118
|
+
}
|
|
113
119
|
async checkPermissions() {
|
|
114
120
|
throw new Error('checkPermissions not supported under the web platform');
|
|
115
121
|
}
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAY5C,MAAM,OAAO,gBAAiB,SAAQ,SAAS;IAO7C;QACE,KAAK,EAAE,CAAC;IACV,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,OAA6B;;QACvC,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAE1E,kGAAkG;QAClG,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;QAEpD,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAC/C,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAEvD,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC5C,CAAC;QAED,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACrD,YAAY,CAAC,EAAE,GAAG,OAAO,CAAC;QAC1B,YAAY,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;QAE5D,iDAAiD;QACjD,IAAI,OA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K,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QACrE,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,QAA2B;QACvC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC3E,CAAC;IAED,KAAK,CAAC,kBAAkB;QACtB,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;CACF"}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -117,6 +117,12 @@ class CameraPreviewWeb extends core.WebPlugin {
|
|
|
117
117
|
video.style.setProperty('opacity', _options['opacity'].toString());
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
+
async setZoom(_options) {
|
|
121
|
+
throw new Error('setZoom not supported under the web platform');
|
|
122
|
+
}
|
|
123
|
+
async getZoom() {
|
|
124
|
+
throw new Error('getZoom not supported under the web platform');
|
|
125
|
+
}
|
|
120
126
|
async checkPermissions() {
|
|
121
127
|
throw new Error('checkPermissions not supported under the web platform');
|
|
122
128
|
}
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CameraPreview = registerPlugin('CameraPreview', {\n web: () => import('./web').then((m) => new m.CameraPreviewWeb()),\n});\nexport * from './definitions';\nexport { CameraPreview };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CameraPreviewWeb extends WebPlugin {\n constructor() {\n super();\n }\n async start(options) {\n var _a;\n const stream = await navigator.mediaDevices.getUserMedia({ video: true });\n // Stop any existing stream so we can request media with different constraints based on user input\n stream.getTracks().forEach((track) => track.stop());\n const video = document.getElementById('video');\n const parent = document.getElementById(options.parent);\n if (video) {\n throw new Error('camera already started');\n }\n const videoElement = document.createElement('video');\n videoElement.id = 'video';\n videoElement.setAttribute('class', options.className || '');\n // Don't flip video feed if camera is rear facing\n if (options.position !== 'rear') {\n videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');\n }\n const userAgent = navigator.userAgent.toLowerCase();\n const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');\n // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful\n // Without these attributes videoElement.play() will throw a NotAllowedError\n // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari\n if (isSafari) {\n videoElement.setAttribute('autoplay', 'true');\n videoElement.setAttribute('muted', 'true');\n videoElement.setAttribute('playsinline', 'true');\n }\n parent.appendChild(videoElement);\n if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia)) {\n throw new Error('No media devices available');\n }\n const constraints = {\n video: {\n width: { ideal: options.width },\n height: { ideal: options.height },\n },\n };\n if (options.position === 'rear') {\n constraints.video.facingMode = 'environment';\n this.isBackCamera = true;\n }\n else {\n this.isBackCamera = false;\n }\n videoElement.srcObject = await navigator.mediaDevices.getUserMedia(constraints);\n videoElement.play();\n return {};\n }\n async stop() {\n const video = document.getElementById('video');\n if (video) {\n video.pause();\n const st = video.srcObject;\n const tracks = st.getTracks();\n for (let i = 0; i < tracks.length; i++) {\n const track = tracks[i];\n track.stop();\n }\n video.remove();\n }\n }\n async capture(options) {\n return new Promise((resolve, _) => {\n const video = document.getElementById('video');\n const canvas = document.createElement('canvas');\n // video.width = video.offsetWidth;\n const context = canvas.getContext('2d');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n // flip horizontally back camera isn't used\n if (!this.isBackCamera) {\n context.translate(video.videoWidth, 0);\n context.scale(-1, 1);\n }\n context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);\n let base64EncodedImage;\n if (options.quality != undefined) {\n base64EncodedImage = canvas\n .toDataURL('image/jpeg', options.quality / 100.0)\n .replace('data:image/jpeg;base64,', '');\n }\n else {\n base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');\n }\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n async captureSample(_options) {\n return this.capture(_options);\n }\n async getSupportedFlashModes() {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n async setFlashMode(_options) {\n throw new Error('setFlashMode not supported under the web platform');\n }\n async flip() {\n throw new Error('flip not supported under the web platform');\n }\n async setOpacity(_options) {\n const video = document.getElementById('video');\n if (!!video && !!_options['opacity']) {\n video.style.setProperty('opacity', _options['opacity'].toString());\n }\n }\n async checkPermissions() {\n throw new Error('checkPermissions not supported under the web platform');\n }\n async requestPermissions() {\n throw new Error('requestPermissions not supported under the web platform');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,aAAa,GAAGA,mBAAc,CAAC,eAAe,EAAE;AACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;AACpE,CAAC;;ACFM,MAAM,gBAAgB,SAASC,cAAS,CAAC;AAChD,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,EAAE;AACf;AACA,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;AACzB,QAAQ,IAAI,EAAE;AACd,QAAQ,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACjF;AACA,QAAQ,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC;AAC3D,QAAQ,MAAM,KAAK,GAAG,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K,CAAC,6DAA6D,CAAC;AACtF;AACA,IAAI,MAAM,YAAY,CAAC,QAAQ,EAAE;AACjC,QAAQ,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC;AAC5E;AACA,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC;AACpE;AACA,IAAI,MAAM,UAAU,CAAC,QAAQ,EAAE;AAC/B,QAAQ,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC;AACtD,QAAQ,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;AAC9C,YAAY,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC9E;AACA;AACA,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC;AAChF;AACA,IAAI,MAAM,kBAAkB,GAAG;AAC/B,QAAQ,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC;AAClF;AACA;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CameraPreview = registerPlugin('CameraPreview', {\n web: () => import('./web').then((m) => new m.CameraPreviewWeb()),\n});\nexport * from './definitions';\nexport { CameraPreview };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CameraPreviewWeb extends WebPlugin {\n constructor() {\n super();\n }\n async start(options) {\n var _a;\n const stream = await navigator.mediaDevices.getUserMedia({ video: true });\n // Stop any existing stream so we can request media with different constraints based on user input\n stream.getTracks().forEach((track) => track.stop());\n const video = document.getElementById('video');\n const parent = document.getElementById(options.parent);\n if (video) {\n throw new Error('camera already started');\n }\n const videoElement = document.createElement('video');\n videoElement.id = 'video';\n videoElement.setAttribute('class', options.className || '');\n // Don't flip video feed if camera is rear facing\n if (options.position !== 'rear') {\n videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');\n }\n const userAgent = navigator.userAgent.toLowerCase();\n const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');\n // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful\n // Without these attributes videoElement.play() will throw a NotAllowedError\n // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari\n if (isSafari) {\n videoElement.setAttribute('autoplay', 'true');\n videoElement.setAttribute('muted', 'true');\n videoElement.setAttribute('playsinline', 'true');\n }\n parent.appendChild(videoElement);\n if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia)) {\n throw new Error('No media devices available');\n }\n const constraints = {\n video: {\n width: { ideal: options.width },\n height: { ideal: options.height },\n },\n };\n if (options.position === 'rear') {\n constraints.video.facingMode = 'environment';\n this.isBackCamera = true;\n }\n else {\n this.isBackCamera = false;\n }\n videoElement.srcObject = await navigator.mediaDevices.getUserMedia(constraints);\n videoElement.play();\n return {};\n }\n async stop() {\n const video = document.getElementById('video');\n if (video) {\n video.pause();\n const st = video.srcObject;\n const tracks = st.getTracks();\n for (let i = 0; i < tracks.length; i++) {\n const track = tracks[i];\n track.stop();\n }\n video.remove();\n }\n }\n async capture(options) {\n return new Promise((resolve, _) => {\n const video = document.getElementById('video');\n const canvas = document.createElement('canvas');\n // video.width = video.offsetWidth;\n const context = canvas.getContext('2d');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n // flip horizontally back camera isn't used\n if (!this.isBackCamera) {\n context.translate(video.videoWidth, 0);\n context.scale(-1, 1);\n }\n context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);\n let base64EncodedImage;\n if (options.quality != undefined) {\n base64EncodedImage = canvas\n .toDataURL('image/jpeg', options.quality / 100.0)\n .replace('data:image/jpeg;base64,', '');\n }\n else {\n base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');\n }\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n async captureSample(_options) {\n return this.capture(_options);\n }\n async getSupportedFlashModes() {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n async setFlashMode(_options) {\n throw new Error('setFlashMode not supported under the web platform');\n }\n async flip() {\n throw new Error('flip not supported under the web platform');\n }\n async setOpacity(_options) {\n const video = document.getElementById('video');\n if (!!video && !!_options['opacity']) {\n video.style.setProperty('opacity', _options['opacity'].toString());\n }\n }\n async setZoom(_options) {\n throw new Error('setZoom not supported under the web platform');\n }\n async getZoom() {\n throw new Error('getZoom not supported under the web platform');\n }\n async checkPermissions() {\n throw new Error('checkPermissions not supported under the web platform');\n }\n async requestPermissions() {\n throw new Error('requestPermissions not supported under the web platform');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,aAAa,GAAGA,mBAAc,CAAC,eAAe,EAAE;AACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;AACpE,CAAC;;ACFM,MAAM,gBAAgB,SAASC,cAAS,CAAC;AAChD,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,EAAE;AACf;AACA,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;AACzB,QAAQ,IAAI,EAAE;AACd,QAAQ,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACjF;AACA,QAAQ,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC;AAC3D,QAAQ,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC;AACtD,QAAQ,MAAM,MAAM,GAAG,QAAQ,CAAC,cA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MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC;AAC5E;AACA,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC;AACpE;AACA,IAAI,MAAM,UAAU,CAAC,QAAQ,EAAE;AAC/B,QAAQ,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC;AACtD,QAAQ,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;AAC9C,YAAY,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC9E;AACA;AACA,IAAI,MAAM,OAAO,CAAC,QAAQ,EAAE;AAC5B,QAAQ,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC;AACvE;AACA,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC;AACvE;AACA,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC;AAChF;AACA,IAAI,MAAM,kBAAkB,GAAG;AAC/B,QAAQ,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC;AAClF;AACA;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -116,6 +116,12 @@ var capacitorSplashScreen = (function (exports, core) {
|
|
|
116
116
|
video.style.setProperty('opacity', _options['opacity'].toString());
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
+
async setZoom(_options) {
|
|
120
|
+
throw new Error('setZoom not supported under the web platform');
|
|
121
|
+
}
|
|
122
|
+
async getZoom() {
|
|
123
|
+
throw new Error('getZoom not supported under the web platform');
|
|
124
|
+
}
|
|
119
125
|
async checkPermissions() {
|
|
120
126
|
throw new Error('checkPermissions not supported under the web platform');
|
|
121
127
|
}
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CameraPreview = registerPlugin('CameraPreview', {\n web: () => import('./web').then((m) => new m.CameraPreviewWeb()),\n});\nexport * from './definitions';\nexport { CameraPreview };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CameraPreviewWeb extends WebPlugin {\n constructor() {\n super();\n }\n async start(options) {\n var _a;\n const stream = await navigator.mediaDevices.getUserMedia({ video: true });\n // Stop any existing stream so we can request media with different constraints based on user input\n stream.getTracks().forEach((track) => track.stop());\n const video = document.getElementById('video');\n const parent = document.getElementById(options.parent);\n if (video) {\n throw new Error('camera already started');\n }\n const videoElement = document.createElement('video');\n videoElement.id = 'video';\n videoElement.setAttribute('class', options.className || '');\n // Don't flip video feed if camera is rear facing\n if (options.position !== 'rear') {\n videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');\n }\n const userAgent = navigator.userAgent.toLowerCase();\n const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');\n // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful\n // Without these attributes videoElement.play() will throw a NotAllowedError\n // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari\n if (isSafari) {\n videoElement.setAttribute('autoplay', 'true');\n videoElement.setAttribute('muted', 'true');\n videoElement.setAttribute('playsinline', 'true');\n }\n parent.appendChild(videoElement);\n if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia)) {\n throw new Error('No media devices available');\n }\n const constraints = {\n video: {\n width: { ideal: options.width },\n height: { ideal: options.height },\n },\n };\n if (options.position === 'rear') {\n constraints.video.facingMode = 'environment';\n this.isBackCamera = true;\n }\n else {\n this.isBackCamera = false;\n }\n videoElement.srcObject = await navigator.mediaDevices.getUserMedia(constraints);\n videoElement.play();\n return {};\n }\n async stop() {\n const video = document.getElementById('video');\n if (video) {\n video.pause();\n const st = video.srcObject;\n const tracks = st.getTracks();\n for (let i = 0; i < tracks.length; i++) {\n const track = tracks[i];\n track.stop();\n }\n video.remove();\n }\n }\n async capture(options) {\n return new Promise((resolve, _) => {\n const video = document.getElementById('video');\n const canvas = document.createElement('canvas');\n // video.width = video.offsetWidth;\n const context = canvas.getContext('2d');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n // flip horizontally back camera isn't used\n if (!this.isBackCamera) {\n context.translate(video.videoWidth, 0);\n context.scale(-1, 1);\n }\n context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);\n let base64EncodedImage;\n if (options.quality != undefined) {\n base64EncodedImage = canvas\n .toDataURL('image/jpeg', options.quality / 100.0)\n .replace('data:image/jpeg;base64,', '');\n }\n else {\n base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');\n }\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n async captureSample(_options) {\n return this.capture(_options);\n }\n async getSupportedFlashModes() {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n async setFlashMode(_options) {\n throw new Error('setFlashMode not supported under the web platform');\n }\n async flip() {\n throw new Error('flip not supported under the web platform');\n }\n async setOpacity(_options) {\n const video = document.getElementById('video');\n if (!!video && !!_options['opacity']) {\n video.style.setProperty('opacity', _options['opacity'].toString());\n }\n }\n async checkPermissions() {\n throw new Error('checkPermissions not supported under the web platform');\n }\n async requestPermissions() {\n throw new Error('requestPermissions not supported under the web platform');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,aAAa,GAAGA,mBAAc,CAAC,eAAe,EAAE;IACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;IACpE,CAAC;;ICFM,MAAM,gBAAgB,SAASC,cAAS,CAAC;IAChD,IAAI,WAAW,GAAG;I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,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,wBAAwB,EAAE,EAAE,CAAC;IACxG;IACA,YAAY,OAAO,CAAC;IACpB,gBAAgB,KAAK,EAAE,kBAAkB;IACzC,aAAa,CAAC;IACd,SAAS,CAAC;IACV;IACA,IAAI,MAAM,aAAa,CAAC,QAAQ,EAAE;IAClC,QAAQ,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IACrC;IACA,IAAI,MAAM,sBAAsB,GAAG;IACnC,QAAQ,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC;IACtF;IACA,IAAI,MAAM,YAAY,CAAC,QAAQ,EAAE;IACjC,QAAQ,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC;IAC5E;IACA,IAAI,MAAM,IAAI,GAAG;IACjB,QAAQ,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC;IACpE;IACA,IAAI,MAAM,UAAU,CAAC,QAAQ,EAAE;IAC/B,QAAQ,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC;IACtD,QAAQ,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;IAC9C,YAAY,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC9E;IACA;IACA,IAAI,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC;IAChF;IACA,IAAI,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC;IAClF;IACA;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CameraPreview = registerPlugin('CameraPreview', {\n web: () => import('./web').then((m) => new m.CameraPreviewWeb()),\n});\nexport * from './definitions';\nexport { CameraPreview };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CameraPreviewWeb extends WebPlugin {\n constructor() {\n super();\n }\n async start(options) {\n var _a;\n const stream = await navigator.mediaDevices.getUserMedia({ video: true });\n // Stop any existing stream so we can request media with different constraints based on user input\n stream.getTracks().forEach((track) => track.stop());\n const video = document.getElementById('video');\n const parent = document.getElementById(options.parent);\n if (video) {\n throw new Error('camera already started');\n }\n const videoElement = document.createElement('video');\n videoElement.id = 'video';\n videoElement.setAttribute('class', options.className || '');\n // Don't flip video feed if camera is rear facing\n if (options.position !== 'rear') {\n videoElement.setAttribute('style', '-webkit-transform: scaleX(-1); transform: scaleX(-1);');\n }\n const userAgent = navigator.userAgent.toLowerCase();\n const isSafari = userAgent.includes('safari') && !userAgent.includes('chrome');\n // Safari on iOS needs to have the autoplay, muted and playsinline attributes set for video.play() to be successful\n // Without these attributes videoElement.play() will throw a NotAllowedError\n // https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari\n if (isSafari) {\n videoElement.setAttribute('autoplay', 'true');\n videoElement.setAttribute('muted', 'true');\n videoElement.setAttribute('playsinline', 'true');\n }\n parent.appendChild(videoElement);\n if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia)) {\n throw new Error('No media devices available');\n }\n const constraints = {\n video: {\n width: { ideal: options.width },\n height: { ideal: options.height },\n },\n };\n if (options.position === 'rear') {\n constraints.video.facingMode = 'environment';\n this.isBackCamera = true;\n }\n else {\n this.isBackCamera = false;\n }\n videoElement.srcObject = await navigator.mediaDevices.getUserMedia(constraints);\n videoElement.play();\n return {};\n }\n async stop() {\n const video = document.getElementById('video');\n if (video) {\n video.pause();\n const st = video.srcObject;\n const tracks = st.getTracks();\n for (let i = 0; i < tracks.length; i++) {\n const track = tracks[i];\n track.stop();\n }\n video.remove();\n }\n }\n async capture(options) {\n return new Promise((resolve, _) => {\n const video = document.getElementById('video');\n const canvas = document.createElement('canvas');\n // video.width = video.offsetWidth;\n const context = canvas.getContext('2d');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n // flip horizontally back camera isn't used\n if (!this.isBackCamera) {\n context.translate(video.videoWidth, 0);\n context.scale(-1, 1);\n }\n context.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);\n let base64EncodedImage;\n if (options.quality != undefined) {\n base64EncodedImage = canvas\n .toDataURL('image/jpeg', options.quality / 100.0)\n .replace('data:image/jpeg;base64,', '');\n }\n else {\n base64EncodedImage = canvas.toDataURL('image/png').replace('data:image/png;base64,', '');\n }\n resolve({\n value: base64EncodedImage,\n });\n });\n }\n async captureSample(_options) {\n return this.capture(_options);\n }\n async getSupportedFlashModes() {\n throw new Error('getSupportedFlashModes not supported under the web platform');\n }\n async setFlashMode(_options) {\n throw new Error('setFlashMode not supported under the web platform');\n }\n async flip() {\n throw new Error('flip not supported under the web platform');\n }\n async setOpacity(_options) {\n const video = document.getElementById('video');\n if (!!video && !!_options['opacity']) {\n video.style.setProperty('opacity', _options['opacity'].toString());\n }\n }\n async setZoom(_options) {\n throw new Error('setZoom not supported under the web platform');\n }\n async getZoom() {\n throw new Error('getZoom not supported under the web platform');\n }\n async checkPermissions() {\n throw new Error('checkPermissions not supported under the web platform');\n }\n async requestPermissions() {\n throw new Error('requestPermissions not supported under the web platform');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,aAAa,GAAGA,mBAAc,CAAC,eAAe,EAAE;IACtD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,gBAAgB,EAAE,CAAC;IACpE,CAAC;;ICFM,MAAM,gBAAgB,SAASC,cAAS,CAAC;IAChD,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,EAAE;IACf;IACA,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;IACzB,QAAQ,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|
|
|
152
152
|
// Note that zoomFactor 2 "equals" the regular 1x zoom factor of the native iphone camera app
|
|
153
153
|
// 0.5x however equal a videoZoomFactor of 1. We do not want to use ultra wide angle by default
|
|
154
154
|
// the default videoZoomFactor to 2 in case the current camera device type is .builtInTripleCamera
|
|
155
|
-
cameraDevice.videoZoomFactor =
|
|
155
|
+
cameraDevice.videoZoomFactor = 2
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
|
|
@@ -388,6 +388,51 @@ class CameraController: NSObject {
|
|
|
388
388
|
target.addGestureRecognizer(pinchGesture)
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
+
/**
|
|
392
|
+
Set the zoom level of the camera
|
|
393
|
+
|
|
394
|
+
- Parameters:
|
|
395
|
+
- zoomLevel: The zoom level to set (1.0 = no zoom, higher values = more zoom)
|
|
396
|
+
- Throws: `CameraControllerError.noCamerasAvailable` if camera is not available
|
|
397
|
+
*/
|
|
398
|
+
public func setZoom(zoomLevel: CGFloat) throws {
|
|
399
|
+
guard let device = self.currentCamera else {
|
|
400
|
+
throw CameraControllerError.noCamerasAvailable
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
func minMaxZoom(_ factor: CGFloat) -> CGFloat {
|
|
404
|
+
return max(1.0, min(factor, device.activeFormat.videoMaxZoomFactor))
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
let constrainedZoomFactor = minMaxZoom(zoomLevel)
|
|
408
|
+
|
|
409
|
+
do {
|
|
410
|
+
try device.lockForConfiguration()
|
|
411
|
+
defer { device.unlockForConfiguration() }
|
|
412
|
+
|
|
413
|
+
device.videoZoomFactor = constrainedZoomFactor
|
|
414
|
+
|
|
415
|
+
// Update our stored zoom factor
|
|
416
|
+
videoZoomFactor = constrainedZoomFactor
|
|
417
|
+
} catch {
|
|
418
|
+
throw CameraControllerError.invalidOperation
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
Get the current zoom level of the camera
|
|
424
|
+
|
|
425
|
+
- Returns: The current zoom level (1.0 = no zoom, higher values = more zoom)
|
|
426
|
+
- Throws: `CameraControllerError.noCamerasAvailable` if camera is not available
|
|
427
|
+
*/
|
|
428
|
+
public func getZoom() throws -> CGFloat {
|
|
429
|
+
guard let device = self.currentCamera else {
|
|
430
|
+
throw CameraControllerError.noCamerasAvailable
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
return device.videoZoomFactor
|
|
434
|
+
}
|
|
435
|
+
|
|
391
436
|
}
|
|
392
437
|
|
|
393
438
|
extension UIImage {
|
|
@@ -513,11 +558,15 @@ extension CameraController: UIGestureRecognizerDelegate {
|
|
|
513
558
|
}
|
|
514
559
|
|
|
515
560
|
switch pinch.state {
|
|
516
|
-
case .began:
|
|
561
|
+
case .began:
|
|
562
|
+
// Store the current zoom factor when pinch begins
|
|
563
|
+
videoZoomFactor = device.videoZoomFactor
|
|
517
564
|
case .changed:
|
|
518
|
-
|
|
565
|
+
// Calculate new zoom factor based on current zoom and pinch scale
|
|
566
|
+
let newScaleFactor = minMaxZoom(videoZoomFactor * pinch.scale)
|
|
519
567
|
update(scale: newScaleFactor)
|
|
520
568
|
case .ended:
|
|
569
|
+
// Update stored zoom factor to the final zoom level
|
|
521
570
|
videoZoomFactor = device.videoZoomFactor
|
|
522
571
|
default: break
|
|
523
572
|
}
|
package/ios/Plugin/Plugin.swift
CHANGED
|
@@ -202,6 +202,50 @@ public class CameraPreview: CAPPlugin {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
/**
|
|
206
|
+
Set the zoom level of the camera
|
|
207
|
+
*/
|
|
208
|
+
@objc func setZoom(_ call: CAPPluginCall) {
|
|
209
|
+
guard let captureSession = self.cameraController.captureSession, captureSession.isRunning else {
|
|
210
|
+
call.reject("camera is not running")
|
|
211
|
+
return
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
guard let zoomLevel = call.getDouble("zoom") else {
|
|
215
|
+
call.reject("zoom parameter is missing")
|
|
216
|
+
return
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if zoomLevel < 1.0 {
|
|
220
|
+
call.reject("zoom level must be >= 1.0")
|
|
221
|
+
return
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
do {
|
|
225
|
+
try self.cameraController.setZoom(zoomLevel: CGFloat(zoomLevel))
|
|
226
|
+
call.resolve()
|
|
227
|
+
} catch {
|
|
228
|
+
call.reject("failed to set zoom level: \(error.localizedDescription)")
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
Get the current zoom level of the camera
|
|
234
|
+
*/
|
|
235
|
+
@objc func getZoom(_ call: CAPPluginCall) {
|
|
236
|
+
guard let captureSession = self.cameraController.captureSession, captureSession.isRunning else {
|
|
237
|
+
call.reject("camera is not running")
|
|
238
|
+
return
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
do {
|
|
242
|
+
let currentZoom = try self.cameraController.getZoom()
|
|
243
|
+
call.resolve(["zoom": currentZoom])
|
|
244
|
+
} catch {
|
|
245
|
+
call.reject("failed to get zoom level: \(error.localizedDescription)")
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
205
249
|
/**
|
|
206
250
|
Helper method for initializing the plugin settings based on the Capacitor call
|
|
207
251
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carviz/capacitor-camera-preview",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "Fork of the capacitor-community/camera-preview plugin focusing on high resolution photos without bloating up the code.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/plugin.cjs.js",
|