Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch #57

Merged
merged 22 commits into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d483b80
Set the viewport and media size when the stream is ready
xavierfoucrier Nov 20, 2019
4361d8e
Set ideal width/height constraints depending on instance properties
xavierfoucrier Nov 20, 2019
654db6d
Do not resize the video element
xavierfoucrier Nov 21, 2019
ed58588
Add `data-instacam` attributes on stream, buffer and blend layer elem…
xavierfoucrier Nov 21, 2019
c8ed980
Set the viewport size based on the video when the stream is ready
xavierfoucrier Nov 21, 2019
685d286
Store the current audio and video tracks in the hardware property
xavierfoucrier Nov 21, 2019
eb9c8c3
Use appropriate width/height for drawing on canvas
xavierfoucrier Nov 21, 2019
b1d2fe6
Improve the way hardware properties are set
xavierfoucrier Nov 22, 2019
51fd369
Fix DOMException on CanvasRenderingContext2D
xavierfoucrier Nov 22, 2019
b4d7e64
Remove duplicate track attribute
xavierfoucrier Nov 22, 2019
e2dadc3
Improve constraint syntax (`ideal` is the default value)
xavierfoucrier Nov 22, 2019
2402de3
Add `data-instacam` attributes on the viewport element
xavierfoucrier Nov 22, 2019
a7bbb69
Init the viewport based on the ideal user constraint request
xavierfoucrier Nov 23, 2019
3d21d96
Improve the blend layer position
xavierfoucrier Nov 23, 2019
f6aac44
Add a `pause` method
xavierfoucrier Nov 28, 2019
2489785
Add a note regarding the ESM implementation
xavierfoucrier Dec 1, 2019
a56120e
Group `pause` and `resume` with `start` and `stop`
xavierfoucrier Dec 1, 2019
af7a7c2
Group `(un)mute` with `pause` and `resume`
xavierfoucrier Dec 1, 2019
498fe34
Add `pause` and `resume` documentation
xavierfoucrier Dec 1, 2019
9981a6c
Add section about `data-instacam-*` attributes
xavierfoucrier Dec 1, 2019
98d3e3c
Documentation review for `width` and `height` properties
xavierfoucrier Dec 1, 2019
11726bc
Bump version
xavierfoucrier Dec 3, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 54 additions & 23 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ Here you will find the documentation describing how to use the module.
1. [How it works](#how-it-works)
2. [Markup](#markup)
3. [Usage](#usage)
4. [Properties](#properties)
5. [Methods](#methods)
6. [Callbacks](#callbacks)
7. [Demo](#demo)
4. [Data attributes](#data-attributes)
5. [Properties](#properties)
6. [Methods](#methods)
7. [Callbacks](#callbacks)
8. [Demo](#demo)


## How it works
Expand Down Expand Up @@ -62,6 +63,8 @@ As of May 2017, all major browsers have shipped a working implementation of **ES
</script>
```

> Note that you will need to **use the Instacam source files** as there is no ESM build today for this package

### Use with a CDN
To rapidly **include the minified production** file in your webpage, load the latest build from a **CDN** *(Content Delivery Network)* using a generic script markup:

Expand Down Expand Up @@ -99,6 +102,16 @@ let camera = new Instacam(
```


## Data attributes
Instacam add a set of `data-instacam-*` attributes in the DOM to easily add custom styles/scripts in your application.

- `data-instacam`
- `data-instacam-viewport`
- `data-instacam-stream`
- `data-instacam-buffer`
- `data-instacam-blend`


## Properties
### Getting property
The class properties are stored in the private `_props` attribute but can be **retrieved easily**. If you want to get the current level of the saturation CSS filter, you can do the following:
Expand All @@ -123,13 +136,13 @@ Instacam reference that details all properties of the class.
Type: `Length`
Default: `400`

The width represents **the width of the viewport**. It must fit to the aspect ratio property, by default a **4:3 ratio**, to render a proper image of the media stream, depending on the webcam specifications.
This represents **the ideal requested width** for the viewport. Depending on hardware capabilities, the device will try to be as close as possible to this value. If the requested width is not supported, it will fall back to the closest available width.

#### height
Type: `Length`
Default: `300`

The height represents **the height of the viewport**. It must fit to the aspect ratio property, by default a **4:3 ratio**, to render a proper image of the media stream, depending on the webcam specifications.
This represents **the ideal requested height** for the viewport. Depending on hardware capabilities, the device will try to be as close as possible to this value. If the requested height is not supported, it will fall back to the closest available height.

#### autostart
Type: `Boolean`
Expand Down Expand Up @@ -337,7 +350,7 @@ Instacam reference that details all methods of the class.
#### start ( )
Type: `Function`

The start method allows you to **start the capture of the webcam stream**. If the `autostart` parameter is set to `true`, you don't need to call this method, Instacam will do it for you. Note that both camera and sound will be started, depending on the properties you have defined.
The start method allows you to **start the capture of the webcam stream**. If the `autostart` parameter is set to `true`, you don't need to call this method, Instacam will do it for you. Both camera and sound will be started, depending on the properties you have defined.

```js
camera.start();
Expand All @@ -346,41 +359,34 @@ camera.start();
#### stop ( )
Type: `Function`

The stop method allows you to **stop the capture of the webcam stream**. Note that both camera and sound will be stopped.
The stop method allows you to **stop the capture of the webcam stream**. Both camera and sound will be stopped.

```js
camera.stop();
```

#### snap ([ *left, top, width, height* ])
#### pause ( )
Type: `Function`
Return: `ImageData`

The snap method allows you to **capture image data from a portion of the viewport**. All the parameters are of type `Number`. By default, `left` and `top` are equals to 0, and `width` and `height` are equals to the width and height of the viewport defined in the class properties. If you call this function without parameters, you will get the image data of the entire viewport. **[Take a look at the demo](#demo)** to see how it works.
The pause method allows you to **pause the capture of the webcam stream**. Both camera and sound will be paused. Note that this method will only pause the `<video>` media element rather than physically disabling the camera and microphone.

```js
// capture the entire viewport
let snapshot = camera.snap();

// capture an area of 100x200 from the top left side of the viewport
let snapshot = camera.snap(0, 0, 100, 200);
camera.pause();
```

#### save ([ *format, quality* ])
#### resume ( )
Type: `Function`
Return: `UTF-16 String`

The save method allows you to **save the viewport in a specific image format**. This method returns a `data:` URI, also called `DOMString`, containing a representation of the image in the specified `format`, default is set to `png`. The returned image is at **96dpi**. If the height or width of the viewport is 0, an empty string `data:,` is returned. If the format requested is not `image/png`, and the returned value starts with `data:image/png`, then the requested format is not supported. Chrome supports the `image/webp` format. If the requested format is `image/jpeg` or `image/webp`, then the second argument `quality`, if defined between 0 and 1, is treated as indicating **image quality**. By default, the image quality is set to 1. If you call this function without parameters, you will get a png file of good quality. **[Take a look at the demo](#demo)** to see how it works.
The resume method allows you to **resume the capture of the webcam stream**. Both camera and sound will be resumed.

```js
// convert the viewport and returns a DOMString
let data = camera.save('png', 0.75);
camera.resume();
```

#### mute ( )
Type: `Function`

The mute method allows you to **mute the microphone** of the camera. Note that this method will only mute the `<video>` media element rather than disabling the microphone.
The mute method allows you to **mute the microphone** of the camera. Note that this method will only mute the `<video>` media element rather than physically disabling the microphone.

```js
camera.mute();
Expand All @@ -389,12 +395,37 @@ camera.mute();
#### unmute ( )
Type: `Function`

The unmute method allows your to unmute the microphone of the camera. Note that this method will only mute the `<video>` media element rather than enabling the microphone.
The unmute method allows your to **unmute the microphone** of the camera. Note that this method will only unmute the `<video>` media element rather than physically enabling the microphone.

```js
camera.unmute();
```

#### snap ([ *left, top, width, height* ])
Type: `Function`
Return: `ImageData`

The snap method allows you to **capture image data from a portion of the viewport**. All the parameters are of type `Number`. By default, `left` and `top` are equals to 0, and `width` and `height` are equals to the width and height of the viewport defined in the class properties. If you call this function without parameters, you will get the image data of the entire viewport. **[Take a look at the demo](#demo)** to see how it works.

```js
// capture the entire viewport
let snapshot = camera.snap();

// capture an area of 100x200 from the top left side of the viewport
let snapshot = camera.snap(0, 0, 100, 200);
```

#### save ([ *format, quality* ])
Type: `Function`
Return: `UTF-16 String`

The save method allows you to **save the viewport in a specific image format**. This method returns a `data:` URI, also called `DOMString`, containing a representation of the image in the specified `format`, default is set to `png`. The returned image is at **96dpi**. If the height or width of the viewport is 0, an empty string `data:,` is returned. If the format requested is not `image/png`, and the returned value starts with `data:image/png`, then the requested format is not supported. Chrome supports the `image/webp` format. If the requested format is `image/jpeg` or `image/webp`, then the second argument `quality`, if defined between 0 and 1, is treated as indicating **image quality**. By default, the image quality is set to 1. If you call this function without parameters, you will get a png file of good quality. **[Take a look at the demo](#demo)** to see how it works.

```js
// convert the viewport and returns a DOMString
let data = camera.save('png', 0.75);
```


## Callbacks
### API
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ Here you will find the documentation describing **how to use** the library.
1. [How it works](DOCUMENTATION.md#how-it-works) - how the library do the stuff
2. [Markup](DOCUMENTATION.md#markup) - how should the HTML and CSS look like
3. [Usage](DOCUMENTATION.md#usage) - how to use Instacam
4. [Properties](DOCUMENTATION.md#properties) - all available properties
5. [Methods](DOCUMENTATION.md#methods) - all available methods
6. [Callbacks](DOCUMENTATION.md#callbacks) - all available callbacks
7. [Demo](DOCUMENTATION.md#demo) - Instacam in action
4. [Data attributes](DOCUMENTATION.md#data-attributes) - set of data attributes
5. [Properties](DOCUMENTATION.md#properties) - all available properties
6. [Methods](DOCUMENTATION.md#methods) - all available methods
7. [Callbacks](DOCUMENTATION.md#callbacks) - all available callbacks
8. [Demo](DOCUMENTATION.md#demo) - Instacam in action


## Contribute
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "instacam",
"year": "2019",
"version": "1.10.2",
"version": "1.11.0",
"description": "Instant canvas video",
"main": "dist/instacam.umd.js",
"unpkg": "dist/instacam.umd.js",
Expand Down
Loading