capacitor-plugin-camera-forked 2.0.8

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.
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'CapacitorPluginCameraForked'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.license = package['license']
10
+ s.homepage = package['repository']['url']
11
+ s.author = package['author']
12
+ s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
+ s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '13.0'
15
+ s.dependency 'Capacitor'
16
+ s.swift_version = '5.1'
17
+ end
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Lihang Xu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,513 @@
1
+ # capacitor-plugin-camera
2
+
3
+ A capacitor camera plugin.
4
+
5
+ [Online demo](https://dazzling-cactus-692f14.netlify.app/)
6
+
7
+ ## Supported Platforms
8
+
9
+ * Android (based on CameraX)
10
+ * iOS (based on AVCaptureSession)
11
+ * Web (based on getUserMedia with Dynamsoft Camera Enhancer)
12
+
13
+ ## Versions
14
+
15
+ For Capacitor 5, use versions 1.x.
16
+
17
+ For Capacitor 6, use versions 2.x.
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ npm install capacitor-plugin-camera
23
+ npx cap sync
24
+ ```
25
+ ## Get Bitmap/UIImage via Reflection
26
+
27
+ If you are developing a plugin, you can use reflection to get the camera frames as Bitmap or UIImage on the native side.
28
+
29
+ Java:
30
+
31
+ ```java
32
+ Class cls = Class.forName("com.tonyxlh.capacitor.camera.CameraPreviewPlugin");
33
+ Method m = cls.getMethod("getBitmap",null);
34
+ Bitmap bitmap = (Bitmap) m.invoke(null, null);
35
+ ```
36
+
37
+ Objective-C:
38
+
39
+ ```obj-c
40
+ - (UIImage*)getUIImage{
41
+ UIImage *image = ((UIImage* (*)(id, SEL))objc_msgSend)(objc_getClass("CameraPreviewPlugin"), sel_registerName("getBitmap"));
42
+ return image;
43
+ }
44
+ ```
45
+
46
+ You have to call `saveFrame` beforehand.
47
+
48
+ ## Declare Permissions
49
+
50
+ To use camera and microphone, we need to declare permissions.
51
+
52
+ Add the following to Android's `AndroidManifest.xml`:
53
+
54
+ ```xml
55
+ <uses-permission android:name="android.permission.CAMERA" />
56
+ <uses-permission android:name="android.permission.RECORD_AUDIO" />
57
+ ```
58
+
59
+ Add the following to iOS's `Info.plist`:
60
+
61
+ ```xml
62
+ <key>NSCameraUsageDescription</key>
63
+ <string>For camera usage</string>
64
+ <key>NSMicrophoneUsageDescription</key>
65
+ <string>For video recording</string>
66
+ ```
67
+
68
+ ## FAQ
69
+
70
+ Why I cannot see the camera?
71
+
72
+ For native platforms, the plugin puts the native camera view behind the webview and sets the webview as transparent so that we can display HTML elements above the camera.
73
+
74
+ You may need to add the style below on your app's HTML or body element to avoid blocking the camera view:
75
+
76
+ ```css
77
+ ion-content {
78
+ --background: transparent;
79
+ }
80
+ ```
81
+
82
+ In dark mode, it is neccessary to set the `--ion-blackground-color` property. You can do this with the following code:
83
+
84
+ ```js
85
+ document.documentElement.style.setProperty('--ion-background-color', 'transparent');
86
+ ```
87
+
88
+ ## API
89
+
90
+ <docgen-index>
91
+
92
+ * [`initialize()`](#initialize)
93
+ * [`getResolution()`](#getresolution)
94
+ * [`setResolution(...)`](#setresolution)
95
+ * [`getAllCameras()`](#getallcameras)
96
+ * [`getSelectedCamera()`](#getselectedcamera)
97
+ * [`selectCamera(...)`](#selectcamera)
98
+ * [`setScanRegion(...)`](#setscanregion)
99
+ * [`setZoom(...)`](#setzoom)
100
+ * [`setFocus(...)`](#setfocus)
101
+ * [`setDefaultUIElementURL(...)`](#setdefaultuielementurl)
102
+ * [`setElement(...)`](#setelement)
103
+ * [`startCamera()`](#startcamera)
104
+ * [`stopCamera()`](#stopcamera)
105
+ * [`takeSnapshot(...)`](#takesnapshot)
106
+ * [`saveFrame()`](#saveframe)
107
+ * [`takeSnapshot2(...)`](#takesnapshot2)
108
+ * [`takePhoto(...)`](#takephoto)
109
+ * [`toggleTorch(...)`](#toggletorch)
110
+ * [`getOrientation()`](#getorientation)
111
+ * [`startRecording()`](#startrecording)
112
+ * [`stopRecording(...)`](#stoprecording)
113
+ * [`setLayout(...)`](#setlayout)
114
+ * [`requestCameraPermission()`](#requestcamerapermission)
115
+ * [`requestMicroPhonePermission()`](#requestmicrophonepermission)
116
+ * [`isOpen()`](#isopen)
117
+ * [`addListener('onPlayed', ...)`](#addlisteneronplayed)
118
+ * [`addListener('onOrientationChanged', ...)`](#addlisteneronorientationchanged)
119
+ * [`removeAllListeners()`](#removealllisteners)
120
+ * [Interfaces](#interfaces)
121
+ * [Type Aliases](#type-aliases)
122
+
123
+ </docgen-index>
124
+
125
+ <docgen-api>
126
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
127
+
128
+ ### initialize()
129
+
130
+ ```typescript
131
+ initialize() => Promise<void>
132
+ ```
133
+
134
+ --------------------
135
+
136
+
137
+ ### getResolution()
138
+
139
+ ```typescript
140
+ getResolution() => Promise<{ resolution: string; }>
141
+ ```
142
+
143
+ **Returns:** <code>Promise&lt;{ resolution: string; }&gt;</code>
144
+
145
+ --------------------
146
+
147
+
148
+ ### setResolution(...)
149
+
150
+ ```typescript
151
+ setResolution(options: { resolution: number; }) => Promise<void>
152
+ ```
153
+
154
+ | Param | Type |
155
+ | ------------- | ------------------------------------ |
156
+ | **`options`** | <code>{ resolution: number; }</code> |
157
+
158
+ --------------------
159
+
160
+
161
+ ### getAllCameras()
162
+
163
+ ```typescript
164
+ getAllCameras() => Promise<{ cameras: string[]; }>
165
+ ```
166
+
167
+ **Returns:** <code>Promise&lt;{ cameras: string[]; }&gt;</code>
168
+
169
+ --------------------
170
+
171
+
172
+ ### getSelectedCamera()
173
+
174
+ ```typescript
175
+ getSelectedCamera() => Promise<{ selectedCamera: string; }>
176
+ ```
177
+
178
+ **Returns:** <code>Promise&lt;{ selectedCamera: string; }&gt;</code>
179
+
180
+ --------------------
181
+
182
+
183
+ ### selectCamera(...)
184
+
185
+ ```typescript
186
+ selectCamera(options: { cameraID: string; }) => Promise<void>
187
+ ```
188
+
189
+ | Param | Type |
190
+ | ------------- | ---------------------------------- |
191
+ | **`options`** | <code>{ cameraID: string; }</code> |
192
+
193
+ --------------------
194
+
195
+
196
+ ### setScanRegion(...)
197
+
198
+ ```typescript
199
+ setScanRegion(options: { region: ScanRegion; }) => Promise<void>
200
+ ```
201
+
202
+ | Param | Type |
203
+ | ------------- | -------------------------------------------------------------- |
204
+ | **`options`** | <code>{ region: <a href="#scanregion">ScanRegion</a>; }</code> |
205
+
206
+ --------------------
207
+
208
+
209
+ ### setZoom(...)
210
+
211
+ ```typescript
212
+ setZoom(options: { factor: number; }) => Promise<void>
213
+ ```
214
+
215
+ | Param | Type |
216
+ | ------------- | -------------------------------- |
217
+ | **`options`** | <code>{ factor: number; }</code> |
218
+
219
+ --------------------
220
+
221
+
222
+ ### setFocus(...)
223
+
224
+ ```typescript
225
+ setFocus(options: { x: number; y: number; }) => Promise<void>
226
+ ```
227
+
228
+ | Param | Type |
229
+ | ------------- | -------------------------------------- |
230
+ | **`options`** | <code>{ x: number; y: number; }</code> |
231
+
232
+ --------------------
233
+
234
+
235
+ ### setDefaultUIElementURL(...)
236
+
237
+ ```typescript
238
+ setDefaultUIElementURL(url: string) => Promise<void>
239
+ ```
240
+
241
+ Web Only
242
+
243
+ | Param | Type |
244
+ | --------- | ------------------- |
245
+ | **`url`** | <code>string</code> |
246
+
247
+ --------------------
248
+
249
+
250
+ ### setElement(...)
251
+
252
+ ```typescript
253
+ setElement(ele: any) => Promise<void>
254
+ ```
255
+
256
+ Web Only
257
+
258
+ | Param | Type |
259
+ | --------- | ---------------- |
260
+ | **`ele`** | <code>any</code> |
261
+
262
+ --------------------
263
+
264
+
265
+ ### startCamera()
266
+
267
+ ```typescript
268
+ startCamera() => Promise<void>
269
+ ```
270
+
271
+ --------------------
272
+
273
+
274
+ ### stopCamera()
275
+
276
+ ```typescript
277
+ stopCamera() => Promise<void>
278
+ ```
279
+
280
+ --------------------
281
+
282
+
283
+ ### takeSnapshot(...)
284
+
285
+ ```typescript
286
+ takeSnapshot(options: { quality?: number; }) => Promise<{ base64: string; }>
287
+ ```
288
+
289
+ take a snapshot as base64.
290
+
291
+ | Param | Type |
292
+ | ------------- | ---------------------------------- |
293
+ | **`options`** | <code>{ quality?: number; }</code> |
294
+
295
+ **Returns:** <code>Promise&lt;{ base64: string; }&gt;</code>
296
+
297
+ --------------------
298
+
299
+
300
+ ### saveFrame()
301
+
302
+ ```typescript
303
+ saveFrame() => Promise<{ success: boolean; }>
304
+ ```
305
+
306
+ save a frame internally. Android and iOS only.
307
+
308
+ **Returns:** <code>Promise&lt;{ success: boolean; }&gt;</code>
309
+
310
+ --------------------
311
+
312
+
313
+ ### takeSnapshot2(...)
314
+
315
+ ```typescript
316
+ takeSnapshot2(options: { canvas: HTMLCanvasElement; maxLength?: number; }) => Promise<{ scaleRatio?: number; }>
317
+ ```
318
+
319
+ take a snapshot on to a canvas. Web Only
320
+
321
+ | Param | Type |
322
+ | ------------- | ------------------------------------------------- |
323
+ | **`options`** | <code>{ canvas: any; maxLength?: number; }</code> |
324
+
325
+ **Returns:** <code>Promise&lt;{ scaleRatio?: number; }&gt;</code>
326
+
327
+ --------------------
328
+
329
+
330
+ ### takePhoto(...)
331
+
332
+ ```typescript
333
+ takePhoto(options: { pathToSave?: string; includeBase64?: boolean; }) => Promise<{ path?: string; base64?: string; blob?: Blob; }>
334
+ ```
335
+
336
+ | Param | Type |
337
+ | ------------- | -------------------------------------------------------------- |
338
+ | **`options`** | <code>{ pathToSave?: string; includeBase64?: boolean; }</code> |
339
+
340
+ **Returns:** <code>Promise&lt;{ path?: string; base64?: string; blob?: any; }&gt;</code>
341
+
342
+ --------------------
343
+
344
+
345
+ ### toggleTorch(...)
346
+
347
+ ```typescript
348
+ toggleTorch(options: { on: boolean; }) => Promise<void>
349
+ ```
350
+
351
+ | Param | Type |
352
+ | ------------- | ----------------------------- |
353
+ | **`options`** | <code>{ on: boolean; }</code> |
354
+
355
+ --------------------
356
+
357
+
358
+ ### getOrientation()
359
+
360
+ ```typescript
361
+ getOrientation() => Promise<{ "orientation": "PORTRAIT" | "LANDSCAPE"; }>
362
+ ```
363
+
364
+ get the orientation of the device.
365
+
366
+ **Returns:** <code>Promise&lt;{ orientation: 'PORTRAIT' | 'LANDSCAPE'; }&gt;</code>
367
+
368
+ --------------------
369
+
370
+
371
+ ### startRecording()
372
+
373
+ ```typescript
374
+ startRecording() => Promise<void>
375
+ ```
376
+
377
+ --------------------
378
+
379
+
380
+ ### stopRecording(...)
381
+
382
+ ```typescript
383
+ stopRecording(options: { includeBase64?: boolean; }) => Promise<{ path?: string; base64?: string; blob?: Blob; }>
384
+ ```
385
+
386
+ | Param | Type |
387
+ | ------------- | ----------------------------------------- |
388
+ | **`options`** | <code>{ includeBase64?: boolean; }</code> |
389
+
390
+ **Returns:** <code>Promise&lt;{ path?: string; base64?: string; blob?: any; }&gt;</code>
391
+
392
+ --------------------
393
+
394
+
395
+ ### setLayout(...)
396
+
397
+ ```typescript
398
+ setLayout(options: { top: string; left: string; width: string; height: string; }) => Promise<void>
399
+ ```
400
+
401
+ | Param | Type |
402
+ | ------------- | -------------------------------------------------------------------------- |
403
+ | **`options`** | <code>{ top: string; left: string; width: string; height: string; }</code> |
404
+
405
+ --------------------
406
+
407
+
408
+ ### requestCameraPermission()
409
+
410
+ ```typescript
411
+ requestCameraPermission() => Promise<void>
412
+ ```
413
+
414
+ --------------------
415
+
416
+
417
+ ### requestMicroPhonePermission()
418
+
419
+ ```typescript
420
+ requestMicroPhonePermission() => Promise<void>
421
+ ```
422
+
423
+ --------------------
424
+
425
+
426
+ ### isOpen()
427
+
428
+ ```typescript
429
+ isOpen() => Promise<{ isOpen: boolean; }>
430
+ ```
431
+
432
+ **Returns:** <code>Promise&lt;{ isOpen: boolean; }&gt;</code>
433
+
434
+ --------------------
435
+
436
+
437
+ ### addListener('onPlayed', ...)
438
+
439
+ ```typescript
440
+ addListener(eventName: 'onPlayed', listenerFunc: onPlayedListener) => Promise<PluginListenerHandle>
441
+ ```
442
+
443
+ | Param | Type |
444
+ | ------------------ | ------------------------------------------------------------- |
445
+ | **`eventName`** | <code>'onPlayed'</code> |
446
+ | **`listenerFunc`** | <code><a href="#onplayedlistener">onPlayedListener</a></code> |
447
+
448
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
449
+
450
+ --------------------
451
+
452
+
453
+ ### addListener('onOrientationChanged', ...)
454
+
455
+ ```typescript
456
+ addListener(eventName: 'onOrientationChanged', listenerFunc: onOrientationChangedListener) => Promise<PluginListenerHandle>
457
+ ```
458
+
459
+ | Param | Type |
460
+ | ------------------ | ------------------------------------------------------------------------------------- |
461
+ | **`eventName`** | <code>'onOrientationChanged'</code> |
462
+ | **`listenerFunc`** | <code><a href="#onorientationchangedlistener">onOrientationChangedListener</a></code> |
463
+
464
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
465
+
466
+ --------------------
467
+
468
+
469
+ ### removeAllListeners()
470
+
471
+ ```typescript
472
+ removeAllListeners() => Promise<void>
473
+ ```
474
+
475
+ --------------------
476
+
477
+
478
+ ### Interfaces
479
+
480
+
481
+ #### ScanRegion
482
+
483
+ measuredByPercentage: 0 in pixel, 1 in percent
484
+
485
+ | Prop | Type |
486
+ | -------------------------- | ------------------- |
487
+ | **`left`** | <code>number</code> |
488
+ | **`top`** | <code>number</code> |
489
+ | **`right`** | <code>number</code> |
490
+ | **`bottom`** | <code>number</code> |
491
+ | **`measuredByPercentage`** | <code>number</code> |
492
+
493
+
494
+ #### PluginListenerHandle
495
+
496
+ | Prop | Type |
497
+ | ------------ | ----------------------------------------- |
498
+ | **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |
499
+
500
+
501
+ ### Type Aliases
502
+
503
+
504
+ #### onPlayedListener
505
+
506
+ <code>(result: { resolution: string; }): void</code>
507
+
508
+
509
+ #### onOrientationChangedListener
510
+
511
+ <code>(): void</code>
512
+
513
+ </docgen-api>
@@ -0,0 +1,66 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
6
+ }
7
+
8
+ buildscript {
9
+ repositories {
10
+ google()
11
+ mavenCentral()
12
+ }
13
+ dependencies {
14
+ classpath 'com.android.tools.build:gradle:8.2.1'
15
+ }
16
+ }
17
+
18
+ apply plugin: 'com.android.library'
19
+
20
+ android {
21
+ namespace "com.tonyxlh.capacitor.camera"
22
+ compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
23
+ defaultConfig {
24
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
25
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
26
+ versionCode 1
27
+ versionName "1.0"
28
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
29
+ }
30
+ buildTypes {
31
+ release {
32
+ minifyEnabled false
33
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34
+ }
35
+ }
36
+ lintOptions {
37
+ abortOnError false
38
+ }
39
+ compileOptions {
40
+ sourceCompatibility JavaVersion.VERSION_17
41
+ targetCompatibility JavaVersion.VERSION_17
42
+ }
43
+ }
44
+
45
+ repositories {
46
+ google()
47
+ mavenCentral()
48
+ }
49
+
50
+
51
+ dependencies {
52
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
53
+ implementation project(':capacitor-android')
54
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
55
+ testImplementation "junit:junit:$junitVersion"
56
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
57
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
58
+
59
+ // CameraX core library using the camera2 implementation
60
+ def camerax_version = "1.1.0"
61
+ implementation "androidx.camera:camera-core:${camerax_version}"
62
+ implementation "androidx.camera:camera-camera2:${camerax_version}"
63
+ implementation "androidx.camera:camera-lifecycle:${camerax_version}"
64
+ implementation "androidx.camera:camera-view:${camerax_version}"
65
+ implementation "androidx.camera:camera-video:${camerax_version}"
66
+ }
@@ -0,0 +1,4 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+
3
+ <uses-permission android:name="android.permission.RECORD_AUDIO" />
4
+ </manifest>