Skip to content

Commit eaf3da4

Browse files
authored
Merge pull request #74 from mderrick/v2
V2
2 parents 4911c7e + dbf8a7c commit eaf3da4

File tree

132 files changed

+2810
-5261
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+2810
-5261
lines changed

.babelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["es2015", "react"],
3+
"plugins": ["transform-runtime", "transform-object-rest-spread"]
4+
}

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ trim_trailing_whitespace = true
1313
[*.md]
1414
trim_trailing_whitespace = false
1515

16-
[{package.json}]
16+
[{package.json,.travis.yml}]
1717
# The indent size used in the `package.json` file cannot be changed
1818
# https://github.com/npm/npm/pull/3180#issuecomment-16336516
1919
indent_size = 2

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1+
node_modules
12
dist
2-
**/*.json

.eslintrc

Lines changed: 0 additions & 4 deletions
This file was deleted.

.eslintrc.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"node": true,
5+
"commonjs": true,
6+
"es6": true,
7+
"jest": true,
8+
"jasmine": true
9+
},
10+
"extends": "eslint:recommended",
11+
"parserOptions": {
12+
"ecmaFeatures": {
13+
"experimentalObjectRestSpread": true,
14+
"jsx": true
15+
},
16+
"sourceType": "module"
17+
},
18+
"plugins": [
19+
"react"
20+
],
21+
"rules": {
22+
"quotes": [
23+
"error",
24+
"single"
25+
],
26+
"react/jsx-uses-react": "error",
27+
"react/jsx-uses-vars": "error"
28+
}
29+
}

.gitignore

100644100755
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
.DS_Store
21
node_modules
3-
.grunt
4-
demo/dist
5-
npm-debug.log
2+
npm-debug.log
3+
.DS_Store
4+
dist

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6

.travis.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
language: node_js
2+
script:
3+
- npm run install:demo
4+
- npm run build:demo
5+
- npm run lint
6+
- npm test
7+
deploy:
8+
provider: npm
9+
10+
api_key:
11+
secure: AuzrPiUT3uzn5xbGNEQyKp3OZUtleFXM7dHmucoqDt3idfZxbxIaJ1R1Gw5NYMocBFQ3NC3SgbyIxDM9u7tbI4W3qXwYZWgF6nb10PAmPyPbGp+gZAr/X6a++c8BSDyqQINp5iHS10oL6tbWMxmCQsXweGySMyprxW2rccDvXob6eCAK6TK2ZJBfSdanAUh57FxIkSylFFnLt19n0C+qHHdEsLMSfquDgVomDMi/6EEskdeD9vxh9XpEog/UWp8uYdY9D5FslNB9AgDDoHHd3mhei9EhXinGtZiMTMB1RPoCKfDwd+iBuvu8LeTRi81GTXHzqLqBs/IIsM31Cn0CcKxdyktuaRmShtueCx0eJ/qWZ5Rq5ZCGEkMC7dG73FbC7IqLLhF/eOb8PNq1gWjXt8OOXrlJpyc4WCyeF9Z3NARPHCDaJcpmXhHb/ML2NnfPN9AGpMBVq1i50g32q9pFFnlU7w7FruhFMiVIuaStaF/6nxMLcV+alasD5zUiukdktnNGROgvj0yFFCb6dkXyhsVS3kqAdr++arNv1viIGWOxW1Wi+hbLyzc8ySbR/XX0Vngo2VUNGy7rwkwjC9Ui612JF7fbX/k5D9+MYOiqwHDjvQD/a4PILfgOUFJ3bpLUMdijD9eK4s+InoNM89GVY+HjCukAafC3fnUMIPPK6Zg=
12+
skip_cleanup: true
13+
on:
14+
tags: true
15+
repo: mderrick/react-html5video
16+
after_deploy:
17+
- npm run deploy:demo
18+
env:
19+
global:
20+
- secure: 0vVutNGKCFrTr0XOx06DEhoSuVBb+tkSo6EJUKswiwbyEHA3Na5uJZHv1fi2WB48dKkH1eyNOdiKGhVUt1v2Z8Vsb3FskUw17X/TU3iaKTWsZleuH1UCJJQCCvxogXOthz/nV5ITJ9X+S87ybErRq24aSEgs+ibN44EC+Glxzs7kbsawtPBLA7rzTFRyOWRa8441xhMOE4UUq6GzG9fQ4+hlQiLwi2xnOqSQsPRdLP9cV65Kz9FC2GsJ3GUBFtWu8Ub+GLWl7f7hvXonU/8yF+jueZyRq8cWSQRBTGF4CCzFvGTpVy5kmGvMxdSaDyvhu8hih3iuGVONoRR2cYihdyUFckvLvazVBSbGVyLDfuGLDhqilHsw+IE/e1AbqjkF75JKnKBnHWBZU7plPMadkI3HSEv/uJtyB0xdDfiUuXp0/ecKiDQNkn7RroRfewQ8WWIntA7K2u5KJzXoV6qiDB2ifMxE8Ms982okH+QVkbpBKHWpIsndq2NyN0aXW1kor2ZmLLN0rgWF0cGuE2BrswdKs2yXIFHAu4MoHqb/JuNzEuMkgAX1J+0Q6ah3Oto9pY0H1qj8eM55QKwGddERQnrFQCK5B05P2rGuUZ0OC/V490YJxJ/vLjtqZxnWFZURG6IRpIUTM1wE5muWqzgGsEVqW0p8Lzq8hDs7c/waku8=

Gruntfile.js

Lines changed: 0 additions & 40 deletions
This file was deleted.

README.md

Lines changed: 59 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,166 +1,118 @@
11
# react-html5video
22

3-
A customizeable HTML5 Video that uses the familiar HTML5 video markup but with custom and configurable controls with i18n and a11y.
3+
A customizeable HoC (Higher Order Component) for HTML5 Video that allows custom and configurable controls with i18n and a11y.
44

5+
V2 API has changed and is not backwards compatible. You can find the old documentation [here](https://github.com/mderrick/react-html5video/blob/1.4.0/README.md).
6+
7+
[![Build Status](https://travis-ci.org/mderrick/react-html5video.svg?branch=master)](https://travis-ci.org/mderrick/react-html5video)
58
[![npm version](https://img.shields.io/npm/v/react-html5video.svg?style=flat-square)](https://www.npmjs.com/package/react-html5video)
69
[![npm downloads](https://img.shields.io/npm/dm/react-html5video.svg?style=flat-square)](https://www.npmjs.com/package/react-html5video)
710

8-
<img src="http://mderrick.github.io/react-html5video/example.png?v=1" align="center" height="337" width="600" />
11+
<img src="http://mderrick.github.io/react-html5video/example.v2.png?v=1" align="center" height="337" width="600" />
912

1013
View the [demo](http://mderrick.github.io/react-html5video/).
1114

1215
## Install
1316

14-
`npm install react-html5video --save` or `bower install react-html5video --save`
15-
16-
Include `dist/ReactHtml5Video.css` if you do not want to build your own CSS. Alternatively require `src/assets/video.css` if you want to compile the CSS yourself with [css-loaders](https://github.com/webpack/css-loader) and [url-loaders](https://github.com/webpack/url-loader) etc. See the demo [Webpack config](https://github.com/mderrick/react-html5video/blob/master/demo/webpack.config.js) as an example.
17+
`npm install react-html5video --save`
1718

1819
### Peer Dependencies
1920

20-
This component uses ES2015 and needs to be transpiled using something like [babel-loader](https://github.com/babel/babel-loader). You will also need to either [polyfill](https://babeljs.io/docs/usage/polyfill/) or use [babel-runtime](https://www.npmjs.com/package/babel-runtime). It depends on:
21-
- `react@>=0.14.x`
22-
- `lodash.throttle@latest`.
23-
24-
### UMD
25-
26-
Alternatively if using the UMD module it is already transpiled to ES5 and `lodash.throttle` is included. You can find this build in the `dist` directory:
27-
28-
```js
29-
// Includes lodash.throttle and is transpiled already. No ES2015 polyfill is required.
30-
var Video = require('react-html5video/dist/ReactHtml5Video');
31-
```
32-
33-
```js
34-
// Exports to this global
35-
var Video = window.ReactHtml5Video.default;
36-
```
37-
38-
```js
39-
// Requires es6 transpiling, an es6 polyfill/babel-runtime and all peer dependencies installed
40-
import { default as Video, Controls, Play, Mute, Seek, Fullscreen, Time, Overlay } from 'react-html5video';
41-
```
42-
21+
- `react@>=15.0.x`
22+
- `react-dom@>=15.0.x`
4323

4424
## Usage
4525

4626
### Simple Usage
4727

48-
Use normal HTML5 `<video>` markup with all the standard [html attributes](https://developer.mozilla.org/en/docs/Web/HTML/Element/video) and supported [React media events](https://facebook.github.io/react/docs/events.html#media-events):
28+
The simplest way to use this component is to use the default player that is provided. It works the same way as a normal HTML5 video by taking all the supported [HTML5 video attributes](https://developer.mozilla.org/en/docs/Web/HTML/Element/video) except for `controls`. This is now "controlled" and can be an array of supported component names in any order as below:
4929

5030
```js
51-
import Video from 'react-html5video';
31+
import { DefaultPlayer as Video } from 'react-html5video';
32+
import 'react-html5video/dist/styles.css';
5233
render() {
5334
return (
54-
<Video controls autoPlay loop muted
35+
<Video autoPlay loop muted
36+
controls={['PlayPause', 'Seek', 'Time', 'Volume', 'Fullscreen']}
5537
poster="http://sourceposter.jpg"
5638
onCanPlayThrough={() => {
5739
// Do stuff
5840
}}>
5941
<source src="http://sourcefile.webm" type="video/webm" />
42+
<track label="English" kind="subtitles" srcLang="en" src="http://source.vtt" default />
6043
</Video>
6144
);
6245
}
6346
```
6447

65-
### Advanced Usage
48+
#### a11y* and i18n
6649

67-
You can configure, customize and modify the controls by adding, removing and shuffling them as you desire. You can create your very own custom children components and controls that can interact with the video. All children components will receive [these props](#props-and-methods). Obviously you can still call methods and set properties on the HTML5 DOM element directly if you have access to it with `refs`:
50+
The custom controls provided are built using `<button>` and `<input type="range">` which means basic keyboard controls are available when they are focused. For example, you can and hit the space bar on mute, play and fullscreen buttons as well as seek using the arrow keys when focused on the slider. `aria-label` attributes for screen readers have been used where user interaction is required. Try tabbing through the [demo](http://mderrick.github.io/react-html5video/) with [Vox](http://www.chromevox.com/) enabled.
51+
52+
You can change translate the `aria-label` values for all controls like so:
6853

6954
```js
70-
import { default as Video, Controls, Play, Mute, Seek, Fullscreen, Time, Overlay } from 'react-html5video';
71-
render() {
72-
return (
73-
<Video controls autoPlay loop muted poster="http://sourceposter.jpg">
74-
<source src="http://sourcefile.mp4" type="video/mp4" />
75-
<source src="http://sourcefile.webm" type="video/webm" />
76-
<h1>Optional HTML and components can be added also</h1>
77-
<CustomComponent />
78-
79-
/* As soon as a child is supplied that is not a `<source>`
80-
you have to define all controls and overlays as the default
81-
controls will have been removed. They are however exported
82-
and can be re-applied as below in any order. */
83-
<Overlay />
84-
<Controls>
85-
<Play />
86-
<Seek />
87-
<Time />
88-
<Mute />
89-
<Fullscreen />
90-
<CustomControlComponent />
91-
</Controls>
92-
</Video>
93-
);
94-
}
55+
<Video copy={{ key: value }}>
9556
```
9657

97-
## i18n
58+
The default english `copy` can be found in [here](https://github.com/mderrick/react-html5video/blob/master/src/DefaultPlayer/copy.js).
59+
60+
*Disclaimer: Unfortuantely I don't much experience with a11y but I have tried to use some of the features from [PayPal's accessible HTML5 player](https://github.com/paypal/accessible-html5-video-player). If anyone has further input on this please raise an issue or a pull request.
61+
62+
### Advanced Usage
9863

99-
There is some text used that could require translations. This can be done like so:
64+
If you want to get creative and create your own video player then you will need to use the higher order component. The HoC connects a React component to all the [HTML5 video attributes](https://developer.mozilla.org/en/docs/Web/HTML/Element/video) and the [HTMLMediaElement](https://developer.mozilla.org/en/docs/Web/API/HTMLMediaElement) of the first video it finds in the component it is wrapping.
10065

10166
```js
102-
<Video copyKeys={{ key: value }}>
67+
import videoConnect from 'react-html5video';
68+
69+
const MyVideoPlayer = ({ video, videoEl, children, ...restProps }) => (
70+
<div>
71+
<video {...restProps}>
72+
{ children }
73+
</video>
74+
<p>
75+
Here are the video properties for the above HTML5 video:
76+
{ JSON.stringify(video) }
77+
</p>
78+
<a href="#" onClick={(e) => {
79+
e.preventDefault();
80+
// You can do what you like with the HTMLMediaElement DOM element also.
81+
videoEl.pause();
82+
}}>
83+
Pause video
84+
</a>
85+
</div>
86+
);
87+
88+
export default videoConnect(MyVideoPlayer)
10389
```
10490

105-
The default english `copyKeys` can be found in [here](https://github.com/mderrick/react-html5video/tree/master/src/assets/copy.js).
91+
The above will simply print out the properties of the HTML5 `<video>` within `MyVideoPlayer`. Now you have these properties and the HTMLMediaElement itself available in your component, it is up to you to create your new custom controls using them. See the [default player](https://github.com/mderrick/react-html5video/blob/master/src/DefaultPlayer/DefaultPlayer.js) as an example.
10692

107-
## a11y*
93+
#### API
10894

109-
The custom controls provided are built using `<button>` and `<input type="range">` which means basic keyboard controls are available when they are focused. For example, you can and hit the space bar on mute, play and fullscreen buttons as well as seek using the arrow keys when focused on the slider. All inputs have a visible focus outline and can be tabbed to. `aria-label` attributes for screen readers have been used where user interaction is required. Try tabbing through the [demo](http://mderrick.github.io/react-html5video/) with [Vox](http://www.chromevox.com/) enabled.
95+
The API behaves much like the [React Redux](https://github.com/reactjs/react-redux/) connect HoC but instead of using dispatch to change the state, we have access to the [HTMLMediaElement](https://developer.mozilla.org/en/docs/Web/API/HTMLMediaElement).
11096

111-
*Disclaimer: Unfortuantely I don't much experience with a11y but I have tried to use some of the features from [PayPal's accessible HTML5 player](https://github.com/paypal/accessible-html5-video-player). If anyone has further input on this please raise an issue or a pull request.
97+
#### `videoConnect(ReactComponent, [mapStateToProps], [mapVideoElToProps], [mergeProps])`
98+
99+
- `mapStateToProps(videoState, ownProps)` - Use this to return the [HTML5 video attributes](https://developer.mozilla.org/en/docs/Web/HTML/Element/video) required for your component. The plain object returned here will be merged with what is returned from `mapVideoElToProps` using the `mergeProps` function. By Default this returns all video attributes so they are accessible on `this.props.video` in your wrapped component.
112100

101+
- `mapVideoElToProps(videoEl, videoState, ownProps)` - Use this to return a plain object that uses `videoEl` to update the videos state. `videoEl` is the raw [HTMLMediaElement](https://developer.mozilla.org/en/docs/Web/API/HTMLMediaElement). The object returned here will be merged with what is returned from `mapStateToProps` using the `mergeProps` function. By default the `videoEl` will be accessible on `this.props.videoEl` in your wrapped component.
113102

114-
## Props and Methods
115-
116-
All children components will receive the following properties via props:
117-
- `copyKeys`
118-
- `duration`
119-
- `currentTime`
120-
- `buffered`
121-
- `paused`
122-
- `muted`
123-
- `volume`
124-
- `playbackRate`
125-
- `percentageBuffered`
126-
- `percentagePlayed`
127-
128-
All children components receive the following methods via props:
129-
- `play`
130-
- `pause`
131-
- `togglePlay`
132-
- `mute`
133-
- `unmute`
134-
- `toggleMute`
135-
- `seek`
136-
- `fullscreen`
137-
- `setVolume`
138-
- `setPlaybackRate`
103+
- `mergeProps(stateProps, videoElProps, ownProps)` - If specified, it is passed the result of `mapStateToProps` `mapVideoElToProps` and the parent `props`. The plain object you return will be passed to your wrapped component. By default this will do `Object.assign({}, stateProps, videoElProps, ownProps)`.
139104

140105
## Contributing
141106

142107
### Dev Setup
143108

144-
To run a server with hot module replacement:
109+
To run a development server with HMR:
145110

146111
```bash
147-
$ npm install
148-
$ cd demo
149-
$ npm install
150-
$ npm run dev-server
112+
$ npm i
113+
$ npm run i:demo
114+
$ npm start
151115
```
152116

153-
Open [http://localhost:8082](http://localhost:8082). You can now modify the files in both `src` and `demo/src`.
154-
155-
### Issues
156-
157-
Feel free to raise and solve any existing issues as desired. Where possible please do try and replicate any bugs you may have using the [react-html5video jsfiddle](https://jsfiddle.net/mderrick/7s9a311q/1/) and include them in your ticket.
158-
159-
## Thank You
160-
161-
<img src="http://mderrick.github.io/react-html5video/browserstack.png?v=1" height="22" width="100" />
162-
163-
[BrowserStack](http://www.browserstack.com) for a free subscription to help test cross browser.
164-
165117
## License
166118
MIT

0 commit comments

Comments
 (0)