# @theopenweb/get-user-media-mock

> Creates mock for getUserMedia so can use without Webcam.

Latest version **1.0.0** (published 2022-03-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @theopenweb/get-user-media-mock
pnpm add @theopenweb/get-user-media-mock
yarn add @theopenweb/get-user-media-mock
bun add @theopenweb/get-user-media-mock
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; large bundle.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-03-06 |
| First published | 2022-03-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.8 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | The Open Web |
| Maintainers | theopenweb_jp |
| Keywords | getUserMedia, navigator, mediaDevices, MediaStreamConstraints, MediaTrackConstraints, mock, video, audio, devices |

## Links

- npm: https://www.npmjs.com/package/@theopenweb/get-user-media-mock
- Repository: https://github.com/theopenwebjp/get-user-media-mock
- Homepage: https://theopenweb.info
- Issues: https://github.com/theopenwebjp/get-user-media-mock/issues
- npm.io page: https://npm.io/package/@theopenweb/get-user-media-mock

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2022-03-06

## README

# Description

Mock library for getUserMedia and related functions.

## Installation

`npm install @theopenweb/get-user-media-mock`

## Usage

The code below will automatically apply mocks to the following functions:

* navigator.getUserMedia
* navigator.mediaDevices.getUserMedia
* navigator.mediaDevices.enumerateDevices
* navigator.mediaDevices.getSupportedConstraints

```javascript
window.getUserMediaMock = new GetUserMediaMock();
getUserMediaMock.mock();
```

The code below will only apply mock stream if getUserMedia function(navigator.getUserMedia OR navigator.mediaDevices.getUserMedia) results in an error.

```javascript
window.getUserMediaMock = new GetUserMediaMock();
getUserMediaMock.fallbackMock();
```

For more advanced usage check [Functions].

## Functions

All functions below are on the main instance.
Type information uses TypeScript format. Types can be searched in the repository.

* setMediaUrl (url: string)
* setMockType (mockType: MockType)
* fallbackMock ()
* mock (options: MockOptions)
* restoreOldHandles ()
* getMockStreamFromConstraints
* getMockCanvasStream (constraints: MediaStreamConstraints)
* getMockMediaElementStream (constraints: MediaStreamConstraints)
* createStartedRandomCanvasDrawerInterval (canvas: HTMLCanvasElement)
* getConstraintBestValue (constraints: MediaStreamConstraints, type: MediaStreamTrackType, key: keyof MediaTrackConstraints)
* getMockDevices ()

## Support

Polyfills and transpiling(Babel, etc.) should be done outside of this library.

* [https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/captureStream](HTMLCanvasElement.captureStream)
* [https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/captureStream](HTMLMediaElement.captureStream)

## Dependencies

* [https://github.com/meenie/band.js](band.js - MIT)

## Test

```bash
npx http-server ./
# http://localhost:8080
```

## Test Media

Test Media are included for testing AND possibly mocking.
These media are not heavily depended on, so can be changed or removed if important.
If using build tools, the sizes should not be an issue. If there is an issue when building please contact.

* [http://freemusicarchive.org/music/Tequila_Moonrise/Best_Of__Pick_Your_Player/Tequila_Moonrise](Music - Public Domain Best_Of_-_Pick_Your_Player_-_09_Tequila_Moonrise)
* [https://videos.pexels.com/videos/video-of-people-walking-855564](Video - CC0 License)

---
_Source: https://npm.io/package/@theopenweb/get-user-media-mock · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
