A react component that wraps
getUserMedia
.
Using npm:
$ npm install --save @bsonntag/react-user-media
Using yarn:
$ yarn add @bsonntag/react-user-media
This module uses react's createContext
API,
so make sure you have at least version 16.3.0 installed.
import UserMedia from '@bsonntag/react-user-media';
import React from 'react';
const constraints = { video: true };
const App = () => (
<UserMedia constraints={constraints}>
{stream => (
<video
autoPlay
src={URL.createObjectURL(stream)}
/>
)}
</UserMedia>
);
children
- A function that receives theMediaStream
and renders something.constraints
- AMediaStreamConstraints
.onError
- A function that is called whengetUserMedia
throws.onMediaStream
- A function that receives theMediaStream
.placeholder
- An element that is rendered whilegetUserMedia
is being called.renderError
- A function that receives the error thrown bygetUserMedia
and renders something.
Please feel free to submit any issues or pull requests.
MIT