An open API service indexing awesome lists of open source software.

https://github.com/numbersprotocol/preview-camera


https://github.com/numbersprotocol/preview-camera

capture-cam

Last synced: about 1 year ago
JSON representation

Awesome Lists containing this project

README

          

# @numbersprotocol/preview-camera

Preview Camera Plugin for iOS, Android

## Install

```bash
npm install @numbersprotocol/preview-camera
npx cap sync
```

## API

* [`echo(...)`](#echo)
* [`startPreview()`](#startpreview)
* [`stopPreview()`](#stoppreview)
* [`takePhoto()`](#takephoto)
* [`capturePhoto()`](#capturephoto)
* [`startRecord()`](#startrecord)
* [`stopRecord()`](#stoprecord)
* [`flipCamera()`](#flipcamera)
* [`getFlashModes()`](#getflashmodes)
* [`setFlashMode()`](#setflashmode)
* [`isTorchOn()`](#istorchon)
* [`enableTorch(...)`](#enabletorch)
* [`isTorchAvailable()`](#istorchavailable)
* [`focus(...)`](#focus)
* [`minAvailableZoom()`](#minavailablezoom)
* [`maxAvailableZoom()`](#maxavailablezoom)
* [`zoom(...)`](#zoom)
* [`setQuality(...)`](#setquality)
* [`saveFileToUserDevice(...)`](#savefiletouserdevice)
* [`checkPermissions()`](#checkpermissions)
* [`requestPermissions()`](#requestpermissions)
* [`addListener('captureSuccessResult', ...)`](#addlistenercapturesuccessresult-)
* [`addListener('captureErrorResult', ...)`](#addlistenercaptureerrorresult-)
* [`addListener('captureVideoFinished', ...)`](#addlistenercapturevideofinished-)
* [`addListener('capturePhotoFinished', ...)`](#addlistenercapturephotofinished-)
* [`addListener('accelerometerOrientation', ...)`](#addlisteneraccelerometerorientation-)
* [`removeAllListeners()`](#removealllisteners)
* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)

### echo(...)

```typescript
echo(options: { value: string; }) => Promise<{ value: string; }>
```

| Param | Type |
| ------------- | ------------------------------- |
| **`options`** | { value: string; } |

**Returns:** Promise<{ value: string; }>

--------------------

### startPreview()

```typescript
startPreview() => Promise
```

--------------------

### stopPreview()

```typescript
stopPreview() => Promise
```

--------------------

### takePhoto()

```typescript
takePhoto() => Promise
```

--------------------

### capturePhoto()

```typescript
capturePhoto() => Promise
```

--------------------

### startRecord()

```typescript
startRecord() => Promise
```

--------------------

### stopRecord()

```typescript
stopRecord() => Promise
```

--------------------

### flipCamera()

```typescript
flipCamera() => Promise
```

--------------------

### getFlashModes()

```typescript
getFlashModes() => Promise
```

**Returns:** Promise<any>

--------------------

### setFlashMode()

```typescript
setFlashMode() => Promise
```

--------------------

### isTorchOn()

```typescript
isTorchOn() => Promise<{ result: boolean; }>
```

**Returns:** Promise<{ result: boolean; }>

--------------------

### enableTorch(...)

```typescript
enableTorch(options: { enable: boolean; }) => Promise
```

| Param | Type |
| ------------- | --------------------------------- |
| **`options`** | { enable: boolean; } |

--------------------

### isTorchAvailable()

```typescript
isTorchAvailable() => Promise<{ result: boolean; }>
```

**Returns:** Promise<{ result: boolean; }>

--------------------

### focus(...)

```typescript
focus(options: { x: number; y: number; }) => Promise
```

| Param | Type |
| ------------- | -------------------------------------- |
| **`options`** | { x: number; y: number; } |

--------------------

### minAvailableZoom()

```typescript
minAvailableZoom() => Promise<{ result: number; }>
```

**Returns:** Promise<{ result: number; }>

--------------------

### maxAvailableZoom()

```typescript
maxAvailableZoom() => Promise<{ result: number; }>
```

**Returns:** Promise<{ result: number; }>

--------------------

### zoom(...)

```typescript
zoom(options: { factor: number; }) => Promise
```

| Param | Type |
| ------------- | -------------------------------- |
| **`options`** | { factor: number; } |

--------------------

### setQuality(...)

```typescript
setQuality(options: { quality: 'low' | 'hq'; }) => Promise
```

| Param | Type |
| ------------- | ---------------------------------------- |
| **`options`** | { quality: 'low' \| 'hq'; } |

--------------------

### saveFileToUserDevice(...)

```typescript
saveFileToUserDevice(options: { filePath: string; }) => Promise
```

| Param | Type |
| ------------- | ---------------------------------- |
| **`options`** | { filePath: string; } |

--------------------

### checkPermissions()

```typescript
checkPermissions() => Promise
```

**Returns:** Promise<PermissionStatus>

--------------------

### requestPermissions()

```typescript
requestPermissions() => Promise
```

**Returns:** Promise<PermissionStatus>

--------------------

### addListener('captureSuccessResult', ...)

```typescript
addListener(eventName: 'captureSuccessResult', listenerFunc: (data: CaptureSuccessResult) => void) => Promise
```

| Param | Type |
| ------------------ | ---------------------------------------------------------------------------------------- |
| **`eventName`** | 'captureSuccessResult' |
| **`listenerFunc`** | (data: CaptureSuccessResult) => void |

**Returns:** Promise<PluginListenerHandle>

--------------------

### addListener('captureErrorResult', ...)

```typescript
addListener(eventName: 'captureErrorResult', listenerFunc: (data: CaptureErrorResult) => void) => Promise
```

| Param | Type |
| ------------------ | ------------------------------------------------------------------------------------ |
| **`eventName`** | 'captureErrorResult' |
| **`listenerFunc`** | (data: CaptureErrorResult) => void |

**Returns:** Promise<PluginListenerHandle>

--------------------

### addListener('captureVideoFinished', ...)

```typescript
addListener(eventName: 'captureVideoFinished', listenerFunc: (data: CaptureResult) => void) => Promise
```

| Param | Type |
| ------------------ | -------------------------------------------------------------------------- |
| **`eventName`** | 'captureVideoFinished' |
| **`listenerFunc`** | (data: CaptureResult) => void |

**Returns:** Promise<PluginListenerHandle>

--------------------

### addListener('capturePhotoFinished', ...)

```typescript
addListener(eventName: 'capturePhotoFinished', listenerFunc: (data: CaptureResult) => void) => Promise
```

| Param | Type |
| ------------------ | -------------------------------------------------------------------------- |
| **`eventName`** | 'capturePhotoFinished' |
| **`listenerFunc`** | (data: CaptureResult) => void |

**Returns:** Promise<PluginListenerHandle>

--------------------

### addListener('accelerometerOrientation', ...)

```typescript
addListener(eventName: 'accelerometerOrientation', listenerFunc: (data: { orientation: CustomOrientation; }) => void) => Promise
```

| Param | Type |
| ------------------ | ---------------------------------------------------------------------------------------------------- |
| **`eventName`** | 'accelerometerOrientation' |
| **`listenerFunc`** | (data: { orientation: CustomOrientation; }) => void |

**Returns:** Promise<PluginListenerHandle>

--------------------

### removeAllListeners()

```typescript
removeAllListeners() => Promise
```

--------------------

### Interfaces

#### PermissionStatus

- `camera` permission allows to take photo and record video without audio.
- `microphone` permission allows to record video with audio.

| Prop | Type |
| ---------------- | ----------------------------------------------------------- |
| **`camera`** | PermissionState |
| **`microphone`** | PermissionState |

#### PluginListenerHandle

| Prop | Type |
| ------------ | ----------------------------------------- |
| **`remove`** | () => Promise<void> |

#### CaptureSuccessResult

Represents the result of a successful capture operation.

| Prop | Type | Description |
| -------------- | ---------------------------------------- | ------------------------------------------------------------------------------ |
| **`mimeType`** | 'image/jpeg' \| 'video/mp4' | The MIME type of the captured media. Examples: "image/jpeg", "video/mp4". |
| **`name`** | string | The name of the captured media file. Examples: "my-photo.jpg", "my-video.mp4". |
| **`path`** | string | The path to the captured media file. Example: "file://path-to-my-video.mp4". |
| **`size`** | number | The size of the captured media file in bytes. Example: "7046447". |

#### CaptureErrorResult

Represents the result of a failed capture operation.

| Prop | Type | Description |
| ------------------ | ------------------- | ------------------------------------------------------ |
| **`errorMessage`** | string | The error message describing the cause of the failure. |

#### CaptureResult

| Prop | Type | Description |
| ------------------ | ------------------- | ------------------------------------------------------------------------------------------- |
| **`filePath`** | string | File path for photo or video taken by camera. Example: file://your-app-dir/.../my-video.mp4 |
| **`errorMessage`** | string | Error message if any |

### Type Aliases

#### PermissionState

'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'

#### CustomOrientation

'portraitUp' | 'portraitDown' | 'landscapeRight' | 'landscaperLeft'