Skip to content

Commit

Permalink
Merge pull request #3 from CameraKit/develop
Browse files Browse the repository at this point in the history
v0.1.0
  • Loading branch information
austinkettner authored Jan 29, 2019
2 parents f02f4e3 + f4392a3 commit 0540021
Show file tree
Hide file tree
Showing 43 changed files with 4,659 additions and 1 deletion.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
indent_style = space
indent_size = 2
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#macOS files
.DS_Store

# Logs
logs
*.log
Expand Down Expand Up @@ -59,3 +62,7 @@ typings/

# next.js build output
.next
build

# Created directories
dist
106 changes: 105 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,105 @@
# camerakit-web
# CameraKit Web

## Setup and usage

Install the package:

```
$ npm install camerakit-web
```

Import it in your project

```js
import camerakit from "camerakit-web";

// ...

async function () {
const devices = await camerakit.getDevices();

const myStream = await camerakit.createCaptureStream({
audio: devices.audio[0],
video: devices.video[0]
});

myStream.setResolution({width: 1920, height: 1080});
const myPicture = myStream.shutter.capture();

myStream.recorder.start();

// Wait...

// Pause the recording & resume
myRecorder.pause();
myRecorder.start();

// Wait some more...

const recordedVideo = myRecorder.stop(); // Use the video yourself

myRecorder.downloadLatestRecoring(); // Download the video direct from browser

// Stop using camera
myStream.destroy();
}
```

## API documentation

### `camerakit`

| Name | Parameters | Return | Description |
| ------------------------------- | -------------------------------------------- | ----------------------------------------------------------------- | --------------------------------------------------------------- |
| `camerakit.getDevices` | none | `Promise<{audio: Array<MediaSource>, video: Array<MediaSource>}>` | Returns available media devices for streaming |
| `camerakit.createCaptureStream` | `{audio?: MediaSource, video?: MediaSource}` | `Promise<CaptureStream>` | Creates new `CaptureStream` instance with provided media inputs |

### `CaptureStream`

#### Instance methods

| Name | Parameters | Return | Description |
| ----------------------- | -------------------------------------------------------------------------------------- | ---------------------- | ------------------------------------------------------- |
| `stream.init` | none | `Promise<void>` | Initalizes stream and requests permissions from browser |
| `stream.setResolution` | `{width?: number, height?: number, aspect?: number, source?: "original" \| "preview"}` | `Promise<void>` | Sets the video resolution of the specified source |
| `stream.setSource` | `{audio?: MediaSource, video?: MediaSource, source?: "original" \| "preview"}` | `Promise<void>` | Overrides original media inputs for specified source |
| `stream.getMediaStream` | `{source?: "original" \| "preview"}` | `Promise<MediaStream>` | Returns raw `MediaStream` for use in video display |
| `stream.destroy` | none | `void` | Closes all open streams and cancels capture |

#### Properties

| Name | Type |
| ----------------- | ---------- |
| `stream.shutter` | `Shutter` |
| `stream.recorder` | `Recorder` |

### `Shutter`

Used for taking photos of the `CaptureStream`.

### Instance methods

| name | Parameters | Return | Description |
| ------------------------------- | ------------------------------------------------------- | --------- | ----------------------------------------------------- |
| `shutter.capture` | `{source?: "original" \| "preview", save?: boolean}` | `string` | Takes and returns picture from specified source |
| `shutter.captureAndDownload` | `{source?: "original" \| "preview", filename?: string}` | `boolean` | Calls `capture` and creates file download from result |
| `shutter.downloadLatestCapture` | `filename?: string` | `boolean` | Downloads the last picture taken |

### `Recorder`

Used for recording video of the the `CaptureStream`.

### Instance methods

| name | Parameters | Return | Description |
| ---------------------------------- | ------------------------------------ | --------- | ---------------------------------------------------------- |
| `recorder.start` | `{source?: "original" \| "preview"}` | `void` | Starts the recording from the specified source |
| `recorder.stop` | none | `?Blob` | Stops the recording and returns a completed video file |
| `recorder.pause` | none | `void` | Pauses the recording until resumed with `recorder.start()` |
| `recorder.getLatestRecording` | none | `?Blob` | Returns last recorded video file |
| `recorder.downloadLatestRecording` | `filename?: string` | `boolean` | Creates file download from last video recording |
| `recorder.setMimeType` | none | `void` | Sets the video recording mime type for all sources |

## License

CameraKit Website is [MIT License](https://github.com/CameraKit/CameraKit-Android/blob/master/LICENSE)
19 changes: 19 additions & 0 deletions docs/recorder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# `Recorder`

Used to create video recordings given a media stream.

### Example usage

```js
import * as CameraKitWeb from "camerakit-web";

const stream = // ... Setup & get devices here

const recorder = new CameraKitWeb.Recorder(stream);
recorder.startRecording();

// Video recording...


const videoBuffer = recorder.stopRecording();
```
9 changes: 9 additions & 0 deletions example/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as React from "react";
import * as ReactDOM from "react-dom";
import Example from "./pages/example";

let rootEl = document.getElementById("root");
if (!rootEl) {
throw new Error("Root element not found");
}
ReactDOM.render(<Example />, rootEl);
Loading

0 comments on commit 0540021

Please sign in to comment.