@capgo/camera-preview 6.1.6 → 6.1.10

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 CHANGED
@@ -74,6 +74,17 @@ Add `import '@capgo/camera-preview'` to you entry script in ionic on `app.module
74
74
 
75
75
  <docgen-index>
76
76
 
77
+ * [`start(...)`](#start)
78
+ * [`stop()`](#stop)
79
+ * [`capture(...)`](#capture)
80
+ * [`captureSample(...)`](#capturesample)
81
+ * [`getSupportedFlashModes()`](#getsupportedflashmodes)
82
+ * [`getHorizontalFov()`](#gethorizontalfov)
83
+ * [`setFlashMode(...)`](#setflashmode)
84
+ * [`flip()`](#flip)
85
+ * [`setOpacity(...)`](#setopacity)
86
+ * [`stopRecordVideo()`](#stoprecordvideo)
87
+ * [`startRecordVideo(...)`](#startrecordvideo)
77
88
  * [Interfaces](#interfaces)
78
89
  * [Type Aliases](#type-aliases)
79
90
 
@@ -82,6 +93,195 @@ Add `import '@capgo/camera-preview'` to you entry script in ionic on `app.module
82
93
  <docgen-api>
83
94
  <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
84
95
 
96
+ ### start(...)
97
+
98
+ ```typescript
99
+ start(options: CameraPreviewOptions) => any
100
+ ```
101
+
102
+ Start the camera preview instance.
103
+
104
+ | Param | Type | Description |
105
+ | ------------- | --------------------------------------------------------------------- | -------------------------------------------- |
106
+ | **`options`** | <code><a href="#camerapreviewoptions">CameraPreviewOptions</a></code> | the options to start the camera preview with |
107
+
108
+ **Returns:** <code>any</code>
109
+
110
+ **Since:** 0.0.1
111
+
112
+ --------------------
113
+
114
+
115
+ ### stop()
116
+
117
+ ```typescript
118
+ stop() => any
119
+ ```
120
+
121
+ Stop the camera preview instance.
122
+
123
+ **Returns:** <code>any</code>
124
+
125
+ **Since:** 0.0.1
126
+
127
+ --------------------
128
+
129
+
130
+ ### capture(...)
131
+
132
+ ```typescript
133
+ capture(options: CameraPreviewPictureOptions) => any
134
+ ```
135
+
136
+ Switch camera.
137
+
138
+ | Param | Type | Description |
139
+ | ------------- | ----------------------------------------------------------------------------------- | ------------------------------------- |
140
+ | **`options`** | <code><a href="#camerapreviewpictureoptions">CameraPreviewPictureOptions</a></code> | the options to switch the camera with |
141
+
142
+ **Returns:** <code>any</code>
143
+
144
+ **Since:** 0.0.1
145
+
146
+ --------------------
147
+
148
+
149
+ ### captureSample(...)
150
+
151
+ ```typescript
152
+ captureSample(options: CameraSampleOptions) => any
153
+ ```
154
+
155
+ Capture a sample image.
156
+
157
+ | Param | Type | Description |
158
+ | ------------- | ------------------------------------------------------------------- | -------------------------------------------- |
159
+ | **`options`** | <code><a href="#camerasampleoptions">CameraSampleOptions</a></code> | the options to capture the sample image with |
160
+
161
+ **Returns:** <code>any</code>
162
+
163
+ **Since:** 0.0.1
164
+
165
+ --------------------
166
+
167
+
168
+ ### getSupportedFlashModes()
169
+
170
+ ```typescript
171
+ getSupportedFlashModes() => any
172
+ ```
173
+
174
+ Get supported flash modes.
175
+
176
+ **Returns:** <code>any</code>
177
+
178
+ **Since:** 0.0.1
179
+
180
+ --------------------
181
+
182
+
183
+ ### getHorizontalFov()
184
+
185
+ ```typescript
186
+ getHorizontalFov() => any
187
+ ```
188
+
189
+ Get horizontal field of view.
190
+
191
+ **Returns:** <code>any</code>
192
+
193
+ **Since:** 0.0.1
194
+
195
+ --------------------
196
+
197
+
198
+ ### setFlashMode(...)
199
+
200
+ ```typescript
201
+ setFlashMode(options: { flashMode: CameraPreviewFlashMode | string; }) => any
202
+ ```
203
+
204
+ Set flash mode.
205
+
206
+ | Param | Type | Description |
207
+ | ------------- | ----------------------------------- | -------------------------------------- |
208
+ | **`options`** | <code>{ flashMode: string; }</code> | the options to set the flash mode with |
209
+
210
+ **Returns:** <code>any</code>
211
+
212
+ **Since:** 0.0.1
213
+
214
+ --------------------
215
+
216
+
217
+ ### flip()
218
+
219
+ ```typescript
220
+ flip() => any
221
+ ```
222
+
223
+ Flip camera.
224
+
225
+ **Returns:** <code>any</code>
226
+
227
+ **Since:** 0.0.1
228
+
229
+ --------------------
230
+
231
+
232
+ ### setOpacity(...)
233
+
234
+ ```typescript
235
+ setOpacity(options: CameraOpacityOptions) => any
236
+ ```
237
+
238
+ Set opacity.
239
+
240
+ | Param | Type | Description |
241
+ | ------------- | --------------------------------------------------------------------- | ------------------------------------------ |
242
+ | **`options`** | <code><a href="#cameraopacityoptions">CameraOpacityOptions</a></code> | the options to set the camera opacity with |
243
+
244
+ **Returns:** <code>any</code>
245
+
246
+ **Since:** 0.0.1
247
+
248
+ --------------------
249
+
250
+
251
+ ### stopRecordVideo()
252
+
253
+ ```typescript
254
+ stopRecordVideo() => any
255
+ ```
256
+
257
+ Stop recording video.
258
+
259
+ **Returns:** <code>any</code>
260
+
261
+ **Since:** 0.0.1
262
+
263
+ --------------------
264
+
265
+
266
+ ### startRecordVideo(...)
267
+
268
+ ```typescript
269
+ startRecordVideo(options: CameraPreviewOptions) => any
270
+ ```
271
+
272
+ Start recording video.
273
+
274
+ | Param | Type | Description |
275
+ | ------------- | --------------------------------------------------------------------- | ----------------------------------------- |
276
+ | **`options`** | <code><a href="#camerapreviewoptions">CameraPreviewOptions</a></code> | the options to start recording video with |
277
+
278
+ **Returns:** <code>any</code>
279
+
280
+ **Since:** 0.0.1
281
+
282
+ --------------------
283
+
284
+
85
285
  ### Interfaces
86
286
 
87
287
 
@@ -101,7 +301,7 @@ Add `import '@capgo/camera-preview'` to you entry script in ionic on `app.module
101
301
  | **`position`** | <code>string</code> | Choose the camera to use 'front' or 'rear', default 'front' |
102
302
  | **`storeToFile`** | <code>boolean</code> | Defaults to false - Capture images to a file and return the file path instead of returning base64 encoded data |
103
303
  | **`disableExifHeaderStripping`** | <code>boolean</code> | Defaults to false - Android Only - Disable automatic rotation of the image, and let the browser deal with it (keep reading on how to achieve it) |
104
- | **`enableHighResolution`** | <code>boolean</code> | Defaults to false - iOS only - Activate high resolution image capture so that output images are from the highest resolution possible on the device |
304
+ | **`enableHighResolution`** | <code>boolean</code> | Defaults to false - iOS only - Activate high resolution image capture so that output images are from the highest resolution possible on the device * |
105
305
  | **`disableAudio`** | <code>boolean</code> | Defaults to false - Web only - Disables audio stream to prevent permission requests and output switching |
106
306
  | **`lockAndroidOrientation`** | <code>boolean</code> | Android Only - Locks device orientation when camera is showing. |
107
307
  | **`enableOpacity`** | <code>boolean</code> | Defaults to false - Android and Web only. Set if camera preview can change opacity. |
@@ -137,16 +337,16 @@ Add `import '@capgo/camera-preview'` to you entry script in ionic on `app.module
137
337
 
138
338
  #### CameraPosition
139
339
 
140
- <code>'rear' | 'front'</code>
340
+ <code>"rear" | "front"</code>
141
341
 
142
342
 
143
343
  #### PictureFormat
144
344
 
145
- <code>'jpeg' | 'png'</code>
345
+ <code>"jpeg" | "png"</code>
146
346
 
147
347
 
148
348
  #### CameraPreviewFlashMode
149
349
 
150
- <code>'off' | 'on' | 'auto' | 'red-eye' | 'torch'</code>
350
+ <code>"off" | "on" | "auto" | "red-eye" | "torch"</code>
151
351
 
152
352
  </docgen-api>
package/dist/docs.json CHANGED
@@ -4,271 +4,340 @@
4
4
  "slug": "camerapreviewplugin",
5
5
  "docs": "",
6
6
  "tags": [],
7
- "methods": [],
8
- "properties": [
7
+ "methods": [
9
8
  {
10
9
  "name": "start",
10
+ "signature": "(options: CameraPreviewOptions) => any",
11
+ "parameters": [
12
+ {
13
+ "name": "options",
14
+ "docs": "the options to start the camera preview with",
15
+ "type": "CameraPreviewOptions"
16
+ }
17
+ ],
18
+ "returns": "any",
11
19
  "tags": [
12
20
  {
13
- "text": "options the options to start the camera preview with",
14
- "name": "param"
21
+ "name": "param",
22
+ "text": "options the options to start the camera preview with"
15
23
  },
16
24
  {
17
- "text": "an Promise that resolves when the instance is started",
18
- "name": "returns"
25
+ "name": "returns",
26
+ "text": "an Promise that resolves when the instance is started"
19
27
  },
20
28
  {
21
- "text": "An error if the something went wrong",
22
- "name": "throws"
29
+ "name": "throws",
30
+ "text": "An error if the something went wrong"
23
31
  },
24
32
  {
25
- "text": "0.0.1",
26
- "name": "since"
33
+ "name": "since",
34
+ "text": "0.0.1"
27
35
  }
28
36
  ],
29
37
  "docs": "Start the camera preview instance.",
30
38
  "complexTypes": [
31
39
  "CameraPreviewOptions"
32
40
  ],
33
- "type": "(options: CameraPreviewOptions) => any"
41
+ "slug": "start"
34
42
  },
35
43
  {
36
44
  "name": "stop",
45
+ "signature": "() => any",
46
+ "parameters": [],
47
+ "returns": "any",
37
48
  "tags": [
38
49
  {
39
- "text": "an Promise that resolves when the instance is stopped",
40
- "name": "returns"
50
+ "name": "returns",
51
+ "text": "an Promise that resolves when the instance is stopped"
41
52
  },
42
53
  {
43
- "text": "An error if the something went wrong",
44
- "name": "throws"
54
+ "name": "throws",
55
+ "text": "An error if the something went wrong"
45
56
  },
46
57
  {
47
- "text": "0.0.1",
48
- "name": "since"
58
+ "name": "since",
59
+ "text": "0.0.1"
49
60
  }
50
61
  ],
51
62
  "docs": "Stop the camera preview instance.",
52
63
  "complexTypes": [],
53
- "type": "() => any"
64
+ "slug": "stop"
54
65
  },
55
66
  {
56
67
  "name": "capture",
68
+ "signature": "(options: CameraPreviewPictureOptions) => any",
69
+ "parameters": [
70
+ {
71
+ "name": "options",
72
+ "docs": "the options to switch the camera with",
73
+ "type": "CameraPreviewPictureOptions"
74
+ }
75
+ ],
76
+ "returns": "any",
57
77
  "tags": [
58
78
  {
59
- "text": "options the options to switch the camera with",
60
- "name": "param"
79
+ "name": "param",
80
+ "text": "options the options to switch the camera with"
61
81
  },
62
82
  {
63
- "text": "an Promise that resolves when the camera is switched",
64
- "name": "returns"
83
+ "name": "returns",
84
+ "text": "an Promise that resolves when the camera is switched"
65
85
  },
66
86
  {
67
- "text": "An error if the something went wrong",
68
- "name": "throws"
87
+ "name": "throws",
88
+ "text": "An error if the something went wrong"
69
89
  },
70
90
  {
71
- "text": "0.0.1",
72
- "name": "since"
91
+ "name": "since",
92
+ "text": "0.0.1"
73
93
  }
74
94
  ],
75
95
  "docs": "Switch camera.",
76
96
  "complexTypes": [
77
97
  "CameraPreviewPictureOptions"
78
98
  ],
79
- "type": "(options: CameraPreviewPictureOptions) => any"
99
+ "slug": "capture"
80
100
  },
81
101
  {
82
102
  "name": "captureSample",
103
+ "signature": "(options: CameraSampleOptions) => any",
104
+ "parameters": [
105
+ {
106
+ "name": "options",
107
+ "docs": "the options to capture the sample image with",
108
+ "type": "CameraSampleOptions"
109
+ }
110
+ ],
111
+ "returns": "any",
83
112
  "tags": [
84
113
  {
85
- "text": "options the options to capture the sample image with",
86
- "name": "param"
114
+ "name": "param",
115
+ "text": "options the options to capture the sample image with"
87
116
  },
88
117
  {
89
- "text": "an Promise that resolves with the sample image as a base64 encoded string",
90
- "name": "returns"
118
+ "name": "returns",
119
+ "text": "an Promise that resolves with the sample image as a base64 encoded string"
91
120
  },
92
121
  {
93
- "text": "An error if the something went wrong",
94
- "name": "throws"
122
+ "name": "throws",
123
+ "text": "An error if the something went wrong"
95
124
  },
96
125
  {
97
- "text": "0.0.1",
98
- "name": "since"
126
+ "name": "since",
127
+ "text": "0.0.1"
99
128
  }
100
129
  ],
101
130
  "docs": "Capture a sample image.",
102
131
  "complexTypes": [
103
132
  "CameraSampleOptions"
104
133
  ],
105
- "type": "(options: CameraSampleOptions) => any"
134
+ "slug": "capturesample"
106
135
  },
107
136
  {
108
137
  "name": "getSupportedFlashModes",
138
+ "signature": "() => any",
139
+ "parameters": [],
140
+ "returns": "any",
109
141
  "tags": [
110
142
  {
111
- "text": "an Promise that resolves with the supported flash modes",
112
- "name": "returns"
143
+ "name": "returns",
144
+ "text": "an Promise that resolves with the supported flash modes"
113
145
  },
114
146
  {
115
- "text": "An error if the something went wrong",
116
- "name": "throws"
147
+ "name": "throws",
148
+ "text": "An error if the something went wrong"
117
149
  },
118
150
  {
119
- "text": "0.0.1",
120
- "name": "since"
151
+ "name": "since",
152
+ "text": "0.0.1"
121
153
  }
122
154
  ],
123
155
  "docs": "Get supported flash modes.",
124
156
  "complexTypes": [
125
157
  "CameraPreviewFlashMode"
126
158
  ],
127
- "type": "() => any"
159
+ "slug": "getsupportedflashmodes"
128
160
  },
129
161
  {
130
162
  "name": "getHorizontalFov",
163
+ "signature": "() => any",
164
+ "parameters": [],
165
+ "returns": "any",
131
166
  "tags": [
132
167
  {
133
- "text": "an Promise that resolves with the horizontal field of view",
134
- "name": "returns"
168
+ "name": "returns",
169
+ "text": "an Promise that resolves with the horizontal field of view"
135
170
  },
136
171
  {
137
- "text": "An error if the something went wrong",
138
- "name": "throws"
172
+ "name": "throws",
173
+ "text": "An error if the something went wrong"
139
174
  },
140
175
  {
141
- "text": "0.0.1",
142
- "name": "since"
176
+ "name": "since",
177
+ "text": "0.0.1"
143
178
  }
144
179
  ],
145
180
  "docs": "Get horizontal field of view.",
146
181
  "complexTypes": [],
147
- "type": "() => any"
182
+ "slug": "gethorizontalfov"
148
183
  },
149
184
  {
150
185
  "name": "setFlashMode",
186
+ "signature": "(options: { flashMode: CameraPreviewFlashMode | string; }) => any",
187
+ "parameters": [
188
+ {
189
+ "name": "options",
190
+ "docs": "the options to set the flash mode with",
191
+ "type": "{ flashMode: string; }"
192
+ }
193
+ ],
194
+ "returns": "any",
151
195
  "tags": [
152
196
  {
153
- "text": "options the options to set the flash mode with",
154
- "name": "param"
197
+ "name": "param",
198
+ "text": "options the options to set the flash mode with"
155
199
  },
156
200
  {
157
- "text": "an Promise that resolves when the flash mode is set",
158
- "name": "returns"
201
+ "name": "returns",
202
+ "text": "an Promise that resolves when the flash mode is set"
159
203
  },
160
204
  {
161
- "text": "An error if the something went wrong",
162
- "name": "throws"
205
+ "name": "throws",
206
+ "text": "An error if the something went wrong"
163
207
  },
164
208
  {
165
- "text": "0.0.1",
166
- "name": "since"
209
+ "name": "since",
210
+ "text": "0.0.1"
167
211
  }
168
212
  ],
169
213
  "docs": "Set flash mode.",
170
214
  "complexTypes": [
171
215
  "CameraPreviewFlashMode"
172
216
  ],
173
- "type": "(options: { flashMode: string; }) => any"
217
+ "slug": "setflashmode"
174
218
  },
175
219
  {
176
220
  "name": "flip",
221
+ "signature": "() => any",
222
+ "parameters": [],
223
+ "returns": "any",
177
224
  "tags": [
178
225
  {
179
- "text": "an Promise that resolves when the camera is flipped",
180
- "name": "returns"
226
+ "name": "returns",
227
+ "text": "an Promise that resolves when the camera is flipped"
181
228
  },
182
229
  {
183
- "text": "An error if the something went wrong",
184
- "name": "throws"
230
+ "name": "throws",
231
+ "text": "An error if the something went wrong"
185
232
  },
186
233
  {
187
- "text": "0.0.1",
188
- "name": "since"
234
+ "name": "since",
235
+ "text": "0.0.1"
189
236
  }
190
237
  ],
191
238
  "docs": "Flip camera.",
192
239
  "complexTypes": [],
193
- "type": "() => any"
240
+ "slug": "flip"
194
241
  },
195
242
  {
196
243
  "name": "setOpacity",
244
+ "signature": "(options: CameraOpacityOptions) => any",
245
+ "parameters": [
246
+ {
247
+ "name": "options",
248
+ "docs": "the options to set the camera opacity with",
249
+ "type": "CameraOpacityOptions"
250
+ }
251
+ ],
252
+ "returns": "any",
197
253
  "tags": [
198
254
  {
199
- "text": "options the options to set the camera opacity with",
200
- "name": "param"
255
+ "name": "param",
256
+ "text": "options the options to set the camera opacity with"
201
257
  },
202
258
  {
203
- "text": "an Promise that resolves when the camera color effect is set",
204
- "name": "returns"
259
+ "name": "returns",
260
+ "text": "an Promise that resolves when the camera color effect is set"
205
261
  },
206
262
  {
207
- "text": "An error if the something went wrong",
208
- "name": "throws"
263
+ "name": "throws",
264
+ "text": "An error if the something went wrong"
209
265
  },
210
266
  {
211
- "text": "0.0.1",
212
- "name": "since"
267
+ "name": "since",
268
+ "text": "0.0.1"
213
269
  }
214
270
  ],
215
271
  "docs": "Set opacity.",
216
272
  "complexTypes": [
217
273
  "CameraOpacityOptions"
218
274
  ],
219
- "type": "(options: CameraOpacityOptions) => any"
275
+ "slug": "setopacity"
220
276
  },
221
277
  {
222
278
  "name": "stopRecordVideo",
279
+ "signature": "() => any",
280
+ "parameters": [],
281
+ "returns": "any",
223
282
  "tags": [
224
283
  {
225
- "text": "options the options to stop recording video with",
226
- "name": "param"
284
+ "name": "param",
285
+ "text": "options the options to stop recording video with"
227
286
  },
228
287
  {
229
- "text": "an Promise that resolves when the camera zoom is set",
230
- "name": "returns"
288
+ "name": "returns",
289
+ "text": "an Promise that resolves when the camera zoom is set"
231
290
  },
232
291
  {
233
- "text": "An error if the something went wrong",
234
- "name": "throws"
292
+ "name": "throws",
293
+ "text": "An error if the something went wrong"
235
294
  },
236
295
  {
237
- "text": "0.0.1",
238
- "name": "since"
296
+ "name": "since",
297
+ "text": "0.0.1"
239
298
  }
240
299
  ],
241
300
  "docs": "Stop recording video.",
242
301
  "complexTypes": [],
243
- "type": "() => any"
302
+ "slug": "stoprecordvideo"
244
303
  },
245
304
  {
246
305
  "name": "startRecordVideo",
306
+ "signature": "(options: CameraPreviewOptions) => any",
307
+ "parameters": [
308
+ {
309
+ "name": "options",
310
+ "docs": "the options to start recording video with",
311
+ "type": "CameraPreviewOptions"
312
+ }
313
+ ],
314
+ "returns": "any",
247
315
  "tags": [
248
316
  {
249
- "text": "options the options to start recording video with",
250
- "name": "param"
317
+ "name": "param",
318
+ "text": "options the options to start recording video with"
251
319
  },
252
320
  {
253
- "text": "an Promise that resolves when the video recording is started",
254
- "name": "returns"
321
+ "name": "returns",
322
+ "text": "an Promise that resolves when the video recording is started"
255
323
  },
256
324
  {
257
- "text": "An error if the something went wrong",
258
- "name": "throws"
325
+ "name": "throws",
326
+ "text": "An error if the something went wrong"
259
327
  },
260
328
  {
261
- "text": "0.0.1",
262
- "name": "since"
329
+ "name": "since",
330
+ "text": "0.0.1"
263
331
  }
264
332
  ],
265
333
  "docs": "Start recording video.",
266
334
  "complexTypes": [
267
335
  "CameraPreviewOptions"
268
336
  ],
269
- "type": "(options: CameraPreviewOptions) => any"
337
+ "slug": "startrecordvideo"
270
338
  }
271
- ]
339
+ ],
340
+ "properties": []
272
341
  },
273
342
  "interfaces": [
274
343
  {
@@ -367,7 +436,7 @@
367
436
  {
368
437
  "name": "enableHighResolution",
369
438
  "tags": [],
370
- "docs": "Defaults to false - iOS only - Activate high resolution image capture so that output images are from the highest resolution possible on the device",
439
+ "docs": "Defaults to false - iOS only - Activate high resolution image capture so that output images are from the highest resolution possible on the device *",
371
440
  "complexTypes": [],
372
441
  "type": "boolean"
373
442
  },
@@ -481,11 +550,11 @@
481
550
  "docs": "",
482
551
  "types": [
483
552
  {
484
- "text": "'rear'",
553
+ "text": "\"rear\"",
485
554
  "complexTypes": []
486
555
  },
487
556
  {
488
- "text": "'front'",
557
+ "text": "\"front\"",
489
558
  "complexTypes": []
490
559
  }
491
560
  ]
@@ -496,11 +565,11 @@
496
565
  "docs": "",
497
566
  "types": [
498
567
  {
499
- "text": "'jpeg'",
568
+ "text": "\"jpeg\"",
500
569
  "complexTypes": []
501
570
  },
502
571
  {
503
- "text": "'png'",
572
+ "text": "\"png\"",
504
573
  "complexTypes": []
505
574
  }
506
575
  ]
@@ -511,23 +580,23 @@
511
580
  "docs": "",
512
581
  "types": [
513
582
  {
514
- "text": "'off'",
583
+ "text": "\"off\"",
515
584
  "complexTypes": []
516
585
  },
517
586
  {
518
- "text": "'on'",
587
+ "text": "\"on\"",
519
588
  "complexTypes": []
520
589
  },
521
590
  {
522
- "text": "'auto'",
591
+ "text": "\"auto\"",
523
592
  "complexTypes": []
524
593
  },
525
594
  {
526
- "text": "'red-eye'",
595
+ "text": "\"red-eye\"",
527
596
  "complexTypes": []
528
597
  },
529
598
  {
530
- "text": "'torch'",
599
+ "text": "\"torch\"",
531
600
  "complexTypes": []
532
601
  }
533
602
  ]
@@ -1,4 +1,4 @@
1
- export type CameraPosition = 'rear' | 'front';
1
+ export type CameraPosition = "rear" | "front";
2
2
  export interface CameraPreviewOptions {
3
3
  /** Parent element to attach the video preview element to (applicable to the web platform only) */
4
4
  parent?: string;
@@ -24,7 +24,7 @@ export interface CameraPreviewOptions {
24
24
  storeToFile?: boolean;
25
25
  /** Defaults to false - Android Only - Disable automatic rotation of the image, and let the browser deal with it (keep reading on how to achieve it) */
26
26
  disableExifHeaderStripping?: boolean;
27
- /** Defaults to false - iOS only - Activate high resolution image capture so that output images are from the highest resolution possible on the device */
27
+ /** Defaults to false - iOS only - Activate high resolution image capture so that output images are from the highest resolution possible on the device **/
28
28
  enableHighResolution?: boolean;
29
29
  /** Defaults to false - Web only - Disables audio stream to prevent permission requests and output switching */
30
30
  disableAudio?: boolean;
@@ -42,19 +42,17 @@ export interface CameraPreviewPictureOptions {
42
42
  width?: number;
43
43
  /** The picture quality, 0 - 100, default 85 */
44
44
  quality?: number;
45
- /**
46
- * The picture format, jpeg or png, default jpeg on `Web`.
45
+ /** The picture format, jpeg or png, default jpeg on `Web`.
47
46
  *
48
- * quality has no effect on png
49
- */
47
+ * quality has no effect on png */
50
48
  format?: PictureFormat;
51
49
  }
52
- export type PictureFormat = 'jpeg' | 'png';
50
+ export type PictureFormat = "jpeg" | "png";
53
51
  export interface CameraSampleOptions {
54
52
  /** The picture quality, 0 - 100, default 85 */
55
53
  quality?: number;
56
54
  }
57
- export type CameraPreviewFlashMode = 'off' | 'on' | 'auto' | 'red-eye' | 'torch';
55
+ export type CameraPreviewFlashMode = "off" | "on" | "auto" | "red-eye" | "torch";
58
56
  export interface CameraOpacityOptions {
59
57
  /** The percent opacity to set for camera view, default 1 */
60
58
  opacity?: number;
@@ -67,14 +65,14 @@ export interface CameraPreviewPlugin {
67
65
  * @throws An error if the something went wrong
68
66
  * @since 0.0.1
69
67
  */
70
- start: (options: CameraPreviewOptions) => Promise<void>;
68
+ start(options: CameraPreviewOptions): Promise<void>;
71
69
  /**
72
70
  * Stop the camera preview instance.
73
71
  * @returns {Promise<void>} an Promise that resolves when the instance is stopped
74
72
  * @throws An error if the something went wrong
75
73
  * @since 0.0.1
76
74
  */
77
- stop: () => Promise<void>;
75
+ stop(): Promise<void>;
78
76
  /**
79
77
  * Switch camera.
80
78
  * @param {CameraPreviewOptions} options the options to switch the camera with
@@ -82,7 +80,7 @@ export interface CameraPreviewPlugin {
82
80
  * @throws An error if the something went wrong
83
81
  * @since 0.0.1
84
82
  */
85
- capture: (options: CameraPreviewPictureOptions) => Promise<{
83
+ capture(options: CameraPreviewPictureOptions): Promise<{
86
84
  value: string;
87
85
  }>;
88
86
  /**
@@ -92,7 +90,7 @@ export interface CameraPreviewPlugin {
92
90
  * @throws An error if the something went wrong
93
91
  * @since 0.0.1
94
92
  */
95
- captureSample: (options: CameraSampleOptions) => Promise<{
93
+ captureSample(options: CameraSampleOptions): Promise<{
96
94
  value: string;
97
95
  }>;
98
96
  /**
@@ -101,7 +99,7 @@ export interface CameraPreviewPlugin {
101
99
  * @throws An error if the something went wrong
102
100
  * @since 0.0.1
103
101
  */
104
- getSupportedFlashModes: () => Promise<{
102
+ getSupportedFlashModes(): Promise<{
105
103
  result: CameraPreviewFlashMode[];
106
104
  }>;
107
105
  /**
@@ -110,7 +108,7 @@ export interface CameraPreviewPlugin {
110
108
  * @throws An error if the something went wrong
111
109
  * @since 0.0.1
112
110
  */
113
- getHorizontalFov: () => Promise<{
111
+ getHorizontalFov(): Promise<{
114
112
  result: any;
115
113
  }>;
116
114
  /**
@@ -120,16 +118,16 @@ export interface CameraPreviewPlugin {
120
118
  * @throws An error if the something went wrong
121
119
  * @since 0.0.1
122
120
  */
123
- setFlashMode: (options: {
121
+ setFlashMode(options: {
124
122
  flashMode: CameraPreviewFlashMode | string;
125
- }) => Promise<void>;
123
+ }): Promise<void>;
126
124
  /**
127
125
  * Flip camera.
128
126
  * @returns {Promise<void>} an Promise that resolves when the camera is flipped
129
127
  * @throws An error if the something went wrong
130
128
  * @since 0.0.1
131
129
  */
132
- flip: () => Promise<void>;
130
+ flip(): Promise<void>;
133
131
  /**
134
132
  * Set opacity.
135
133
  * @param {CameraOpacityOptions} options the options to set the camera opacity with
@@ -137,15 +135,17 @@ export interface CameraPreviewPlugin {
137
135
  * @throws An error if the something went wrong
138
136
  * @since 0.0.1
139
137
  */
140
- setOpacity: (options: CameraOpacityOptions) => Promise<void>;
138
+ setOpacity(options: CameraOpacityOptions): Promise<void>;
141
139
  /**
142
140
  * Stop recording video.
143
141
  * @param {CameraPreviewOptions} options the options to stop recording video with
144
- * @returns {Promise<void>} an Promise that resolves when the camera zoom is set
142
+ * @returns {Promise<{videoFilePath: string}>} an Promise that resolves when the camera zoom is set
145
143
  * @throws An error if the something went wrong
146
144
  * @since 0.0.1
147
145
  */
148
- stopRecordVideo: () => Promise<void>;
146
+ stopRecordVideo(): Promise<{
147
+ videoFilePath: string;
148
+ }>;
149
149
  /**
150
150
  * Start recording video.
151
151
  * @param {CameraPreviewOptions} options the options to start recording video with
@@ -153,5 +153,5 @@ export interface CameraPreviewPlugin {
153
153
  * @throws An error if the something went wrong
154
154
  * @since 0.0.1
155
155
  */
156
- startRecordVideo: (options: CameraPreviewOptions) => Promise<void>;
156
+ startRecordVideo(options: CameraPreviewOptions): Promise<void>;
157
157
  }
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export type CameraPosition = 'rear' | 'front'\nexport interface CameraPreviewOptions {\n /** Parent element to attach the video preview element to (applicable to the web platform only) */\n parent?: string\n /** Class name to add to the video preview element (applicable to the web platform only) */\n className?: string\n /** The preview width in pixels, default window.screen.width */\n width?: number\n /** The preview height in pixels, default window.screen.height */\n height?: number\n /** The x origin, default 0 (applicable to the android and ios platforms only) */\n x?: number\n /** The y origin, default 0 (applicable to the android and ios platforms only) */\n y?: number\n /** Brings your html in front of your preview, default false (applicable to the android only) */\n toBack?: boolean\n /** The preview bottom padding in pixes. Useful to keep the appropriate preview sizes when orientation changes (applicable to the android and ios platforms only) */\n paddingBottom?: number\n /** Rotate preview when orientation changes (applicable to the ios platforms only; default value is true) */\n rotateWhenOrientationChanged?: boolean\n /** Choose the camera to use 'front' or 'rear', default 'front' */\n position?: CameraPosition | string\n /** Defaults to false - Capture images to a file and return the file path instead of returning base64 encoded data */\n storeToFile?: boolean\n /** Defaults to false - Android Only - Disable automatic rotation of the image, and let the browser deal with it (keep reading on how to achieve it) */\n disableExifHeaderStripping?: boolean\n /** Defaults to false - iOS only - Activate high resolution image capture so that output images are from the highest resolution possible on the device */\n enableHighResolution?: boolean\n /** Defaults to false - Web only - Disables audio stream to prevent permission requests and output switching */\n disableAudio?: boolean\n /** Android Only - Locks device orientation when camera is showing. */\n lockAndroidOrientation?: boolean\n /** Defaults to false - Android and Web only. Set if camera preview can change opacity. */\n enableOpacity?: boolean\n /** Defaults to false - Android only. Set if camera preview will support pinch to zoom. */\n enableZoom?: boolean\n}\nexport interface CameraPreviewPictureOptions {\n /** The picture height, optional, default 0 (Device default) */\n height?: number\n /** The picture width, optional, default 0 (Device default) */\n width?: number\n /** The picture quality, 0 - 100, default 85 */\n quality?: number\n /**\n * The picture format, jpeg or png, default jpeg on `Web`.\n *\n * quality has no effect on png\n */\n format?: PictureFormat\n}\n\nexport type PictureFormat = 'jpeg' | 'png'\n\nexport interface CameraSampleOptions {\n /** The picture quality, 0 - 100, default 85 */\n quality?: number\n}\n\nexport type CameraPreviewFlashMode =\n | 'off'\n | 'on'\n | 'auto'\n | 'red-eye'\n | 'torch'\n\nexport interface CameraOpacityOptions {\n /** The percent opacity to set for camera view, default 1 */\n opacity?: number\n}\n\nexport interface CameraPreviewPlugin {\n /**\n * Start the camera preview instance.\n * @param {CameraPreviewOptions} options the options to start the camera preview with\n * @returns {Promise<void>} an Promise that resolves when the instance is started\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n start: (options: CameraPreviewOptions) => Promise<void>\n /**\n * Stop the camera preview instance.\n * @returns {Promise<void>} an Promise that resolves when the instance is stopped\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n stop: () => Promise<void>\n /**\n * Switch camera.\n * @param {CameraPreviewOptions} options the options to switch the camera with\n * @returns {Promise<void>} an Promise that resolves when the camera is switched\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n capture: (options: CameraPreviewPictureOptions) => Promise<{ value: string }>\n /**\n * Capture a sample image.\n * @param {CameraSampleOptions} options the options to capture the sample image with\n * @returns {Promise<string>} an Promise that resolves with the sample image as a base64 encoded string\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n captureSample: (options: CameraSampleOptions) => Promise<{ value: string }>\n /**\n * Get supported flash modes.\n * @returns {Promise<CameraPreviewFlashMode[]>} an Promise that resolves with the supported flash modes\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n getSupportedFlashModes: () => Promise<{\n result: CameraPreviewFlashMode[]\n }>\n /**\n * Get horizontal field of view.\n * @returns {Promise<any>} an Promise that resolves with the horizontal field of view\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n getHorizontalFov: () => Promise<{\n result: any\n }>\n /**\n * Set flash mode.\n * @param options the options to set the flash mode with\n * @returns {Promise<void>} an Promise that resolves when the flash mode is set\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n setFlashMode: (options: {\n flashMode: CameraPreviewFlashMode | string\n }) => Promise<void>\n /**\n * Flip camera.\n * @returns {Promise<void>} an Promise that resolves when the camera is flipped\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n flip: () => Promise<void>\n /**\n * Set opacity.\n * @param {CameraOpacityOptions} options the options to set the camera opacity with\n * @returns {Promise<void>} an Promise that resolves when the camera color effect is set\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n setOpacity: (options: CameraOpacityOptions) => Promise<void>\n /**\n * Stop recording video.\n * @param {CameraPreviewOptions} options the options to stop recording video with\n * @returns {Promise<void>} an Promise that resolves when the camera zoom is set\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n stopRecordVideo: () => Promise<void>\n /**\n * Start recording video.\n * @param {CameraPreviewOptions} options the options to start recording video with\n * @returns {Promise<void>} an Promise that resolves when the video recording is started\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n startRecordVideo: (options: CameraPreviewOptions) => Promise<void>\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export type CameraPosition = \"rear\" | \"front\";\nexport interface CameraPreviewOptions {\n /** Parent element to attach the video preview element to (applicable to the web platform only) */\n parent?: string;\n /** Class name to add to the video preview element (applicable to the web platform only) */\n className?: string;\n /** The preview width in pixels, default window.screen.width */\n width?: number;\n /** The preview height in pixels, default window.screen.height */\n height?: number;\n /** The x origin, default 0 (applicable to the android and ios platforms only) */\n x?: number;\n /** The y origin, default 0 (applicable to the android and ios platforms only) */\n y?: number;\n /** Brings your html in front of your preview, default false (applicable to the android only) */\n toBack?: boolean;\n /** The preview bottom padding in pixes. Useful to keep the appropriate preview sizes when orientation changes (applicable to the android and ios platforms only) */\n paddingBottom?: number;\n /** Rotate preview when orientation changes (applicable to the ios platforms only; default value is true) */\n rotateWhenOrientationChanged?: boolean;\n /** Choose the camera to use 'front' or 'rear', default 'front' */\n position?: CameraPosition | string;\n /** Defaults to false - Capture images to a file and return the file path instead of returning base64 encoded data */\n storeToFile?: boolean;\n /** Defaults to false - Android Only - Disable automatic rotation of the image, and let the browser deal with it (keep reading on how to achieve it) */\n disableExifHeaderStripping?: boolean;\n /** Defaults to false - iOS only - Activate high resolution image capture so that output images are from the highest resolution possible on the device **/\n enableHighResolution?: boolean;\n /** Defaults to false - Web only - Disables audio stream to prevent permission requests and output switching */\n disableAudio?: boolean;\n /** Android Only - Locks device orientation when camera is showing. */\n lockAndroidOrientation?: boolean;\n /** Defaults to false - Android and Web only. Set if camera preview can change opacity. */\n enableOpacity?: boolean;\n /** Defaults to false - Android only. Set if camera preview will support pinch to zoom. */\n enableZoom?: boolean;\n}\nexport interface CameraPreviewPictureOptions {\n /** The picture height, optional, default 0 (Device default) */\n height?: number;\n /** The picture width, optional, default 0 (Device default) */\n width?: number;\n /** The picture quality, 0 - 100, default 85 */\n quality?: number;\n /** The picture format, jpeg or png, default jpeg on `Web`.\n *\n * quality has no effect on png */\n format?: PictureFormat;\n}\n\nexport type PictureFormat = \"jpeg\" | \"png\";\n\nexport interface CameraSampleOptions {\n /** The picture quality, 0 - 100, default 85 */\n quality?: number;\n}\n\nexport type CameraPreviewFlashMode =\n | \"off\"\n | \"on\"\n | \"auto\"\n | \"red-eye\"\n | \"torch\";\n\nexport interface CameraOpacityOptions {\n /** The percent opacity to set for camera view, default 1 */\n opacity?: number;\n}\n\nexport interface CameraPreviewPlugin {\n /**\n * Start the camera preview instance.\n * @param {CameraPreviewOptions} options the options to start the camera preview with\n * @returns {Promise<void>} an Promise that resolves when the instance is started\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n start(options: CameraPreviewOptions): Promise<void>;\n /**\n * Stop the camera preview instance.\n * @returns {Promise<void>} an Promise that resolves when the instance is stopped\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n stop(): Promise<void>;\n /**\n * Switch camera.\n * @param {CameraPreviewOptions} options the options to switch the camera with\n * @returns {Promise<void>} an Promise that resolves when the camera is switched\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n capture(options: CameraPreviewPictureOptions): Promise<{ value: string }>;\n /**\n * Capture a sample image.\n * @param {CameraSampleOptions} options the options to capture the sample image with\n * @returns {Promise<string>} an Promise that resolves with the sample image as a base64 encoded string\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n captureSample(options: CameraSampleOptions): Promise<{ value: string }>;\n /**\n * Get supported flash modes.\n * @returns {Promise<CameraPreviewFlashMode[]>} an Promise that resolves with the supported flash modes\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n getSupportedFlashModes(): Promise<{\n result: CameraPreviewFlashMode[];\n }>;\n /**\n * Get horizontal field of view.\n * @returns {Promise<any>} an Promise that resolves with the horizontal field of view\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n getHorizontalFov(): Promise<{\n result: any;\n }>;\n /**\n * Set flash mode.\n * @param options the options to set the flash mode with\n * @returns {Promise<void>} an Promise that resolves when the flash mode is set\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n setFlashMode(options: {\n flashMode: CameraPreviewFlashMode | string;\n }): Promise<void>;\n /**\n * Flip camera.\n * @returns {Promise<void>} an Promise that resolves when the camera is flipped\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n flip(): Promise<void>;\n /**\n * Set opacity.\n * @param {CameraOpacityOptions} options the options to set the camera opacity with\n * @returns {Promise<void>} an Promise that resolves when the camera color effect is set\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n setOpacity(options: CameraOpacityOptions): Promise<void>;\n /**\n * Stop recording video.\n * @param {CameraPreviewOptions} options the options to stop recording video with\n * @returns {Promise<{videoFilePath: string}>} an Promise that resolves when the camera zoom is set\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n stopRecordVideo(): Promise<{videoFilePath: string}>;\n /**\n * Start recording video.\n * @param {CameraPreviewOptions} options the options to start recording video with\n * @returns {Promise<void>} an Promise that resolves when the video recording is started\n * @throws An error if the something went wrong\n * @since 0.0.1\n */\n startRecordVideo(options: CameraPreviewOptions): Promise<void>;\n}\n"]}
@@ -36,6 +36,8 @@ class CameraController: NSObject {
36
36
  var audioInput: AVCaptureDeviceInput?
37
37
 
38
38
  var zoomFactor: CGFloat = 1.0
39
+
40
+ var videoFileURL: URL?
39
41
  }
40
42
 
41
43
  extension CameraController {
@@ -414,10 +416,9 @@ extension CameraController {
414
416
 
415
417
  }
416
418
 
417
- func captureVideo(completion: @escaping (URL?, Error?) -> Void) {
419
+ func captureVideo() throws {
418
420
  guard let captureSession = self.captureSession, captureSession.isRunning else {
419
- completion(nil, CameraControllerError.captureSessionIsMissing)
420
- return
421
+ throw CameraControllerError.captureSessionIsMissing
421
422
  }
422
423
  let path = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0]
423
424
  let identifier = UUID()
@@ -427,16 +428,24 @@ extension CameraController {
427
428
 
428
429
  let fileUrl = path.appendingPathComponent(fileName)
429
430
  try? FileManager.default.removeItem(at: fileUrl)
430
- /*videoOutput!.startRecording(to: fileUrl, recordingDelegate: self)
431
- self.videoRecordCompletionBlock = completion*/
431
+
432
+ // Start recording video
433
+ // ...
434
+
435
+ // Save the file URL for later use
436
+ self.videoFileURL = fileUrl
432
437
  }
433
438
 
434
- func stopRecording(completion: @escaping (Error?) -> Void) {
439
+ func stopRecording(completion: @escaping (URL?, Error?) -> Void) {
435
440
  guard let captureSession = self.captureSession, captureSession.isRunning else {
436
- completion(CameraControllerError.captureSessionIsMissing)
441
+ completion(nil, CameraControllerError.captureSessionIsMissing)
437
442
  return
438
443
  }
439
- // self.videoOutput?.stopRecording()
444
+ // Stop recording video
445
+ // ...
446
+
447
+ // Return the video file URL in the completion handler
448
+ completion(self.videoFileURL, nil)
440
449
  }
441
450
  }
442
451
 
@@ -504,8 +513,10 @@ extension CameraController: UIGestureRecognizerDelegate {
504
513
  extension CameraController: AVCapturePhotoCaptureDelegate {
505
514
  public func photoOutput(_ captureOutput: AVCapturePhotoOutput, didFinishProcessingPhoto photoSampleBuffer: CMSampleBuffer?, previewPhoto previewPhotoSampleBuffer: CMSampleBuffer?,
506
515
  resolvedSettings: AVCaptureResolvedPhotoSettings, bracketSettings: AVCaptureBracketedStillImageSettings?, error: Swift.Error?) {
507
- if let error = error { self.photoCaptureCompletionBlock?(nil, error) } else if let buffer = photoSampleBuffer, let data = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: buffer, previewPhotoSampleBuffer: nil),
508
- let image = UIImage(data: data) {
516
+ if let error = error {
517
+ self.photoCaptureCompletionBlock?(nil, error)
518
+ } else if let buffer = photoSampleBuffer, let data = AVCapturePhotoOutput.jpegPhotoDataRepresentation(forJPEGSampleBuffer: buffer, previewPhotoSampleBuffer: nil),
519
+ let image = UIImage(data: data) {
509
520
  self.photoCaptureCompletionBlock?(image.fixedOrientation(), nil)
510
521
  } else {
511
522
  self.photoCaptureCompletionBlock?(nil, CameraControllerError.unknown)
@@ -603,7 +614,10 @@ extension UIImage {
603
614
  return nil
604
615
  }
605
616
 
606
- guard let colorSpace = cgImage.colorSpace, let ctx = CGContext(data: nil, width: Int(size.width), height: Int(size.height), bitsPerComponent: cgImage.bitsPerComponent, bytesPerRow: 0, space: colorSpace, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else {
617
+ guard let colorSpace = cgImage.colorSpace, let ctx = CGContext(data: nil,
618
+ width: Int(size.width), height: Int(size.height),
619
+ bitsPerComponent: cgImage.bitsPerComponent, bytesPerRow: 0,
620
+ space: colorSpace, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else {
607
621
  return nil // Not able to create CGContext
608
622
  }
609
623
 
@@ -37,8 +37,8 @@ public class CameraPreview: CAPPlugin {
37
37
  var previewView: UIView!
38
38
  var cameraPosition = String()
39
39
  let cameraController = CameraController()
40
- var x: CGFloat?
41
- var y: CGFloat?
40
+ var posX: CGFloat?
41
+ var posY: CGFloat?
42
42
  var width: CGFloat?
43
43
  var height: CGFloat?
44
44
  var paddingBottom: CGFloat?
@@ -53,13 +53,13 @@ public class CameraPreview: CAPPlugin {
53
53
  let height = self.paddingBottom != nil ? self.height! - self.paddingBottom!: self.height!
54
54
 
55
55
  if UIWindow.isLandscape {
56
- self.previewView.frame = CGRect(x: self.y!, y: self.x!, width: max(height, self.width!), height: min(height, self.width!))
56
+ self.previewView.frame = CGRect(x: self.posY!, y: self.posX!, width: max(height, self.width!), height: min(height, self.width!))
57
57
  self.cameraController.previewLayer?.frame = self.previewView.frame
58
58
  }
59
59
 
60
60
  if UIWindow.isPortrait {
61
- if self.previewView != nil && self.x != nil && self.y != nil && self.width != nil && self.height != nil {
62
- self.previewView.frame = CGRect(x: self.x!, y: self.y!, width: min(height, self.width!), height: max(height, self.width!))
61
+ if self.previewView != nil && self.posX != nil && self.posY != nil && self.width != nil && self.height != nil {
62
+ self.previewView.frame = CGRect(x: self.posX!, y: self.posY!, width: min(height, self.width!), height: max(height, self.width!))
63
63
  }
64
64
  self.cameraController.previewLayer?.frame = self.previewView.frame
65
65
  }
@@ -82,8 +82,8 @@ public class CameraPreview: CAPPlugin {
82
82
  } else {
83
83
  self.height = UIScreen.main.bounds.size.height
84
84
  }
85
- self.x = call.getInt("x") != nil ? CGFloat(call.getInt("x")!)/UIScreen.main.scale: 0
86
- self.y = call.getInt("y") != nil ? CGFloat(call.getInt("y")!)/UIScreen.main.scale: 0
85
+ self.posX = call.getInt("x") != nil ? CGFloat(call.getInt("x")!)/UIScreen.main.scale: 0
86
+ self.posY = call.getInt("y") != nil ? CGFloat(call.getInt("y")!)/UIScreen.main.scale: 0
87
87
  if call.getInt("paddingBottom") != nil {
88
88
  self.paddingBottom = CGFloat(call.getInt("paddingBottom")!)
89
89
  }
@@ -111,7 +111,7 @@ public class CameraPreview: CAPPlugin {
111
111
  return
112
112
  }
113
113
  let height = self.paddingBottom != nil ? self.height! - self.paddingBottom!: self.height!
114
- self.previewView = UIView(frame: CGRect(x: self.x ?? 0, y: self.y ?? 0, width: self.width!, height: height))
114
+ self.previewView = UIView(frame: CGRect(x: self.posX ?? 0, y: self.posY ?? 0, width: self.width!, height: height))
115
115
  self.webView?.isOpaque = false
116
116
  self.webView?.backgroundColor = UIColor.clear
117
117
  self.webView?.scrollView.backgroundColor = UIColor.clear
@@ -294,33 +294,31 @@ public class CameraPreview: CAPPlugin {
294
294
 
295
295
  @objc func startRecordVideo(_ call: CAPPluginCall) {
296
296
  DispatchQueue.main.async {
297
+ do {
298
+ try self.cameraController.captureVideo()
299
+ call.resolve()
300
+ } catch {
301
+ call.reject(error.localizedDescription)
302
+ }
303
+ }
304
+ }
297
305
 
298
- let quality: Int? = call.getInt("quality", 85)
299
-
300
- self.cameraController.captureVideo { (image, error) in
301
-
302
- guard let image = image else {
303
- print(error ?? "Image capture error")
306
+ @objc func stopRecordVideo(_ call: CAPPluginCall) {
307
+ DispatchQueue.main.async {
308
+ self.cameraController.stopRecording { (fileURL, error) in
309
+ guard let fileURL = fileURL else {
310
+ print(error ?? "Video capture error")
304
311
  guard let error = error else {
305
- call.reject("Image capture error")
312
+ call.reject("Video capture error")
306
313
  return
307
314
  }
308
315
  call.reject(error.localizedDescription)
309
316
  return
310
317
  }
311
318
 
312
- // self.videoUrl = image
313
-
314
- call.resolve(["value": image.absoluteString])
319
+ call.resolve(["videoUrl": fileURL.absoluteString])
315
320
  }
316
321
  }
317
322
  }
318
323
 
319
- @objc func stopRecordVideo(_ call: CAPPluginCall) {
320
-
321
- self.cameraController.stopRecording { (_) in
322
- call.resolve()
323
- }
324
- }
325
-
326
324
  }
@@ -3,23 +3,81 @@ import Capacitor
3
3
  @testable import Plugin
4
4
 
5
5
  class PluginTests: XCTestCase {
6
+ var plugin: CameraPreview?
6
7
 
7
- func testEcho() {
8
- // This is an example of a functional test case for a plugin.
9
- // Use XCTAssert and related functions to verify your tests produce the correct results.
8
+ override func setUp() {
9
+ super.setUp()
10
+ plugin = CameraPreview()
11
+ }
12
+
13
+ override func tearDown() {
14
+ plugin = nil
15
+ super.tearDown()
16
+ }
17
+
18
+ func testStartCamera() {
19
+ let call = CAPPluginCall(callbackId: "testStartCamera", options: [
20
+ "position": "rear",
21
+ "quality": 85,
22
+ "width": 800,
23
+ "height": 600
24
+ ], success: { (_, _) in
25
+ // Camera started successfully
26
+ XCTAssert(true)
27
+ }, error: { (_) in
28
+ XCTFail("Error shouldn't have been called")
29
+ })
30
+
31
+ plugin?.start(call!)
32
+ }
33
+
34
+ func testFlipCamera() {
35
+ let call = CAPPluginCall(callbackId: "testFlipCamera", options: [:], success: { (_, _) in
36
+ // Camera flipped successfully
37
+ XCTAssert(true)
38
+ }, error: { (_) in
39
+ XCTFail("Error shouldn't have been called")
40
+ })
41
+
42
+ plugin?.flip(call!)
43
+ }
44
+
45
+ func testStopCamera() {
46
+ let call = CAPPluginCall(callbackId: "testStopCamera", options: [:], success: { (_, _) in
47
+ // Camera stopped successfully
48
+ XCTAssert(true)
49
+ }, error: { (_) in
50
+ XCTFail("Error shouldn't have been called")
51
+ })
52
+
53
+ plugin?.stop(call!)
54
+ }
10
55
 
11
- let value = "Hello, World!"
12
- let plugin = MyPlugin()
56
+ func testStartRecordVideo() {
57
+ let call = CAPPluginCall(callbackId: "testStartRecordVideo", options: [:], success: { (_, _) in
58
+ // Video recording started successfully
59
+ XCTAssert(true)
60
+ }, error: { (_) in
61
+ XCTFail("Error shouldn't have been called")
62
+ })
13
63
 
14
- let call = CAPPluginCall(callbackId: "test", options: [
15
- "value": value
16
- ], success: { (result, _) in
17
- let resultValue = result!.data["value"] as? String
18
- XCTAssertEqual(value, resultValue)
64
+ plugin?.startRecordVideo(call!)
65
+ }
66
+
67
+ func testStopRecordVideo() {
68
+ let expectation = self.expectation(description: "Video recording stopped")
69
+
70
+ let call = CAPPluginCall(callbackId: "testStopRecordVideo", options: [:], success: { (result, _) in
71
+ // Video recording stopped successfully
72
+ let videoUrl = result?.data?["videoUrl"] as? String
73
+ XCTAssertNotNil(videoUrl)
74
+ expectation.fulfill()
19
75
  }, error: { (_) in
20
76
  XCTFail("Error shouldn't have been called")
21
77
  })
22
78
 
23
- plugin.echo(call!)
79
+ plugin?.stopRecordVideo(call!)
80
+
81
+ waitForExpectations(timeout: 5, handler: nil)
24
82
  }
25
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/camera-preview",
3
- "version": "6.1.6",
3
+ "version": "6.1.10",
4
4
  "description": "Camera preview",
5
5
  "author": "Martin Donadieu <martindonadieu@gmail.com>",
6
6
  "license": "MIT",
@@ -71,6 +71,5 @@
71
71
  "src": "android"
72
72
  }
73
73
  },
74
- "prettier": "@ionic/prettier-config",
75
- "swiftlint": "@ionic/swiftlint-config"
74
+ "prettier": "@ionic/prettier-config"
76
75
  }