capacitor-camera-module 0.0.1 → 0.0.2
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/README.md +86 -0
- package/dist/docs.json +126 -1
- package/dist/esm/definitions.d.ts +19 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +9 -1
- package/dist/esm/web.js +148 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +148 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +148 -0
- package/dist/plugin.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,6 +14,12 @@ npx cap sync
|
|
|
14
14
|
<docgen-index>
|
|
15
15
|
|
|
16
16
|
* [`echo(...)`](#echo)
|
|
17
|
+
* [`echo(...)`](#echo)
|
|
18
|
+
* [`checkPermission()`](#checkpermission)
|
|
19
|
+
* [`requestPermission()`](#requestpermission)
|
|
20
|
+
* [`checkAndRequestPermission()`](#checkandrequestpermission)
|
|
21
|
+
* [`getCameraCapabilities()`](#getcameracapabilities)
|
|
22
|
+
* [Interfaces](#interfaces)
|
|
17
23
|
|
|
18
24
|
</docgen-index>
|
|
19
25
|
|
|
@@ -34,4 +40,84 @@ echo(options: { value: string; }) => Promise<{ value: string; }>
|
|
|
34
40
|
|
|
35
41
|
--------------------
|
|
36
42
|
|
|
43
|
+
|
|
44
|
+
### echo(...)
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
echo(options: { value: string; }) => Promise<{ value: string; }>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
| Param | Type |
|
|
51
|
+
| ------------- | ------------------------------- |
|
|
52
|
+
| **`options`** | <code>{ value: string; }</code> |
|
|
53
|
+
|
|
54
|
+
**Returns:** <code>Promise<{ value: string; }></code>
|
|
55
|
+
|
|
56
|
+
--------------------
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
### checkPermission()
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
checkPermission() => Promise<PermissionStatus>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Returns:** <code>Promise<<a href="#permissionstatus">PermissionStatus</a>></code>
|
|
66
|
+
|
|
67
|
+
--------------------
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
### requestPermission()
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
requestPermission() => Promise<PermissionStatus>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**Returns:** <code>Promise<<a href="#permissionstatus">PermissionStatus</a>></code>
|
|
77
|
+
|
|
78
|
+
--------------------
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
### checkAndRequestPermission()
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
checkAndRequestPermission() => Promise<PermissionStatus>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Returns:** <code>Promise<<a href="#permissionstatus">PermissionStatus</a>></code>
|
|
88
|
+
|
|
89
|
+
--------------------
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
### getCameraCapabilities()
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
getCameraCapabilities() => Promise<CameraCapabilities>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Returns:** <code>Promise<<a href="#cameracapabilities">CameraCapabilities</a>></code>
|
|
99
|
+
|
|
100
|
+
--------------------
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
### Interfaces
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
#### PermissionStatus
|
|
107
|
+
|
|
108
|
+
| Prop | Type |
|
|
109
|
+
| ------------- | -------------------------------------------------------------------------------------- |
|
|
110
|
+
| **`granted`** | <code>boolean</code> |
|
|
111
|
+
| **`status`** | <code>'granted' \| 'denied' \| 'prompt' \| 'prompt-with-rationale' \| 'limited'</code> |
|
|
112
|
+
| **`details`** | <code>string</code> |
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
#### CameraCapabilities
|
|
116
|
+
|
|
117
|
+
| Prop | Type |
|
|
118
|
+
| --------------------- | -------------------- |
|
|
119
|
+
| **`hasCamera`** | <code>boolean</code> |
|
|
120
|
+
| **`isSecureContext`** | <code>boolean</code> |
|
|
121
|
+
| **`userAgent`** | <code>string</code> |
|
|
122
|
+
|
|
37
123
|
</docgen-api>
|
package/dist/docs.json
CHANGED
|
@@ -20,11 +20,136 @@
|
|
|
20
20
|
"docs": "",
|
|
21
21
|
"complexTypes": [],
|
|
22
22
|
"slug": "echo"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"name": "echo",
|
|
26
|
+
"signature": "(options: { value: string; }) => Promise<{ value: string; }>",
|
|
27
|
+
"parameters": [
|
|
28
|
+
{
|
|
29
|
+
"name": "options",
|
|
30
|
+
"docs": "",
|
|
31
|
+
"type": "{ value: string; }"
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"returns": "Promise<{ value: string; }>",
|
|
35
|
+
"tags": [],
|
|
36
|
+
"docs": "",
|
|
37
|
+
"complexTypes": [],
|
|
38
|
+
"slug": "echo"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"name": "checkPermission",
|
|
42
|
+
"signature": "() => Promise<PermissionStatus>",
|
|
43
|
+
"parameters": [],
|
|
44
|
+
"returns": "Promise<PermissionStatus>",
|
|
45
|
+
"tags": [],
|
|
46
|
+
"docs": "",
|
|
47
|
+
"complexTypes": [
|
|
48
|
+
"PermissionStatus"
|
|
49
|
+
],
|
|
50
|
+
"slug": "checkpermission"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"name": "requestPermission",
|
|
54
|
+
"signature": "() => Promise<PermissionStatus>",
|
|
55
|
+
"parameters": [],
|
|
56
|
+
"returns": "Promise<PermissionStatus>",
|
|
57
|
+
"tags": [],
|
|
58
|
+
"docs": "",
|
|
59
|
+
"complexTypes": [
|
|
60
|
+
"PermissionStatus"
|
|
61
|
+
],
|
|
62
|
+
"slug": "requestpermission"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"name": "checkAndRequestPermission",
|
|
66
|
+
"signature": "() => Promise<PermissionStatus>",
|
|
67
|
+
"parameters": [],
|
|
68
|
+
"returns": "Promise<PermissionStatus>",
|
|
69
|
+
"tags": [],
|
|
70
|
+
"docs": "",
|
|
71
|
+
"complexTypes": [
|
|
72
|
+
"PermissionStatus"
|
|
73
|
+
],
|
|
74
|
+
"slug": "checkandrequestpermission"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"name": "getCameraCapabilities",
|
|
78
|
+
"signature": "() => Promise<CameraCapabilities>",
|
|
79
|
+
"parameters": [],
|
|
80
|
+
"returns": "Promise<CameraCapabilities>",
|
|
81
|
+
"tags": [],
|
|
82
|
+
"docs": "",
|
|
83
|
+
"complexTypes": [
|
|
84
|
+
"CameraCapabilities"
|
|
85
|
+
],
|
|
86
|
+
"slug": "getcameracapabilities"
|
|
23
87
|
}
|
|
24
88
|
],
|
|
25
89
|
"properties": []
|
|
26
90
|
},
|
|
27
|
-
"interfaces": [
|
|
91
|
+
"interfaces": [
|
|
92
|
+
{
|
|
93
|
+
"name": "PermissionStatus",
|
|
94
|
+
"slug": "permissionstatus",
|
|
95
|
+
"docs": "",
|
|
96
|
+
"tags": [],
|
|
97
|
+
"methods": [],
|
|
98
|
+
"properties": [
|
|
99
|
+
{
|
|
100
|
+
"name": "granted",
|
|
101
|
+
"tags": [],
|
|
102
|
+
"docs": "",
|
|
103
|
+
"complexTypes": [],
|
|
104
|
+
"type": "boolean"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"name": "status",
|
|
108
|
+
"tags": [],
|
|
109
|
+
"docs": "",
|
|
110
|
+
"complexTypes": [],
|
|
111
|
+
"type": "'granted' | 'denied' | 'prompt' | 'prompt-with-rationale' | 'limited'"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"name": "details",
|
|
115
|
+
"tags": [],
|
|
116
|
+
"docs": "",
|
|
117
|
+
"complexTypes": [],
|
|
118
|
+
"type": "string | undefined"
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"name": "CameraCapabilities",
|
|
124
|
+
"slug": "cameracapabilities",
|
|
125
|
+
"docs": "",
|
|
126
|
+
"tags": [],
|
|
127
|
+
"methods": [],
|
|
128
|
+
"properties": [
|
|
129
|
+
{
|
|
130
|
+
"name": "hasCamera",
|
|
131
|
+
"tags": [],
|
|
132
|
+
"docs": "",
|
|
133
|
+
"complexTypes": [],
|
|
134
|
+
"type": "boolean"
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"name": "isSecureContext",
|
|
138
|
+
"tags": [],
|
|
139
|
+
"docs": "",
|
|
140
|
+
"complexTypes": [],
|
|
141
|
+
"type": "boolean"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"name": "userAgent",
|
|
145
|
+
"tags": [],
|
|
146
|
+
"docs": "",
|
|
147
|
+
"complexTypes": [],
|
|
148
|
+
"type": "string"
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
}
|
|
152
|
+
],
|
|
28
153
|
"enums": [],
|
|
29
154
|
"typeAliases": [],
|
|
30
155
|
"pluginConfigs": []
|
|
@@ -4,4 +4,23 @@ export interface CameraModulePlugin {
|
|
|
4
4
|
}): Promise<{
|
|
5
5
|
value: string;
|
|
6
6
|
}>;
|
|
7
|
+
echo(options: {
|
|
8
|
+
value: string;
|
|
9
|
+
}): Promise<{
|
|
10
|
+
value: string;
|
|
11
|
+
}>;
|
|
12
|
+
checkPermission(): Promise<PermissionStatus>;
|
|
13
|
+
requestPermission(): Promise<PermissionStatus>;
|
|
14
|
+
checkAndRequestPermission(): Promise<PermissionStatus>;
|
|
15
|
+
getCameraCapabilities(): Promise<CameraCapabilities>;
|
|
16
|
+
}
|
|
17
|
+
export interface PermissionStatus {
|
|
18
|
+
granted: boolean;
|
|
19
|
+
status: 'granted' | 'denied' | 'prompt' | 'prompt-with-rationale' | 'limited';
|
|
20
|
+
details?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface CameraCapabilities {
|
|
23
|
+
hasCamera: boolean;
|
|
24
|
+
isSecureContext: boolean;
|
|
25
|
+
userAgent: string;
|
|
7
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface CameraModulePlugin {\n echo(options: { value: string }): Promise<{ value: string }>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface CameraModulePlugin {\n echo(options: { value: string }): Promise<{ value: string }>;\n\n echo(options: { value: string }): Promise<{ value: string }>;\n\n checkPermission(): Promise<PermissionStatus>;\n\n requestPermission(): Promise<PermissionStatus>;\n\n checkAndRequestPermission(): Promise<PermissionStatus>;\n\n getCameraCapabilities(): Promise<CameraCapabilities>;\n}\n\nexport interface PermissionStatus {\n granted: boolean;\n status: 'granted' | 'denied' | 'prompt' | 'prompt-with-rationale' | 'limited';\n details?: string;\n}\n\n\nexport interface CameraCapabilities {\n hasCamera: boolean;\n isSecureContext: boolean;\n userAgent: string;\n}"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
-
import type { CameraModulePlugin } from './definitions';
|
|
2
|
+
import type { CameraModulePlugin, PermissionStatus } from './definitions';
|
|
3
3
|
export declare class CameraModuleWeb extends WebPlugin implements CameraModulePlugin {
|
|
4
4
|
echo(options: {
|
|
5
5
|
value: string;
|
|
6
6
|
}): Promise<{
|
|
7
7
|
value: string;
|
|
8
8
|
}>;
|
|
9
|
+
checkPermission(): Promise<PermissionStatus>;
|
|
10
|
+
requestPermission(): Promise<PermissionStatus>;
|
|
11
|
+
checkAndRequestPermission(): Promise<PermissionStatus>;
|
|
12
|
+
getCameraCapabilities(): Promise<{
|
|
13
|
+
hasCamera: boolean;
|
|
14
|
+
isSecureContext: boolean;
|
|
15
|
+
userAgent: string;
|
|
16
|
+
}>;
|
|
9
17
|
}
|
package/dist/esm/web.js
CHANGED
|
@@ -4,5 +4,153 @@ export class CameraModuleWeb extends WebPlugin {
|
|
|
4
4
|
console.log('ECHO', options);
|
|
5
5
|
return options;
|
|
6
6
|
}
|
|
7
|
+
async checkPermission() {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
// Verificar disponibilidad de APIs - usando prefijo _ para variables no usadas
|
|
10
|
+
const hasMediaDevices = !!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.enumerateDevices);
|
|
11
|
+
const _hasGetUserMedia = !!((_b = navigator.mediaDevices) === null || _b === void 0 ? void 0 : _b.getUserMedia); // Prefijo _
|
|
12
|
+
if (!hasMediaDevices || !_hasGetUserMedia) {
|
|
13
|
+
throw this.unavailable('Camera API no disponible en este navegador');
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
17
|
+
const videoDevices = devices.filter((device) => device.kind === 'videoinput');
|
|
18
|
+
// No hay dispositivos de cámara
|
|
19
|
+
if (videoDevices.length === 0) {
|
|
20
|
+
return {
|
|
21
|
+
granted: false,
|
|
22
|
+
status: 'denied',
|
|
23
|
+
details: 'No camera devices found',
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
// Verificar si algún dispositivo tiene label (indica permiso)
|
|
27
|
+
const hasPermission = videoDevices.some((device) => device.label && device.label.trim() !== '');
|
|
28
|
+
// Determinar estado más preciso
|
|
29
|
+
let status = 'denied';
|
|
30
|
+
if (hasPermission) {
|
|
31
|
+
status = 'granted';
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
// En web, sin intentar getUserMedia, asumimos que es la primera vez
|
|
35
|
+
status = 'prompt';
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
granted: hasPermission,
|
|
39
|
+
status,
|
|
40
|
+
details: `Found ${videoDevices.length} camera device(s)`,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
console.error('Error checking camera permission:', error);
|
|
45
|
+
return {
|
|
46
|
+
granted: false,
|
|
47
|
+
status: 'denied',
|
|
48
|
+
details: error.message || 'Unknown error',
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async requestPermission() {
|
|
53
|
+
var _a;
|
|
54
|
+
// Verificar getUserMedia específicamente para este método
|
|
55
|
+
if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia)) {
|
|
56
|
+
throw this.unavailable('Camera API no disponible en este navegador');
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
// Intentar acceder a la cámara con configuración mínima
|
|
60
|
+
const stream = await navigator.mediaDevices.getUserMedia({
|
|
61
|
+
video: {
|
|
62
|
+
width: { ideal: 1280 },
|
|
63
|
+
height: { ideal: 720 },
|
|
64
|
+
facingMode: { ideal: 'environment' },
|
|
65
|
+
},
|
|
66
|
+
audio: false,
|
|
67
|
+
});
|
|
68
|
+
// Limpiar recursos inmediatamente
|
|
69
|
+
stream.getTracks().forEach((track) => {
|
|
70
|
+
track.stop();
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
granted: true,
|
|
74
|
+
status: 'granted',
|
|
75
|
+
details: 'Permission granted successfully',
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
console.error('Error requesting camera permission:', error);
|
|
80
|
+
// Manejo específico de errores
|
|
81
|
+
let status = 'denied';
|
|
82
|
+
let details = error.message || 'Unknown error';
|
|
83
|
+
if (error.name === 'NotAllowedError') {
|
|
84
|
+
status = 'denied';
|
|
85
|
+
details = 'User denied camera access';
|
|
86
|
+
}
|
|
87
|
+
else if (error.name === 'NotFoundError') {
|
|
88
|
+
status = 'denied';
|
|
89
|
+
details = 'No camera found';
|
|
90
|
+
}
|
|
91
|
+
else if (error.name === 'NotReadableError') {
|
|
92
|
+
status = 'denied';
|
|
93
|
+
details = 'Camera is already in use';
|
|
94
|
+
}
|
|
95
|
+
else if (error.name === 'OverconstrainedError') {
|
|
96
|
+
status = 'denied';
|
|
97
|
+
details = 'Camera constraints cannot be met';
|
|
98
|
+
}
|
|
99
|
+
else if (error.name === 'SecurityError') {
|
|
100
|
+
status = 'denied';
|
|
101
|
+
details = 'Camera access blocked by browser security settings';
|
|
102
|
+
}
|
|
103
|
+
else if (error.name === 'TypeError') {
|
|
104
|
+
status = 'denied';
|
|
105
|
+
details = 'Invalid constraints specified';
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
granted: false,
|
|
109
|
+
status,
|
|
110
|
+
details,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async checkAndRequestPermission() {
|
|
115
|
+
try {
|
|
116
|
+
// Primero verificar el estado actual
|
|
117
|
+
const currentStatus = await this.checkPermission();
|
|
118
|
+
// Si ya tiene permiso, retornar inmediatamente
|
|
119
|
+
if (currentStatus.granted) {
|
|
120
|
+
return currentStatus;
|
|
121
|
+
}
|
|
122
|
+
// Si no tiene permiso, solicitar
|
|
123
|
+
return await this.requestPermission();
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
console.error('Error in checkAndRequestPermission:', error);
|
|
127
|
+
return {
|
|
128
|
+
granted: false,
|
|
129
|
+
status: 'denied',
|
|
130
|
+
details: 'Failed to check or request permission',
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// Método adicional para verificar soporte de características
|
|
135
|
+
async getCameraCapabilities() {
|
|
136
|
+
var _a, _b;
|
|
137
|
+
const hasMediaDevices = !!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.enumerateDevices);
|
|
138
|
+
const hasGetUserMedia = !!((_b = navigator.mediaDevices) === null || _b === void 0 ? void 0 : _b.getUserMedia);
|
|
139
|
+
let hasCamera = false;
|
|
140
|
+
if (hasMediaDevices || hasGetUserMedia) {
|
|
141
|
+
try {
|
|
142
|
+
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
143
|
+
hasCamera = devices.some((device) => device.kind === 'videoinput');
|
|
144
|
+
}
|
|
145
|
+
catch (_c) {
|
|
146
|
+
hasCamera = false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
hasCamera,
|
|
151
|
+
isSecureContext: window.isSecureContext,
|
|
152
|
+
userAgent: navigator.userAgent,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
7
155
|
}
|
|
8
156
|
//# 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;AAI5C,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,KAAK,CAAC,IAAI,CAAC,OAA0B;QACnC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC7B,OAAO,OAAO,CAAC;IACjB,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { CameraModulePlugin } from './definitions';\n\nexport class CameraModuleWeb extends WebPlugin implements CameraModulePlugin {\n async echo(options: { value: string }): Promise<{ value: string }> {\n console.log('ECHO', options);\n return options;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,KAAK,CAAC,IAAI,CAAC,OAA0B;QACnC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC7B,OAAO,OA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AAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE,KAAK,CAAC,CAAC;YAC5D,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,QAAQ;gBAChB,OAAO,EAAE,uCAAuC;aACjD,CAAC;QACJ,CAAC;IACH,CAAC;IAED,6DAA6D;IAC7D,KAAK,CAAC,qBAAqB;;QAKzB,MAAM,eAAe,GAAG,CAAC,CAAC,CAAA,MAAA,SAAS,CAAC,YAAY,0CAAE,gBAAgB,CAAA,CAAC;QACnE,MAAM,eAAe,GAAG,CAAC,CAAC,CAAA,MAAA,SAAS,CAAC,YAAY,0CAAE,YAAY,CAAA,CAAC;QAE/D,IAAI,SAAS,GAAG,KAAK,CAAC;QAEtB,IAAI,eAAe,IAAI,eAAe,EAAE,CAAC;YACvC,IAAI,CAAC;gBACH,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,gBAAgB,EAAE,CAAC;gBAChE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC;YACrE,CAAC;YAAC,WAAM,CAAC;gBACP,SAAS,GAAG,KAAK,CAAC;YACpB,CAAC;QACH,CAAC;QAED,OAAO;YACL,SAAS;YACT,eAAe,EAAE,MAAM,CAAC,eAAe;YACvC,SAAS,EAAE,SAAS,CAAC,SAAS;SAC/B,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { CameraModulePlugin, PermissionStatus } from './definitions';\n\nexport class CameraModuleWeb extends WebPlugin implements CameraModulePlugin {\n async echo(options: { value: string }): Promise<{ value: string }> {\n console.log('ECHO', options);\n return options;\n }\n\n async checkPermission(): Promise<PermissionStatus> {\n // Verificar disponibilidad de APIs - usando prefijo _ para variables no usadas\n const hasMediaDevices = !!navigator.mediaDevices?.enumerateDevices;\n const _hasGetUserMedia = !!navigator.mediaDevices?.getUserMedia; // Prefijo _\n\n if (!hasMediaDevices || !_hasGetUserMedia) {\n throw this.unavailable('Camera API no disponible en este navegador');\n }\n\n try {\n const devices = await navigator.mediaDevices.enumerateDevices();\n const videoDevices = devices.filter((device) => device.kind === 'videoinput');\n\n // No hay dispositivos de cámara\n if (videoDevices.length === 0) {\n return {\n granted: false,\n status: 'denied',\n details: 'No camera devices found',\n };\n }\n\n // Verificar si algún dispositivo tiene label (indica permiso)\n const hasPermission = videoDevices.some((device) => device.label && device.label.trim() !== '');\n\n // Determinar estado más preciso\n let status: PermissionStatus['status'] = 'denied';\n if (hasPermission) {\n status = 'granted';\n } else {\n // En web, sin intentar getUserMedia, asumimos que es la primera vez\n status = 'prompt';\n }\n\n return {\n granted: hasPermission,\n status,\n details: `Found ${videoDevices.length} camera device(s)`,\n };\n } catch (error: any) {\n console.error('Error checking camera permission:', error);\n return {\n granted: false,\n status: 'denied',\n details: error.message || 'Unknown error',\n };\n }\n }\n\n async requestPermission(): Promise<PermissionStatus> {\n // Verificar getUserMedia específicamente para este método\n if (!navigator.mediaDevices?.getUserMedia) {\n throw this.unavailable('Camera API no disponible en este navegador');\n }\n\n try {\n // Intentar acceder a la cámara con configuración mínima\n const stream = await navigator.mediaDevices.getUserMedia({\n video: {\n width: { ideal: 1280 },\n height: { ideal: 720 },\n facingMode: { ideal: 'environment' },\n },\n audio: false,\n });\n\n // Limpiar recursos inmediatamente\n stream.getTracks().forEach((track) => {\n track.stop();\n });\n\n return {\n granted: true,\n status: 'granted',\n details: 'Permission granted successfully',\n };\n } catch (error: any) {\n console.error('Error requesting camera permission:', error);\n\n // Manejo específico de errores\n let status: PermissionStatus['status'] = 'denied';\n let details = error.message || 'Unknown error';\n\n if (error.name === 'NotAllowedError') {\n status = 'denied';\n details = 'User denied camera access';\n } else if (error.name === 'NotFoundError') {\n status = 'denied';\n details = 'No camera found';\n } else if (error.name === 'NotReadableError') {\n status = 'denied';\n details = 'Camera is already in use';\n } else if (error.name === 'OverconstrainedError') {\n status = 'denied';\n details = 'Camera constraints cannot be met';\n } else if (error.name === 'SecurityError') {\n status = 'denied';\n details = 'Camera access blocked by browser security settings';\n } else if (error.name === 'TypeError') {\n status = 'denied';\n details = 'Invalid constraints specified';\n }\n\n return {\n granted: false,\n status,\n details,\n };\n }\n }\n\n async checkAndRequestPermission(): Promise<PermissionStatus> {\n try {\n // Primero verificar el estado actual\n const currentStatus = await this.checkPermission();\n\n // Si ya tiene permiso, retornar inmediatamente\n if (currentStatus.granted) {\n return currentStatus;\n }\n\n // Si no tiene permiso, solicitar\n return await this.requestPermission();\n } catch (error) {\n console.error('Error in checkAndRequestPermission:', error);\n return {\n granted: false,\n status: 'denied',\n details: 'Failed to check or request permission',\n };\n }\n }\n\n // Método adicional para verificar soporte de características\n async getCameraCapabilities(): Promise<{\n hasCamera: boolean;\n isSecureContext: boolean;\n userAgent: string;\n }> {\n const hasMediaDevices = !!navigator.mediaDevices?.enumerateDevices;\n const hasGetUserMedia = !!navigator.mediaDevices?.getUserMedia;\n\n let hasCamera = false;\n\n if (hasMediaDevices || hasGetUserMedia) {\n try {\n const devices = await navigator.mediaDevices.enumerateDevices();\n hasCamera = devices.some((device) => device.kind === 'videoinput');\n } catch {\n hasCamera = false;\n }\n }\n\n return {\n hasCamera,\n isSecureContext: window.isSecureContext,\n userAgent: navigator.userAgent,\n };\n }\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -11,6 +11,154 @@ class CameraModuleWeb extends core.WebPlugin {
|
|
|
11
11
|
console.log('ECHO', options);
|
|
12
12
|
return options;
|
|
13
13
|
}
|
|
14
|
+
async checkPermission() {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
// Verificar disponibilidad de APIs - usando prefijo _ para variables no usadas
|
|
17
|
+
const hasMediaDevices = !!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.enumerateDevices);
|
|
18
|
+
const _hasGetUserMedia = !!((_b = navigator.mediaDevices) === null || _b === void 0 ? void 0 : _b.getUserMedia); // Prefijo _
|
|
19
|
+
if (!hasMediaDevices || !_hasGetUserMedia) {
|
|
20
|
+
throw this.unavailable('Camera API no disponible en este navegador');
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
24
|
+
const videoDevices = devices.filter((device) => device.kind === 'videoinput');
|
|
25
|
+
// No hay dispositivos de cámara
|
|
26
|
+
if (videoDevices.length === 0) {
|
|
27
|
+
return {
|
|
28
|
+
granted: false,
|
|
29
|
+
status: 'denied',
|
|
30
|
+
details: 'No camera devices found',
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
// Verificar si algún dispositivo tiene label (indica permiso)
|
|
34
|
+
const hasPermission = videoDevices.some((device) => device.label && device.label.trim() !== '');
|
|
35
|
+
// Determinar estado más preciso
|
|
36
|
+
let status = 'denied';
|
|
37
|
+
if (hasPermission) {
|
|
38
|
+
status = 'granted';
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// En web, sin intentar getUserMedia, asumimos que es la primera vez
|
|
42
|
+
status = 'prompt';
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
granted: hasPermission,
|
|
46
|
+
status,
|
|
47
|
+
details: `Found ${videoDevices.length} camera device(s)`,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.error('Error checking camera permission:', error);
|
|
52
|
+
return {
|
|
53
|
+
granted: false,
|
|
54
|
+
status: 'denied',
|
|
55
|
+
details: error.message || 'Unknown error',
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async requestPermission() {
|
|
60
|
+
var _a;
|
|
61
|
+
// Verificar getUserMedia específicamente para este método
|
|
62
|
+
if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia)) {
|
|
63
|
+
throw this.unavailable('Camera API no disponible en este navegador');
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
// Intentar acceder a la cámara con configuración mínima
|
|
67
|
+
const stream = await navigator.mediaDevices.getUserMedia({
|
|
68
|
+
video: {
|
|
69
|
+
width: { ideal: 1280 },
|
|
70
|
+
height: { ideal: 720 },
|
|
71
|
+
facingMode: { ideal: 'environment' },
|
|
72
|
+
},
|
|
73
|
+
audio: false,
|
|
74
|
+
});
|
|
75
|
+
// Limpiar recursos inmediatamente
|
|
76
|
+
stream.getTracks().forEach((track) => {
|
|
77
|
+
track.stop();
|
|
78
|
+
});
|
|
79
|
+
return {
|
|
80
|
+
granted: true,
|
|
81
|
+
status: 'granted',
|
|
82
|
+
details: 'Permission granted successfully',
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
console.error('Error requesting camera permission:', error);
|
|
87
|
+
// Manejo específico de errores
|
|
88
|
+
let status = 'denied';
|
|
89
|
+
let details = error.message || 'Unknown error';
|
|
90
|
+
if (error.name === 'NotAllowedError') {
|
|
91
|
+
status = 'denied';
|
|
92
|
+
details = 'User denied camera access';
|
|
93
|
+
}
|
|
94
|
+
else if (error.name === 'NotFoundError') {
|
|
95
|
+
status = 'denied';
|
|
96
|
+
details = 'No camera found';
|
|
97
|
+
}
|
|
98
|
+
else if (error.name === 'NotReadableError') {
|
|
99
|
+
status = 'denied';
|
|
100
|
+
details = 'Camera is already in use';
|
|
101
|
+
}
|
|
102
|
+
else if (error.name === 'OverconstrainedError') {
|
|
103
|
+
status = 'denied';
|
|
104
|
+
details = 'Camera constraints cannot be met';
|
|
105
|
+
}
|
|
106
|
+
else if (error.name === 'SecurityError') {
|
|
107
|
+
status = 'denied';
|
|
108
|
+
details = 'Camera access blocked by browser security settings';
|
|
109
|
+
}
|
|
110
|
+
else if (error.name === 'TypeError') {
|
|
111
|
+
status = 'denied';
|
|
112
|
+
details = 'Invalid constraints specified';
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
granted: false,
|
|
116
|
+
status,
|
|
117
|
+
details,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async checkAndRequestPermission() {
|
|
122
|
+
try {
|
|
123
|
+
// Primero verificar el estado actual
|
|
124
|
+
const currentStatus = await this.checkPermission();
|
|
125
|
+
// Si ya tiene permiso, retornar inmediatamente
|
|
126
|
+
if (currentStatus.granted) {
|
|
127
|
+
return currentStatus;
|
|
128
|
+
}
|
|
129
|
+
// Si no tiene permiso, solicitar
|
|
130
|
+
return await this.requestPermission();
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
console.error('Error in checkAndRequestPermission:', error);
|
|
134
|
+
return {
|
|
135
|
+
granted: false,
|
|
136
|
+
status: 'denied',
|
|
137
|
+
details: 'Failed to check or request permission',
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// Método adicional para verificar soporte de características
|
|
142
|
+
async getCameraCapabilities() {
|
|
143
|
+
var _a, _b;
|
|
144
|
+
const hasMediaDevices = !!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.enumerateDevices);
|
|
145
|
+
const hasGetUserMedia = !!((_b = navigator.mediaDevices) === null || _b === void 0 ? void 0 : _b.getUserMedia);
|
|
146
|
+
let hasCamera = false;
|
|
147
|
+
if (hasMediaDevices || hasGetUserMedia) {
|
|
148
|
+
try {
|
|
149
|
+
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
150
|
+
hasCamera = devices.some((device) => device.kind === 'videoinput');
|
|
151
|
+
}
|
|
152
|
+
catch (_c) {
|
|
153
|
+
hasCamera = false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
hasCamera,
|
|
158
|
+
isSecureContext: window.isSecureContext,
|
|
159
|
+
userAgent: navigator.userAgent,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
14
162
|
}
|
|
15
163
|
|
|
16
164
|
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 CameraModule = registerPlugin('CameraModule', {\n web: () => import('./web').then((m) => new m.CameraModuleWeb()),\n});\nexport * from './definitions';\nexport { CameraModule };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CameraModuleWeb extends WebPlugin {\n async echo(options) {\n console.log('ECHO', options);\n return options;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;AACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;AACnE,CAAC;;ACFM,MAAM,eAAe,SAASC,cAAS,CAAC;AAC/C,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;AACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;AACpC,QAAQ,OAAO,OAAO;AACtB,IAAI;AACJ;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CameraModule = registerPlugin('CameraModule', {\n web: () => import('./web').then((m) => new m.CameraModuleWeb()),\n});\nexport * from './definitions';\nexport { CameraModule };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CameraModuleWeb extends WebPlugin {\n async echo(options) {\n console.log('ECHO', options);\n return options;\n }\n async checkPermission() {\n var _a, _b;\n // Verificar disponibilidad de APIs - usando prefijo _ para variables no usadas\n const hasMediaDevices = !!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.enumerateDevices);\n const _hasGetUserMedia = !!((_b = navigator.mediaDevices) === null || _b === void 0 ? void 0 : _b.getUserMedia); // Prefijo _\n if (!hasMediaDevices || !_hasGetUserMedia) {\n throw this.unavailable('Camera API no disponible en este navegador');\n }\n try {\n const devices = await navigator.mediaDevices.enumerateDevices();\n const videoDevices = devices.filter((device) => device.kind === 'videoinput');\n // No hay dispositivos de cámara\n if (videoDevices.length === 0) {\n return {\n granted: false,\n status: 'denied',\n details: 'No camera devices found',\n };\n }\n // Verificar si algún dispositivo tiene label (indica permiso)\n const hasPermission = videoDevices.some((device) => device.label && device.label.trim() !== '');\n // Determinar estado más preciso\n let status = 'denied';\n if (hasPermission) {\n status = 'granted';\n }\n else {\n // En web, sin intentar getUserMedia, asumimos que es la primera vez\n status = 'prompt';\n }\n return {\n granted: hasPermission,\n status,\n details: `Found ${videoDevices.length} camera device(s)`,\n };\n }\n catch (error) {\n console.error('Error checking camera permission:', error);\n return {\n granted: false,\n status: 'denied',\n details: error.message || 'Unknown error',\n };\n }\n }\n async requestPermission() {\n var _a;\n // Verificar getUserMedia específicamente para este método\n if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia)) {\n throw this.unavailable('Camera API no disponible en este navegador');\n }\n try {\n // Intentar acceder a la cámara con configuración mínima\n const stream = await navigator.mediaDevices.getUserMedia({\n video: {\n width: { ideal: 1280 },\n height: { ideal: 720 },\n facingMode: { ideal: 'environment' },\n },\n audio: false,\n });\n // Limpiar recursos inmediatamente\n stream.getTracks().forEach((track) => {\n track.stop();\n });\n return {\n granted: true,\n status: 'granted',\n details: 'Permission granted successfully',\n };\n }\n catch (error) {\n console.error('Error requesting camera permission:', error);\n // Manejo específico de errores\n let status = 'denied';\n let details = error.message || 'Unknown error';\n if (error.name === 'NotAllowedError') {\n status = 'denied';\n details = 'User denied camera access';\n }\n else if (error.name === 'NotFoundError') {\n status = 'denied';\n details = 'No camera found';\n }\n else if (error.name === 'NotReadableError') {\n status = 'denied';\n details = 'Camera is already in use';\n }\n else if (error.name === 'OverconstrainedError') {\n status = 'denied';\n details = 'Camera constraints cannot be met';\n }\n else if (error.name === 'SecurityError') {\n status = 'denied';\n details = 'Camera access blocked by browser security settings';\n }\n else if (error.name === 'TypeError') {\n status = 'denied';\n details = 'Invalid constraints specified';\n }\n return {\n granted: false,\n status,\n details,\n };\n }\n }\n async checkAndRequestPermission() {\n try {\n // Primero verificar el estado actual\n const currentStatus = await this.checkPermission();\n // Si ya tiene permiso, retornar inmediatamente\n if (currentStatus.granted) {\n return currentStatus;\n }\n // Si no tiene permiso, solicitar\n return await this.requestPermission();\n }\n catch (error) {\n console.error('Error in checkAndRequestPermission:', error);\n return {\n granted: false,\n status: 'denied',\n details: 'Failed to check or request permission',\n };\n }\n }\n // Método adicional para verificar soporte de características\n async getCameraCapabilities() {\n var _a, _b;\n const hasMediaDevices = !!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.enumerateDevices);\n const hasGetUserMedia = !!((_b = navigator.mediaDevices) === null || _b === void 0 ? void 0 : _b.getUserMedia);\n let hasCamera = false;\n if (hasMediaDevices || hasGetUserMedia) {\n try {\n const devices = await navigator.mediaDevices.enumerateDevices();\n hasCamera = devices.some((device) => device.kind === 'videoinput');\n }\n catch (_c) {\n hasCamera = false;\n }\n }\n return {\n hasCamera,\n isSecureContext: window.isSecureContext,\n userAgent: navigator.userAgent,\n };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;AACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;AACnE,CAAC;;ACFM,MAAM,eAAe,SAASC,cAAS,CAAC;AAC/C,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;AACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;AACpC,QAAQ,OAAO,OAAO;AACtB,IAAI;AACJ,IA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,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,KAAK,YAAY,CAAC;AAClF,YAAY;AACZ,YAAY,OAAO,EAAE,EAAE;AACvB,gBAAgB,SAAS,GAAG,KAAK;AACjC,YAAY;AACZ,QAAQ;AACR,QAAQ,OAAO;AACf,YAAY,SAAS;AACrB,YAAY,eAAe,EAAE,MAAM,CAAC,eAAe;AACnD,YAAY,SAAS,EAAE,SAAS,CAAC,SAAS;AAC1C,SAAS;AACT,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -10,6 +10,154 @@ var capacitorCameraModule = (function (exports, core) {
|
|
|
10
10
|
console.log('ECHO', options);
|
|
11
11
|
return options;
|
|
12
12
|
}
|
|
13
|
+
async checkPermission() {
|
|
14
|
+
var _a, _b;
|
|
15
|
+
// Verificar disponibilidad de APIs - usando prefijo _ para variables no usadas
|
|
16
|
+
const hasMediaDevices = !!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.enumerateDevices);
|
|
17
|
+
const _hasGetUserMedia = !!((_b = navigator.mediaDevices) === null || _b === void 0 ? void 0 : _b.getUserMedia); // Prefijo _
|
|
18
|
+
if (!hasMediaDevices || !_hasGetUserMedia) {
|
|
19
|
+
throw this.unavailable('Camera API no disponible en este navegador');
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
23
|
+
const videoDevices = devices.filter((device) => device.kind === 'videoinput');
|
|
24
|
+
// No hay dispositivos de cámara
|
|
25
|
+
if (videoDevices.length === 0) {
|
|
26
|
+
return {
|
|
27
|
+
granted: false,
|
|
28
|
+
status: 'denied',
|
|
29
|
+
details: 'No camera devices found',
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// Verificar si algún dispositivo tiene label (indica permiso)
|
|
33
|
+
const hasPermission = videoDevices.some((device) => device.label && device.label.trim() !== '');
|
|
34
|
+
// Determinar estado más preciso
|
|
35
|
+
let status = 'denied';
|
|
36
|
+
if (hasPermission) {
|
|
37
|
+
status = 'granted';
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// En web, sin intentar getUserMedia, asumimos que es la primera vez
|
|
41
|
+
status = 'prompt';
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
granted: hasPermission,
|
|
45
|
+
status,
|
|
46
|
+
details: `Found ${videoDevices.length} camera device(s)`,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
console.error('Error checking camera permission:', error);
|
|
51
|
+
return {
|
|
52
|
+
granted: false,
|
|
53
|
+
status: 'denied',
|
|
54
|
+
details: error.message || 'Unknown error',
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async requestPermission() {
|
|
59
|
+
var _a;
|
|
60
|
+
// Verificar getUserMedia específicamente para este método
|
|
61
|
+
if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia)) {
|
|
62
|
+
throw this.unavailable('Camera API no disponible en este navegador');
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
// Intentar acceder a la cámara con configuración mínima
|
|
66
|
+
const stream = await navigator.mediaDevices.getUserMedia({
|
|
67
|
+
video: {
|
|
68
|
+
width: { ideal: 1280 },
|
|
69
|
+
height: { ideal: 720 },
|
|
70
|
+
facingMode: { ideal: 'environment' },
|
|
71
|
+
},
|
|
72
|
+
audio: false,
|
|
73
|
+
});
|
|
74
|
+
// Limpiar recursos inmediatamente
|
|
75
|
+
stream.getTracks().forEach((track) => {
|
|
76
|
+
track.stop();
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
granted: true,
|
|
80
|
+
status: 'granted',
|
|
81
|
+
details: 'Permission granted successfully',
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
console.error('Error requesting camera permission:', error);
|
|
86
|
+
// Manejo específico de errores
|
|
87
|
+
let status = 'denied';
|
|
88
|
+
let details = error.message || 'Unknown error';
|
|
89
|
+
if (error.name === 'NotAllowedError') {
|
|
90
|
+
status = 'denied';
|
|
91
|
+
details = 'User denied camera access';
|
|
92
|
+
}
|
|
93
|
+
else if (error.name === 'NotFoundError') {
|
|
94
|
+
status = 'denied';
|
|
95
|
+
details = 'No camera found';
|
|
96
|
+
}
|
|
97
|
+
else if (error.name === 'NotReadableError') {
|
|
98
|
+
status = 'denied';
|
|
99
|
+
details = 'Camera is already in use';
|
|
100
|
+
}
|
|
101
|
+
else if (error.name === 'OverconstrainedError') {
|
|
102
|
+
status = 'denied';
|
|
103
|
+
details = 'Camera constraints cannot be met';
|
|
104
|
+
}
|
|
105
|
+
else if (error.name === 'SecurityError') {
|
|
106
|
+
status = 'denied';
|
|
107
|
+
details = 'Camera access blocked by browser security settings';
|
|
108
|
+
}
|
|
109
|
+
else if (error.name === 'TypeError') {
|
|
110
|
+
status = 'denied';
|
|
111
|
+
details = 'Invalid constraints specified';
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
granted: false,
|
|
115
|
+
status,
|
|
116
|
+
details,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async checkAndRequestPermission() {
|
|
121
|
+
try {
|
|
122
|
+
// Primero verificar el estado actual
|
|
123
|
+
const currentStatus = await this.checkPermission();
|
|
124
|
+
// Si ya tiene permiso, retornar inmediatamente
|
|
125
|
+
if (currentStatus.granted) {
|
|
126
|
+
return currentStatus;
|
|
127
|
+
}
|
|
128
|
+
// Si no tiene permiso, solicitar
|
|
129
|
+
return await this.requestPermission();
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
console.error('Error in checkAndRequestPermission:', error);
|
|
133
|
+
return {
|
|
134
|
+
granted: false,
|
|
135
|
+
status: 'denied',
|
|
136
|
+
details: 'Failed to check or request permission',
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Método adicional para verificar soporte de características
|
|
141
|
+
async getCameraCapabilities() {
|
|
142
|
+
var _a, _b;
|
|
143
|
+
const hasMediaDevices = !!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.enumerateDevices);
|
|
144
|
+
const hasGetUserMedia = !!((_b = navigator.mediaDevices) === null || _b === void 0 ? void 0 : _b.getUserMedia);
|
|
145
|
+
let hasCamera = false;
|
|
146
|
+
if (hasMediaDevices || hasGetUserMedia) {
|
|
147
|
+
try {
|
|
148
|
+
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
149
|
+
hasCamera = devices.some((device) => device.kind === 'videoinput');
|
|
150
|
+
}
|
|
151
|
+
catch (_c) {
|
|
152
|
+
hasCamera = false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
hasCamera,
|
|
157
|
+
isSecureContext: window.isSecureContext,
|
|
158
|
+
userAgent: navigator.userAgent,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
13
161
|
}
|
|
14
162
|
|
|
15
163
|
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 CameraModule = registerPlugin('CameraModule', {\n web: () => import('./web').then((m) => new m.CameraModuleWeb()),\n});\nexport * from './definitions';\nexport { CameraModule };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CameraModuleWeb extends WebPlugin {\n async echo(options) {\n console.log('ECHO', options);\n return options;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;IACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;IACnE,CAAC;;ICFM,MAAM,eAAe,SAASC,cAAS,CAAC;IAC/C,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;IACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IACpC,QAAQ,OAAO,OAAO;IACtB,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CameraModule = registerPlugin('CameraModule', {\n web: () => import('./web').then((m) => new m.CameraModuleWeb()),\n});\nexport * from './definitions';\nexport { CameraModule };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CameraModuleWeb extends WebPlugin {\n async echo(options) {\n console.log('ECHO', options);\n return options;\n }\n async checkPermission() {\n var _a, _b;\n // Verificar disponibilidad de APIs - usando prefijo _ para variables no usadas\n const hasMediaDevices = !!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.enumerateDevices);\n const _hasGetUserMedia = !!((_b = navigator.mediaDevices) === null || _b === void 0 ? void 0 : _b.getUserMedia); // Prefijo _\n if (!hasMediaDevices || !_hasGetUserMedia) {\n throw this.unavailable('Camera API no disponible en este navegador');\n }\n try {\n const devices = await navigator.mediaDevices.enumerateDevices();\n const videoDevices = devices.filter((device) => device.kind === 'videoinput');\n // No hay dispositivos de cámara\n if (videoDevices.length === 0) {\n return {\n granted: false,\n status: 'denied',\n details: 'No camera devices found',\n };\n }\n // Verificar si algún dispositivo tiene label (indica permiso)\n const hasPermission = videoDevices.some((device) => device.label && device.label.trim() !== '');\n // Determinar estado más preciso\n let status = 'denied';\n if (hasPermission) {\n status = 'granted';\n }\n else {\n // En web, sin intentar getUserMedia, asumimos que es la primera vez\n status = 'prompt';\n }\n return {\n granted: hasPermission,\n status,\n details: `Found ${videoDevices.length} camera device(s)`,\n };\n }\n catch (error) {\n console.error('Error checking camera permission:', error);\n return {\n granted: false,\n status: 'denied',\n details: error.message || 'Unknown error',\n };\n }\n }\n async requestPermission() {\n var _a;\n // Verificar getUserMedia específicamente para este método\n if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia)) {\n throw this.unavailable('Camera API no disponible en este navegador');\n }\n try {\n // Intentar acceder a la cámara con configuración mínima\n const stream = await navigator.mediaDevices.getUserMedia({\n video: {\n width: { ideal: 1280 },\n height: { ideal: 720 },\n facingMode: { ideal: 'environment' },\n },\n audio: false,\n });\n // Limpiar recursos inmediatamente\n stream.getTracks().forEach((track) => {\n track.stop();\n });\n return {\n granted: true,\n status: 'granted',\n details: 'Permission granted successfully',\n };\n }\n catch (error) {\n console.error('Error requesting camera permission:', error);\n // Manejo específico de errores\n let status = 'denied';\n let details = error.message || 'Unknown error';\n if (error.name === 'NotAllowedError') {\n status = 'denied';\n details = 'User denied camera access';\n }\n else if (error.name === 'NotFoundError') {\n status = 'denied';\n details = 'No camera found';\n }\n else if (error.name === 'NotReadableError') {\n status = 'denied';\n details = 'Camera is already in use';\n }\n else if (error.name === 'OverconstrainedError') {\n status = 'denied';\n details = 'Camera constraints cannot be met';\n }\n else if (error.name === 'SecurityError') {\n status = 'denied';\n details = 'Camera access blocked by browser security settings';\n }\n else if (error.name === 'TypeError') {\n status = 'denied';\n details = 'Invalid constraints specified';\n }\n return {\n granted: false,\n status,\n details,\n };\n }\n }\n async checkAndRequestPermission() {\n try {\n // Primero verificar el estado actual\n const currentStatus = await this.checkPermission();\n // Si ya tiene permiso, retornar inmediatamente\n if (currentStatus.granted) {\n return currentStatus;\n }\n // Si no tiene permiso, solicitar\n return await this.requestPermission();\n }\n catch (error) {\n console.error('Error in checkAndRequestPermission:', error);\n return {\n granted: false,\n status: 'denied',\n details: 'Failed to check or request permission',\n };\n }\n }\n // Método adicional para verificar soporte de características\n async getCameraCapabilities() {\n var _a, _b;\n const hasMediaDevices = !!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.enumerateDevices);\n const hasGetUserMedia = !!((_b = navigator.mediaDevices) === null || _b === void 0 ? void 0 : _b.getUserMedia);\n let hasCamera = false;\n if (hasMediaDevices || hasGetUserMedia) {\n try {\n const devices = await navigator.mediaDevices.enumerateDevices();\n hasCamera = devices.some((device) => device.kind === 'videoinput');\n }\n catch (_c) {\n hasCamera = false;\n }\n }\n return {\n hasCamera,\n isSecureContext: window.isSecureContext,\n userAgent: navigator.userAgent,\n };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;IACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;IACnE,CAAC;;ICFM,MAAM,eAAe,SAASC,cAAS,CAAC;IAC/C,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;IACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IACpC,QAAQ,OAAO,OAAO;IACtB,IAAI;IACJ,IAAI,MAAM,eAAe,GAAG;IAC5B,QAAQ,IAAI,EAAE,EAAE,EAAE;IAClB;IACA,QAAQ,MAAM,eAAe,GAAG,CAAC,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,YAAY,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,MAAM,GAAG,EAAE,CAAC,gBAAgB,CAAC;IAC1H,QAAQ,MAAM,gBAAgB,GAAG,CAAC,EAAE,CAAC,EAAE,GAAG,SAAS,CAAC,YAAY,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,CAAC;IACxH,QAAQ,IAAI,CAAC,eAAe,IAAI,CAAC,gBAAgB,EAAE;IACnD,YAAY,MAAM,IAAI,CAAC,WAAW,CAAC,4CAA4C,CAAC;IAChF,QAAQ;IACR,QAAQ,IAAI;IACZ,YAAY,MAAM,OAAO,G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