Skip to content

Commit 6ad15c1

Browse files
committed
npm publish
0 parents  commit 6ad15c1

28 files changed

+2169
-0
lines changed

.npmignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
demo/
2+
.idea/
3+
support/
4+
*.tar
5+
*.tgz
6+
.npmignore
7+
*.map
8+
*.ts
9+
!*.d.ts
10+
tsconfig.json
11+
scripts
12+
.DS_Store
13+
*.aar
14+
node_modules

README.md

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

Yoonit.Camera.android.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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(faceImageSize: number): void;
13+
requestPermission(explanation?: string): Promise<boolean>;
14+
hasPermission(): boolean;
15+
}

Yoonit.Camera.android.js

Lines changed: 156 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Yoonit.Camera.android.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)