Skip to content

Commit fe8852b

Browse files
committed
npm publish
0 parents  commit fe8852b

28 files changed

+8497
-0
lines changed

.npmignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
demo/
2+
.idea/
3+
support/
4+
*.tar
5+
*.tgz
6+
.npmignore
7+
*.map
8+
*.ts
9+
tsconfig.json
10+
scripts
11+
.DS_Store
12+
*.aar
13+
node_modules
14+
*.esm.json
15+
!extractTGZ.js
16+
*.js.map
17+
*.log
18+
19+
# Editor directories and files
20+
.idea
21+
.vscode

README.md

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
[<img src="https://raw.githubusercontent.com/Yoonit-Labs/nativescript-yoonit-camera/development/logo_cyberlabs.png" width="300">](https://cyberlabs.ai/)
2+
3+
# NativeScript Yoonit Camera
4+
5+
![NativeScript](https://img.shields.io/badge/NativeScript-7-lightgrey.svg?style=for-the-badge&logo=nativescript) ![Version](https://img.shields.io/npm/v/@yoonit/nativescript-camera?color=lightgrey&style=for-the-badge&logo=npm) ![Downloads](https://img.shields.io/npm/dm/@yoonit/nativescript-camera?color=lightgrey&logo=npm&style=for-the-badge)
6+
7+
![Android](https://img.shields.io/badge/Android-YES-lightgrey.svg?style=for-the-badge&logo=android) ![iOS](https://img.shields.io/badge/iOS-YES-lightgrey.svg?style=for-the-badge&logo=apple) ![MIT license](https://img.shields.io/npm/l/@yoonit/nativescript-camera?color=lightgrey&style=for-the-badge)
8+
9+
A NativeScript plugin to provide:
10+
- Modern Android Camera API (Camera X)
11+
- MLKit integration
12+
- Camera preview (Front & Back)
13+
- Face detection (With Min & Max size (Soon))
14+
- Landmark detection (Soon)
15+
- Face crop
16+
- Face capture
17+
- Frame capture
18+
- Face ROI (Soon)
19+
- QR Code scanning
20+
21+
## Installation
22+
23+
```javascript
24+
npm i -s @yoonit/nativescript-camera
25+
```
26+
27+
## Usage
28+
29+
All the functionalities that the `@yoonit/nativescript-camera` provides is accessed through the `YoonitCamera` component, that includes the camera preview. Below we have the basic usage code, for more details, your can see the [**Methods**](#methods), [**Events**](#events) or the [**Demo Vue**](https://github.com/Yoonit-Labs/nativescript-yoonit-camera/tree/development/demo-vue).
30+
31+
32+
#### VueJS Plugin
33+
`main.js`
34+
```javascript
35+
import Vue from 'nativescript-vue'
36+
import YoonitCamera from '@yoonit/nativescript-camera/vue'
37+
38+
Vue.use(YoonitCamera)
39+
```
40+
41+
After that, you can access the camera object in your entire project using `this.$yoo.camera`
42+
43+
#### Vue Component
44+
`App.vue`
45+
```vue
46+
<template>
47+
<Page @loaded="onLoaded">
48+
<YoonitCamera
49+
ref="yooCamera"
50+
@faceDetected="doFaceDetected"
51+
@faceImage="doImageCreated"
52+
@frameImage="doImageCreated"
53+
@endCapture="doEndCapture"
54+
@qrCodeContent="doQRCodeContent"
55+
@status="doStatus"
56+
@permissionDenied="doPermissionDenied"
57+
/>
58+
</Page>
59+
</template>
60+
61+
<script>
62+
export default {
63+
data: () => ({}),
64+
65+
methods: {
66+
async onLoaded(args) {
67+
console.log('[YooCamera] Getting Camera view')
68+
this.$yoo.camera.registerElement(this.$refs.yooCamera)
69+
70+
console.log('[YooCamera] Getting permission')
71+
if (await this.$yoo.camera.requestPermission()) {
72+
console.log('[YooCamera] Permission granted, start preview')
73+
74+
this.$yoo.camera.preview()
75+
}
76+
},
77+
78+
doFaceDetected({ faceDetected }) {
79+
console.log('[YooCamera] faceDetected', faceDetected)
80+
},
81+
82+
doImageCreated({
83+
count,
84+
total,
85+
image: {
86+
path,
87+
source
88+
}
89+
}) {
90+
if (total === 0) {
91+
console.log('[YooCamera] doFaceImage', `[${count}] ${path}`)
92+
} else {
93+
console.log('[YooCamera] doFaceImage', `[${count}] of [${total}] - ${path}`)
94+
}
95+
96+
console.log('[YooCamera] doFaceImage', path, source)
97+
},
98+
99+
doEndCapture() {
100+
console.log('[YooCamera] doEndCapture')
101+
},
102+
103+
doQRCodeContent({ content }) {
104+
console.log('[YooCamera] doQRCodeContent', content)
105+
},
106+
107+
doStatus({ status }) {
108+
console.log('[YooCamera] doStatus', JSON.parse(status))
109+
},
110+
111+
doToggleLens() {
112+
const currentCameraLens = this.$yoo.camera.getLens()
113+
114+
console.log('[YooCamera] doToggleLens', currentCameraLens)
115+
116+
this.$yoo.camera.toggleLens()
117+
},
118+
119+
doStartCapture(captureType) {
120+
console.log('[YooCamera] doStartCapture', captureType)
121+
122+
this.$yoo.camera.startCapture(captureType)
123+
},
124+
125+
doFaceDetectionBox(status) {
126+
console.log('[YooCamera] doFaceDetectionBox', status)
127+
128+
this.$yoo.camera.setFaceDetectionBox(status)
129+
},
130+
131+
doPermissionDenied() {
132+
console.log('[YooCamera] doPermissionDenied')
133+
}
134+
}
135+
}
136+
</script>
137+
```
138+
139+
## API
140+
141+
#### Methods
142+
143+
| Function | Parameters | Valid values | Return Type | Description
144+
| - | - | - | - | -
145+
| **`requestPermission`** | - | - | promise | Ask to user to give the permission to access camera.
146+
| **`hasPermission`** | - | - | boolean | Return if application has camera permission.
147+
| **`preview`** | - | - | void | Start camera preview if has permission.
148+
| **`startCapture`** | `captureType: string` | <ul><li>`"none"`</li><li>`"face"`</li><li>`"barcode"`</li><li>`"frame"`</li></ul> | void | Set capture type none, face, barcode or frame.
149+
| **`stopCapture`** | - | - | void | Stop any type of capture.
150+
| **`toggleLens`** | - | - | void | Set camera lens facing front or back.
151+
| **`getLens`** | - | - | number | Return `number` that represents lens face state: 0 for front 1 for back camera.
152+
| **`setFaceNumberOfImages`** | `faceNumberOfImages: number` | Any positive `number` value | void | Default value is 0. For value 0 is saved infinity images. When saved images reached the "face number os images", the `onEndCapture` is triggered.
153+
| **`setFaceDetectionBox`** | `faceDetectionBox: boolean` | `true` or `false` | void | Set to show face detection box when face detected.
154+
| **`setFaceTimeBetweenImages`** | `faceTimeBetweenImages: number` | Any positive `number` that represent time in milli seconds | void | Set saving face images time interval in milli seconds.
155+
| **`setFacePaddingPercent`** | `facePaddingPercent: number` | Any positive `number` value | void | Set face image and bounding box padding in percent.
156+
| **`setFaceImageSize`** | `faceImageSize: number` | Any positive `number` value | void | Set face image size to be saved.
157+
| **`setFrameNumberOfImages`** | `frameNumberOfImages: number` | Any positive `number` value | void | Default value is 0. For value 0 is saved infinity images. When saved images reached the "frame number os images", the `onEndCapture` is triggered.
158+
| **`setFrameTimeBetweenImages`** | `frameTimeBetweenImages: number` | Any positive `number` that represent time in milli seconds | void | Set saving frame images time interval in milli seconds.
159+
160+
161+
#### Events
162+
163+
| Event | Parameters | Description
164+
| - | - | -
165+
| faceImage | `{ count: number, total: number, image: object = { path: string, source: blob } }` | Must have started capture type of face. Emitted when the face image file is created: <ul><li>count: current index</li><li>total: total to create</li><li>image.path: the face image path</li><li>image.source: the blob file</li><ul>
166+
| frameImage | `{ count: number, total: number, image: object = { path: string, source: blob } }` | Must have started capture type of frame. Emitted when the frame image file is created: <ul><li>count: current index</li><li>total: total to create</li><li>image.path: the frame image path</li><li>image.source: the blob file</li><ul>
167+
| faceDetected | `{ x: number, y: number, width: number, height: number }` | Must have started capture type of face. Emit the detected face bounding box. Emit all parameters null if no more face detecting.
168+
| endCapture | - | Must have started capture type of face or frame. Emitted when the number of face or frame image files created is equal of the number of images set (see the method `setFaceNumberOfImages` for face and `setFrameNumberOfImages`for frame).
169+
| qrCodeContent | `{ content: string }` | Must have started capture type of barcode (see `startCapture`). Emitted when the camera scan a QR Code.
170+
| status | `{ type: 'error'/'message', status: string }` | Emit message error from native. Used more often for debug purpose.
171+
| permissionDenied | - | Emit when try to `preview` but there is not camera permission.
172+
173+
174+
## To contribute and make it better
175+
176+
Clone the repo, change what you want and send PR.
177+
178+
Contributions are always welcome!
179+
180+
---
181+
182+
Code with ❤ by the [**Cyberlabs AI**](https://cyberlabs.ai/) Front-End Team

Yoonit.Camera.android.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { CameraBase } from './Yoonit.Camera.common';
2+
export declare class YoonitCamera extends CameraBase {
3+
nativeView: ai.cyberlabs.yoonit.camera.CameraView;
4+
createNativeView(): Object;
5+
initNativeView(): void;
6+
disposeNativeView(): void;
7+
startCapture(captureType: string): void;
8+
setFaceNumberOfImages(faceNumberOfImages: number): void;
9+
setFaceDetectionBox(faceDetectionBox: boolean): void;
10+
setFaceTimeBetweenImages(faceTimeBetweenImages: number): void;
11+
setFacePaddingPercent(facePaddingPercent: number): void;
12+
setFaceImageSize(width: number, height: number): void;
13+
setFrameNumberOfImages(frameNumberOfImages: number): void;
14+
setFrameTimeBetweenImages(frameTimeBetweenImages: number): void;
15+
requestPermission(explanation?: string): Promise<boolean>;
16+
hasPermission(): boolean;
17+
}

0 commit comments

Comments
 (0)