@carviz/capacitor-camera-preview 7.1.0 → 7.2.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 +22 -0
- package/android/src/main/java/com/ahm/capacitor/camera/preview/CameraPreview.java +9 -1
- package/dist/esm/definitions.d.ts +9 -1
- package/dist/esm/web.d.ts +3 -0
- 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 +56 -0
- package/ios/Plugin/Plugin.m +2 -0
- package/ios/Plugin/Plugin.swift +11 -1
- package/package.json +2 -2
|
@@ -47,7 +47,12 @@ public class CameraActivity extends Fragment {
|
|
|
47
47
|
void onCameraStarted();
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
public interface ZoomChangeListener {
|
|
51
|
+
void onZoomChanged(float zoomLevel);
|
|
52
|
+
}
|
|
53
|
+
|
|
50
54
|
private CameraPreviewListener eventListener;
|
|
55
|
+
private ZoomChangeListener zoomChangeListener;
|
|
51
56
|
private static final String TAG = "CameraActivity";
|
|
52
57
|
public FrameLayout mainLayout;
|
|
53
58
|
public FrameLayout frameContainerLayout;
|
|
@@ -91,6 +96,10 @@ public class CameraActivity extends Fragment {
|
|
|
91
96
|
eventListener = listener;
|
|
92
97
|
}
|
|
93
98
|
|
|
99
|
+
public void setZoomChangeListener(ZoomChangeListener listener) {
|
|
100
|
+
zoomChangeListener = listener;
|
|
101
|
+
}
|
|
102
|
+
|
|
94
103
|
private String appResourcesPackage;
|
|
95
104
|
|
|
96
105
|
@Override
|
|
@@ -281,6 +290,13 @@ public class CameraActivity extends Fragment {
|
|
|
281
290
|
mDist = newDist;
|
|
282
291
|
params.setZoom(zoom);
|
|
283
292
|
mCamera.setParameters(params);
|
|
293
|
+
|
|
294
|
+
// Notify listener of zoom change during pinch
|
|
295
|
+
if (zoomChangeListener != null) {
|
|
296
|
+
// Convert zoom index back to zoom level for consistency
|
|
297
|
+
float zoomLevel = 1.0f + (zoom * (getMaxZoomLevel() - 1.0f) / maxZoom);
|
|
298
|
+
zoomChangeListener.onZoomChanged(zoomLevel);
|
|
299
|
+
}
|
|
284
300
|
}
|
|
285
301
|
}
|
|
286
302
|
}
|
|
@@ -865,6 +881,12 @@ public class CameraActivity extends Fragment {
|
|
|
865
881
|
mCamera.setParameters(params);
|
|
866
882
|
|
|
867
883
|
Log.d(TAG, "Zoom set to level: " + zoomLevel + " (index: " + zoomIndex + ")");
|
|
884
|
+
|
|
885
|
+
// Notify listener of zoom change
|
|
886
|
+
if (zoomChangeListener != null) {
|
|
887
|
+
zoomChangeListener.onZoomChanged(zoomLevel);
|
|
888
|
+
}
|
|
889
|
+
|
|
868
890
|
return true;
|
|
869
891
|
} catch (Exception e) {
|
|
870
892
|
Log.e(TAG, "Error setting zoom: " + e.getMessage());
|
|
@@ -28,7 +28,7 @@ import java.util.List;
|
|
|
28
28
|
import org.json.JSONArray;
|
|
29
29
|
|
|
30
30
|
@CapacitorPlugin(name = "CameraPreview", permissions = { @Permission(strings = { CAMERA }, alias = CameraPreview.CAMERA_PERMISSION_ALIAS) })
|
|
31
|
-
public class CameraPreview extends Plugin implements CameraActivity.CameraPreviewListener {
|
|
31
|
+
public class CameraPreview extends Plugin implements CameraActivity.CameraPreviewListener, CameraActivity.ZoomChangeListener {
|
|
32
32
|
|
|
33
33
|
static final String CAMERA_PERMISSION_ALIAS = "camera";
|
|
34
34
|
|
|
@@ -271,6 +271,7 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
271
271
|
fragment.toBack = toBack;
|
|
272
272
|
fragment.enableOpacity = enableOpacity;
|
|
273
273
|
fragment.enableZoom = enableZoom;
|
|
274
|
+
fragment.setZoomChangeListener(this);
|
|
274
275
|
|
|
275
276
|
bridge
|
|
276
277
|
.getActivity()
|
|
@@ -395,6 +396,13 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
|
|
|
395
396
|
bridge.releaseCall(pluginCall);
|
|
396
397
|
}
|
|
397
398
|
|
|
399
|
+
@Override
|
|
400
|
+
public void onZoomChanged(float zoom) {
|
|
401
|
+
JSObject result = new JSObject();
|
|
402
|
+
result.put("zoom", zoom);
|
|
403
|
+
notifyListeners("zoomChanged", result);
|
|
404
|
+
}
|
|
405
|
+
|
|
398
406
|
private boolean hasView(PluginCall call) {
|
|
399
407
|
if (fragment == null) {
|
|
400
408
|
return false;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PermissionState } from '@capacitor/core';
|
|
1
|
+
import type { PermissionState, PluginListenerHandle } from '@capacitor/core';
|
|
2
2
|
export type CameraPosition = 'rear' | 'front';
|
|
3
3
|
export interface CameraPreviewOptions {
|
|
4
4
|
/** Parent element to attach the video preview element to (applicable to the web platform only) */
|
|
@@ -58,6 +58,10 @@ export interface CameraZoomOptions {
|
|
|
58
58
|
/** The zoom level to set, where 1.0 is the default (no zoom) */
|
|
59
59
|
zoom: number;
|
|
60
60
|
}
|
|
61
|
+
export interface CameraZoomChangeEvent {
|
|
62
|
+
/** The new zoom level */
|
|
63
|
+
zoom: number;
|
|
64
|
+
}
|
|
61
65
|
export interface CameraPreviewPlugin {
|
|
62
66
|
/** Starts the camera preview instance */
|
|
63
67
|
start(options: CameraPreviewOptions): Promise<{}>;
|
|
@@ -93,4 +97,8 @@ export interface CameraPreviewPlugin {
|
|
|
93
97
|
checkPermissions(): Promise<PermissionState>;
|
|
94
98
|
/** Request camera permission */
|
|
95
99
|
requestPermissions(): Promise<PermissionState>;
|
|
100
|
+
/** Listen for zoom changes - Android / iOS only */
|
|
101
|
+
addListener(eventName: 'zoomChanged', listenerFunc: (event: CameraZoomChangeEvent) => void): Promise<PluginListenerHandle>;
|
|
102
|
+
/** Remove all listeners for this plugin */
|
|
103
|
+
removeAllListeners(): Promise<void>;
|
|
96
104
|
}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { PluginListenerHandle } from '@capacitor/core';
|
|
2
3
|
import type { CameraPreviewOptions, CameraPreviewPictureOptions, CameraPreviewPlugin, CameraPreviewFlashMode, CameraSampleOptions, CameraOpacityOptions, CameraZoomOptions } from './definitions';
|
|
3
4
|
export declare class CameraPreviewWeb extends WebPlugin implements CameraPreviewPlugin {
|
|
4
5
|
/**
|
|
@@ -23,4 +24,6 @@ export declare class CameraPreviewWeb extends WebPlugin implements CameraPreview
|
|
|
23
24
|
getZoom(): Promise<any>;
|
|
24
25
|
checkPermissions(): Promise<PermissionState>;
|
|
25
26
|
requestPermissions(): Promise<PermissionState>;
|
|
27
|
+
addListener(_eventName: string, _listenerFunc: (info: any) => void): Promise<PluginListenerHandle>;
|
|
28
|
+
removeAllListeners(): Promise<void>;
|
|
26
29
|
}
|
package/dist/esm/web.js
CHANGED
|
@@ -122,5 +122,11 @@ export class CameraPreviewWeb extends WebPlugin {
|
|
|
122
122
|
async requestPermissions() {
|
|
123
123
|
throw new Error('requestPermissions not supported under the web platform');
|
|
124
124
|
}
|
|
125
|
+
async addListener(_eventName, _listenerFunc) {
|
|
126
|
+
throw new Error('addListener not supported under the web platform');
|
|
127
|
+
}
|
|
128
|
+
async removeAllListeners() {
|
|
129
|
+
throw new Error('removeAllListeners not supported under the web platform');
|
|
130
|
+
}
|
|
125
131
|
}
|
|
126
132
|
//# sourceMappingURL=web.js.map
|
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":"A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CAAC,CAAC;IAC3E,CAAC;IAED,KAAK,CAAC,kBAAkB;QACtB,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,UAAkB,EAAE,aAAkC;QACtE,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IAED,KAAK,CAAC,kBAAkB;QACtB,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;CACF"}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -129,6 +129,12 @@ class CameraPreviewWeb extends core.WebPlugin {
|
|
|
129
129
|
async requestPermissions() {
|
|
130
130
|
throw new Error('requestPermissions not supported under the web platform');
|
|
131
131
|
}
|
|
132
|
+
async addListener(_eventName, _listenerFunc) {
|
|
133
|
+
throw new Error('addListener not supported under the web platform');
|
|
134
|
+
}
|
|
135
|
+
async removeAllListeners() {
|
|
136
|
+
throw new Error('removeAllListeners not supported under the web platform');
|
|
137
|
+
}
|
|
132
138
|
}
|
|
133
139
|
|
|
134
140
|
var web = /*#__PURE__*/Object.freeze({
|
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 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,GA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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,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;;;;;;;;;"}
|
|
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 async addListener(_eventName, _listenerFunc) {\n throw new Error('addListener not supported under the web platform');\n }\n async removeAllListeners() {\n throw new Error('removeAllListeners 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;AAC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yD,CAAC;AAClF;AACA;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -128,6 +128,12 @@ var capacitorSplashScreen = (function (exports, core) {
|
|
|
128
128
|
async requestPermissions() {
|
|
129
129
|
throw new Error('requestPermissions not supported under the web platform');
|
|
130
130
|
}
|
|
131
|
+
async addListener(_eventName, _listenerFunc) {
|
|
132
|
+
throw new Error('addListener not supported under the web platform');
|
|
133
|
+
}
|
|
134
|
+
async removeAllListeners() {
|
|
135
|
+
throw new Error('removeAllListeners not supported under the web platform');
|
|
136
|
+
}
|
|
131
137
|
}
|
|
132
138
|
|
|
133
139
|
var web = /*#__PURE__*/Object.freeze({
|
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 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,IAAI,EAAE;IACd,QAAQ,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACjF;IACA,QAAQ,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC;IAC3D,QAAQ,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC;IACtD,QAAQ,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC;IAC9D,QAAQ,IAAI,KAAK,EAAE;IACnB,YAAY,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC;IACrD;IACA,QAAQ,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC;IAC5D,QAAQ,YAAY,CAAC,EAAE,GAAG,OAAO;IACjC,QAAQ,YAAY,CAAC,YAAY,CAAC,OAAO,EAAE,OA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,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,OAAO,CAAC,QAAQ,EAAE;IAC5B,QAAQ,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC;IACvE;IACA,IAAI,MAAM,OAAO,GAAG;IACpB,QAAQ,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC;IACvE;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 async addListener(_eventName, _listenerFunc) {\n throw new Error('addListener not supported under the web platform');\n }\n async removeAllListeners() {\n throw new Error('removeAllListeners 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,IAAI,EAAE;IACd,QAAQ,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACjF;IACA,QAAQ,MAAM,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC;IAC3D,QAAQ,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC;IACtD,QAAQ,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC;IAC9D,QAAQ,IAAI,KAAK,EAAE;IACnB,YAAY,MAA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AAQ,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,OAAO,CAAC,QAAQ,EAAE;IAC5B,QAAQ,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC;IACvE;IACA,IAAI,MAAM,OAAO,GAAG;IACpB,QAAQ,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC;IACvE;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,IAAI,MAAM,WAAW,CAAC,UAAU,EAAE,aAAa,EAAE;IACjD,QAAQ,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC;IAC3E;IACA,IAAI,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC;IAClF;IACA;;;;;;;;;;;;;;;"}
|
|
@@ -15,6 +15,9 @@ public enum CameraPosition {
|
|
|
15
15
|
case rear
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
protocol CameraControllerDelegate: AnyObject {
|
|
19
|
+
func cameraController(_ controller: CameraController, didChangeZoomTo zoomLevel: CGFloat)
|
|
20
|
+
}
|
|
18
21
|
|
|
19
22
|
extension CameraControllerError: LocalizedError {
|
|
20
23
|
public var errorDescription: String? {
|
|
@@ -40,6 +43,7 @@ class CameraController: NSObject {
|
|
|
40
43
|
var captureSession: AVCaptureSession?
|
|
41
44
|
|
|
42
45
|
var photoOutput = AVCapturePhotoOutput()
|
|
46
|
+
var videoDataOutput = AVCaptureVideoDataOutput()
|
|
43
47
|
var photoCaptureCompletionBlock: ((UIImage?, Error?) -> Void)?
|
|
44
48
|
var sampleBufferCaptureCompletionBlock: ((UIImage?, Error?) -> Void)?
|
|
45
49
|
|
|
@@ -54,6 +58,9 @@ class CameraController: NSObject {
|
|
|
54
58
|
|
|
55
59
|
/** Video zoom factor that is used for manually zooming in and out via pinch gesture */
|
|
56
60
|
var videoZoomFactor: CGFloat = 1
|
|
61
|
+
|
|
62
|
+
/** Delegate for camera events */
|
|
63
|
+
weak var delegate: CameraControllerDelegate?
|
|
57
64
|
|
|
58
65
|
public func prepare(cameraPosition: CameraPosition?, enableHighResolution isHighResolutionPhotoEnabled: Bool, completionHandler: @escaping (Error?) -> Void) {
|
|
59
66
|
// Set up capture session
|
|
@@ -85,6 +92,13 @@ class CameraController: NSObject {
|
|
|
85
92
|
captureSession.addOutput(self.photoOutput)
|
|
86
93
|
}
|
|
87
94
|
|
|
95
|
+
// Configure video data output for sample capture
|
|
96
|
+
self.videoDataOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "videoQueue"))
|
|
97
|
+
self.videoDataOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA)]
|
|
98
|
+
if captureSession.canAddOutput(self.videoDataOutput) {
|
|
99
|
+
captureSession.addOutput(self.videoDataOutput)
|
|
100
|
+
}
|
|
101
|
+
|
|
88
102
|
captureSession.startRunning()
|
|
89
103
|
|
|
90
104
|
// Lastly setting the video zoom factor
|
|
@@ -287,6 +301,7 @@ class CameraController: NSObject {
|
|
|
287
301
|
return
|
|
288
302
|
}
|
|
289
303
|
|
|
304
|
+
// Store the completion block to be called when we receive the next video frame
|
|
290
305
|
self.sampleBufferCaptureCompletionBlock = completion
|
|
291
306
|
}
|
|
292
307
|
|
|
@@ -414,6 +429,9 @@ class CameraController: NSObject {
|
|
|
414
429
|
|
|
415
430
|
// Update our stored zoom factor
|
|
416
431
|
videoZoomFactor = constrainedZoomFactor
|
|
432
|
+
|
|
433
|
+
// Notify delegate of zoom change
|
|
434
|
+
delegate?.cameraController(self, didChangeZoomTo: constrainedZoomFactor)
|
|
417
435
|
} catch {
|
|
418
436
|
throw CameraControllerError.invalidOperation
|
|
419
437
|
}
|
|
@@ -508,6 +526,41 @@ extension CameraController: AVCapturePhotoCaptureDelegate {
|
|
|
508
526
|
}
|
|
509
527
|
}
|
|
510
528
|
|
|
529
|
+
extension CameraController: AVCaptureVideoDataOutputSampleBufferDelegate {
|
|
530
|
+
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
|
|
531
|
+
// Only process if we have a pending sample capture request
|
|
532
|
+
guard let completion = self.sampleBufferCaptureCompletionBlock else { return }
|
|
533
|
+
|
|
534
|
+
// Clear the completion block to avoid capturing multiple frames for one request
|
|
535
|
+
self.sampleBufferCaptureCompletionBlock = nil
|
|
536
|
+
|
|
537
|
+
// Convert sample buffer to UIImage
|
|
538
|
+
guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {
|
|
539
|
+
DispatchQueue.main.async {
|
|
540
|
+
completion(nil, CameraControllerError.unknown)
|
|
541
|
+
}
|
|
542
|
+
return
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
let ciImage = CIImage(cvPixelBuffer: pixelBuffer)
|
|
546
|
+
let context = CIContext()
|
|
547
|
+
|
|
548
|
+
guard let cgImage = context.createCGImage(ciImage, from: ciImage.extent) else {
|
|
549
|
+
DispatchQueue.main.async {
|
|
550
|
+
completion(nil, CameraControllerError.unknown)
|
|
551
|
+
}
|
|
552
|
+
return
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
let image = UIImage(cgImage: cgImage)
|
|
556
|
+
|
|
557
|
+
// Call completion on main queue
|
|
558
|
+
DispatchQueue.main.async {
|
|
559
|
+
completion(image, nil)
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
511
564
|
extension CameraController: UIGestureRecognizerDelegate {
|
|
512
565
|
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
|
|
513
566
|
return true
|
|
@@ -552,6 +605,9 @@ extension CameraController: UIGestureRecognizerDelegate {
|
|
|
552
605
|
defer { device.unlockForConfiguration() }
|
|
553
606
|
|
|
554
607
|
device.videoZoomFactor = factor
|
|
608
|
+
|
|
609
|
+
// Notify delegate of zoom change during pinch
|
|
610
|
+
delegate?.cameraController(self, didChangeZoomTo: factor)
|
|
555
611
|
} catch {
|
|
556
612
|
debugPrint(error)
|
|
557
613
|
}
|
package/ios/Plugin/Plugin.m
CHANGED
|
@@ -11,6 +11,8 @@ CAP_PLUGIN(CameraPreview, "CameraPreview",
|
|
|
11
11
|
CAP_PLUGIN_METHOD(flip, CAPPluginReturnPromise);
|
|
12
12
|
CAP_PLUGIN_METHOD(getSupportedFlashModes, CAPPluginReturnPromise);
|
|
13
13
|
CAP_PLUGIN_METHOD(setFlashMode, CAPPluginReturnPromise);
|
|
14
|
+
CAP_PLUGIN_METHOD(setZoom, CAPPluginReturnPromise);
|
|
15
|
+
CAP_PLUGIN_METHOD(getZoom, CAPPluginReturnPromise);
|
|
14
16
|
CAP_PLUGIN_METHOD(checkPermissions, CAPPluginReturnPromise);
|
|
15
17
|
CAP_PLUGIN_METHOD(requestPermissions, CAPPluginReturnPromise);
|
|
16
18
|
)
|
package/ios/Plugin/Plugin.swift
CHANGED
|
@@ -6,7 +6,7 @@ import AVFoundation
|
|
|
6
6
|
* here: https://capacitor.ionicframework.com/docs/plugins/ios
|
|
7
7
|
*/
|
|
8
8
|
@objc(CameraPreview)
|
|
9
|
-
public class CameraPreview: CAPPlugin {
|
|
9
|
+
public class CameraPreview: CAPPlugin, CameraControllerDelegate {
|
|
10
10
|
let cameraController = CameraController()
|
|
11
11
|
var cameraPosition: CameraPosition = .rear
|
|
12
12
|
var x: CGFloat = 0.0
|
|
@@ -20,6 +20,13 @@ public class CameraPreview: CAPPlugin {
|
|
|
20
20
|
var storeToFile = false
|
|
21
21
|
var enableZoom = false
|
|
22
22
|
var enableHighResolution = false
|
|
23
|
+
|
|
24
|
+
// MARK: - CameraControllerDelegate
|
|
25
|
+
|
|
26
|
+
func cameraController(_ controller: CameraController, didChangeZoomTo zoomLevel: CGFloat) {
|
|
27
|
+
// Emit zoom change event to JavaScript
|
|
28
|
+
notifyListeners("zoomChanged", data: ["zoom": zoomLevel])
|
|
29
|
+
}
|
|
23
30
|
|
|
24
31
|
/**
|
|
25
32
|
Start the camera preview in a new UIView
|
|
@@ -39,6 +46,9 @@ public class CameraPreview: CAPPlugin {
|
|
|
39
46
|
return
|
|
40
47
|
}
|
|
41
48
|
|
|
49
|
+
// Set up delegate for zoom change events
|
|
50
|
+
self?.cameraController.delegate = self
|
|
51
|
+
|
|
42
52
|
self?.cameraController.prepare(cameraPosition: self?.cameraPosition, enableHighResolution: self?.enableHighResolution ?? false) { error in
|
|
43
53
|
if let error = error {
|
|
44
54
|
call.reject(error.localizedDescription)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carviz/capacitor-camera-preview",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.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",
|
|
@@ -82,4 +82,4 @@
|
|
|
82
82
|
"bugs": {
|
|
83
83
|
"url": "https://github.com/GetCarviz/capacitor-camera-preview/issues"
|
|
84
84
|
}
|
|
85
|
-
}
|
|
85
|
+
}
|