├── .babelrc ├── .editorconfig ├── .eslintignore ├── .eslintrc.json ├── .gitignore ├── .nvmrc ├── .travis.yml ├── LICENSE.md ├── README.md ├── __mocks__ ├── fileMock.js └── fileTransformer.js ├── browserslist ├── demo ├── .babelrc ├── assets │ ├── poster-big-buck-bunny.png │ ├── poster-sintel-trailer.png │ ├── sintel-en.vtt │ ├── sintel-es.vtt │ └── static │ │ ├── example.png │ │ └── example.v2.png ├── generateConfig.js ├── package.json ├── src │ ├── components │ │ ├── App.css │ │ ├── App.js │ │ └── App.test.js │ ├── entry.js │ └── index.html └── webpack.config.js ├── generateConfig.js ├── package-lock.json ├── package.json ├── postcss.config.js ├── scripts ├── deploy:demo.js └── start.js ├── src ├── DefaultPlayer │ ├── Captions │ │ ├── Captions.css │ │ ├── Captions.js │ │ └── Captions.test.js │ ├── DefaultPlayer.css │ ├── DefaultPlayer.js │ ├── DefaultPlayer.test.js │ ├── Fullscreen │ │ ├── Fullscreen.css │ │ ├── Fullscreen.js │ │ └── Fullscreen.test.js │ ├── Icon │ │ ├── closed_caption.svg │ │ ├── fullscreen.svg │ │ ├── fullscreen_exit.svg │ │ ├── pause.svg │ │ ├── play_arrow.svg │ │ ├── report.svg │ │ ├── spin.svg │ │ ├── volume_down.svg │ │ ├── volume_mute.svg │ │ ├── volume_off.svg │ │ └── volume_up.svg │ ├── Overlay │ │ ├── Overlay.css │ │ ├── Overlay.js │ │ └── Overlay.test.js │ ├── PlayPause │ │ ├── PlayPause.css │ │ ├── PlayPause.js │ │ └── PlayPause.test.js │ ├── Seek │ │ ├── Seek.css │ │ ├── Seek.js │ │ └── Seek.test.js │ ├── Time │ │ ├── Time.css │ │ ├── Time.js │ │ └── Time.test.js │ ├── Volume │ │ ├── Volume.css │ │ ├── Volume.js │ │ └── Volume.test.js │ └── copy.js ├── entry.js └── video │ ├── api.js │ ├── api.test.js │ ├── constants.js │ ├── video.js │ └── video.test.js └── webpack.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015", "react"], 3 | "plugins": ["transform-runtime", "transform-object-rest-spread"] 4 | } 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig: http://EditorConfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | indent_size = 4 9 | indent_style = space 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | 13 | [*.md] 14 | trim_trailing_whitespace = false 15 | 16 | [{package.json,.travis.yml}] 17 | # The indent size used in the `package.json` file cannot be changed 18 | # https://github.com/npm/npm/pull/3180#issuecomment-16336516 19 | indent_size = 2 20 | indent_style = space 21 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 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 | } 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | .DS_Store 4 | dist 5 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 6 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 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 | email: me@mattderrick.co.uk 10 | api_key: 11 | secure: ge4pjksEwP8kKRdS3nq1Bq7gPH9t9/G44vMqUd5BO5puR760jucvXCdqJ9isBzAHyXE7+0jbXmpE1KbUsiGqkasGEYsxtJYvx1Lb2F37e6W7QDRWxmN1AG0+MkTl49+RQFaL9uMLSWl9yStRWnzljcqbK8Jcnt8cE+JU1zvwCkKnokysyCbL7pz8w22fwuXZP8wg8wYZQL5c9mYRtNyUKFloNfADMEO1Zl0ZbpgBJdiT/MXtY6F1Y7mdCc+fCPucv0kbxoXm/kNsryYB0iLdtqwn3TW56Bwt+jaTEy2Wr62il1wST9/da4Iwzt5THLPO4+8sR2te45HkmaZmeRI92W6t7GUgseImTzYeFdxoyxXyziFH1hNTlOQuGDSie5DX87OXlEouILUmiLTcNZL0GrF6BALOyFB8ac/wtAO0OlVJqnMwlTI4s8K4yVBlP5cpRdPKVwbuwS/KX8pOhAmtRhyKgIBonsLuTp6GRkS1704Ui0nIJPjo65gOJIfnorYkKeJqrT6oDG1IUipCXX9vN5R0h00JqR3fOXsA1h6j1QFpg3hlG6UBXFWJ3SQdUUGjczy+z80sipRA2Kdf2TnFSKu1tVpRghWJ9bfmQmyN8NyzYCH9rxJj4K/Nh0TAi3J5Ns/6ypHwOg/9/s/8MhJUwE+FLaKy7NYl+RQXLnEeanA= 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: Jay4xSxm/nSDbbv7AghcCRCxbkzrX92SToFjW1ZvbnH/4gjgEHqNgaoZH/3mJ/s+1GyC9SCiAcOwlnCAGFabYdQNhwHBhQJFMK8v0WP2IKC2Vwh294sGPrCTvexRceumlh6y1la1KYYTuu6DDDsAaZ8eQcrK6hOcfuwl5xXB4xGNfshLavITs8a71F1RdX0cCa/ifSzbDjkfY1+1/o7vCCK595WP+WvTD/gA/OlpDygmtzJwg0400o9vmAlz7KzCLkk7pVakNODv3QvGHpd5n8jpzW30sHyKbnZfiqZPuw/6yV6NIYBmAXrviLUYQt07KU0IFWDO6cjc2H6puk3tL0yyZgZ0fMnin9mEGM0Rrf71zrtBH3XBhsLJGFK/vCuC1Kl+/mDSBrxm7koBawh7tzxOw7H2L3PMDin0A4MvUQS54ffGXd2AhNQKcf3w7eEb/kwdIOWPMcvDO7cca9OQxi50HB7bPOTsOIVflmCfgomBV2pwWAaAqcAGJni8dvp1BI8wN95bDLU1lSeTT/9RQlDRjykG5FzH/yBKhqVax+mtl6AxEFDHsZKE2Tc/mVqzpRChGJ9GF4N+E003qTaS6kTmqzYja/p9UL8aWThkQf4MnD91SR8duvD2wZOXoyNn+rSrrtZJ0p055mhms58ZbOSDgNPK8xSS0RZdPlwd+zo= 21 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Matt Derrick 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-html5video 2 | 3 | ### This component is no longer maintained. I would advise you use something similar to `useVideo` from [react-use](https://github.com/streamich/react-use/blob/master/docs/useVideo.md) instead. 4 | 5 | A customizeable HoC (Higher Order Component) for HTML5 Video that allows custom and configurable controls with i18n and a11y. 6 | 7 | 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). 8 | 9 | [![Build Status](https://travis-ci.org/mderrick/react-html5video.svg?branch=master)](https://travis-ci.org/mderrick/react-html5video) 10 | [![npm version](https://img.shields.io/npm/v/react-html5video.svg?style=flat-square)](https://www.npmjs.com/package/react-html5video) 11 | [![npm downloads](https://img.shields.io/npm/dm/react-html5video.svg?style=flat-square)](https://www.npmjs.com/package/react-html5video) 12 | 13 | 14 | 15 | View the [demo](http://mderrick.github.io/react-html5video/). 16 | 17 | ## Install 18 | 19 | `npm install react-html5video --save` 20 | 21 | ### Peer Dependencies 22 | 23 | - `react@>=15.0.x` 24 | - `react-dom@>=15.0.x` 25 | - `prop-types@>=15.0.x` 26 | 27 | ## Usage 28 | 29 | ### Simple Usage 30 | 31 | 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: 32 | 33 | ```js 34 | import { DefaultPlayer as Video } from 'react-html5video'; 35 | import 'react-html5video/dist/styles.css'; 36 | render() { 37 | return ( 38 | 47 | ); 48 | } 49 | ``` 50 | 51 | #### a11y* and i18n 52 | 53 | The custom controls provided are built using ` 20 | 32 | 33 | ); 34 | }; 35 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Captions/Captions.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { shallow } from 'enzyme'; 3 | import Captions from './Captions'; 4 | import styles from './Captions.css'; 5 | 6 | describe('Captions', () => { 7 | let component; 8 | 9 | beforeAll(() => { 10 | component = shallow( 11 | 12 | ); 13 | }); 14 | 15 | it('should accept a className prop and append it to the components class', () => { 16 | const newClassNameString = 'a new className'; 17 | expect(component.prop('className')) 18 | .toContain(styles.component); 19 | component.setProps({ 20 | className: newClassNameString 21 | }); 22 | expect(component.prop('className')) 23 | .toContain(styles.component); 24 | expect(component.prop('className')) 25 | .toContain(newClassNameString); 26 | }); 27 | 28 | it('has correct aria-label', () => { 29 | expect(component.find('button').prop('aria-label')) 30 | .toEqual('Captions'); 31 | }); 32 | }); 33 | -------------------------------------------------------------------------------- /src/DefaultPlayer/DefaultPlayer.css: -------------------------------------------------------------------------------- 1 | .component { 2 | position: relative; 3 | font-family: Helvetica; 4 | font-size: 11px; 5 | background-color: #000; 6 | } 7 | 8 | .video { 9 | width: 100%; 10 | height: 100%; 11 | } 12 | 13 | .controls { 14 | position: absolute; 15 | bottom: 0; 16 | right: 0; 17 | left: 0; 18 | height: 34px; 19 | display: flex; 20 | background-color: rgba(0,0,0,0.7); 21 | opacity: 0; 22 | transition: opacity 0.2s; 23 | } 24 | 25 | .seek { 26 | flex-grow: 1; 27 | } 28 | 29 | .component:hover .controls { 30 | opacity: 1; 31 | } 32 | -------------------------------------------------------------------------------- /src/DefaultPlayer/DefaultPlayer.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import videoConnect from './../video/video'; 4 | import copy from './copy'; 5 | import { 6 | setVolume, 7 | showTrack, 8 | toggleTracks, 9 | toggleMute, 10 | togglePause, 11 | setCurrentTime, 12 | toggleFullscreen, 13 | getPercentagePlayed, 14 | getPercentageBuffered 15 | } from './../video/api'; 16 | import styles from './DefaultPlayer.css'; 17 | import Time from './Time/Time'; 18 | import Seek from './Seek/Seek'; 19 | import Volume from './Volume/Volume'; 20 | import Captions from './Captions/Captions'; 21 | import PlayPause from './PlayPause/PlayPause'; 22 | import Fullscreen from './Fullscreen/Fullscreen'; 23 | import Overlay from './Overlay/Overlay'; 24 | 25 | const DefaultPlayer = ({ 26 | copy, 27 | video, 28 | style, 29 | controls, 30 | children, 31 | className, 32 | onSeekChange, 33 | onVolumeChange, 34 | onVolumeClick, 35 | onCaptionsClick, 36 | onPlayPauseClick, 37 | onFullscreenClick, 38 | onCaptionsItemClick, 39 | ...restProps 40 | }) => { 41 | return ( 42 |
47 | 52 | 55 | { controls && controls.length && !video.error 56 | ?
57 | { controls.map((control, i) => { 58 | switch (control) { 59 | case 'Seek': 60 | return ; 66 | case 'PlayPause': 67 | return ; 73 | case 'Fullscreen': 74 | return ; 79 | case 'Time': 80 | return
106 | : null } 107 |
108 | ); 109 | }; 110 | 111 | const controls = ['PlayPause', 'Seek', 'Time', 'Volume', 'Fullscreen', 'Captions']; 112 | 113 | DefaultPlayer.defaultProps = { 114 | copy, 115 | controls, 116 | video: {} 117 | }; 118 | 119 | DefaultPlayer.propTypes = { 120 | copy: PropTypes.object.isRequired, 121 | controls: PropTypes.arrayOf(PropTypes.oneOf(controls)), 122 | video: PropTypes.object.isRequired 123 | }; 124 | 125 | const connectedPlayer = videoConnect( 126 | DefaultPlayer, 127 | ({ networkState, readyState, error, ...restState }) => ({ 128 | video: { 129 | readyState, 130 | networkState, 131 | error: error || networkState === 3, 132 | // TODO: This is not pretty. Doing device detection to remove 133 | // spinner on iOS devices for a quick and dirty win. We should see if 134 | // we can use the same readyState check safely across all browsers. 135 | loading: readyState < (/iPad|iPhone|iPod/.test(navigator.userAgent) ? 1 : 4), 136 | percentagePlayed: getPercentagePlayed(restState), 137 | percentageBuffered: getPercentageBuffered(restState), 138 | ...restState 139 | } 140 | }), 141 | (videoEl, state) => ({ 142 | onFullscreenClick: () => toggleFullscreen(videoEl.parentElement), 143 | onVolumeClick: () => toggleMute(videoEl, state), 144 | onCaptionsClick: () => toggleTracks(state), 145 | onPlayPauseClick: () => togglePause(videoEl, state), 146 | onCaptionsItemClick: (track) => showTrack(state, track), 147 | onVolumeChange: (e) => setVolume(videoEl, state, e.target.value), 148 | onSeekChange: (e) => setCurrentTime(videoEl, state, e.target.value * state.duration / 100) 149 | }) 150 | ); 151 | 152 | export { 153 | connectedPlayer as default, 154 | DefaultPlayer, 155 | Time, 156 | Seek, 157 | Volume, 158 | Captions, 159 | PlayPause, 160 | Fullscreen, 161 | Overlay 162 | }; 163 | -------------------------------------------------------------------------------- /src/DefaultPlayer/DefaultPlayer.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { shallow } from 'enzyme'; 3 | import { DefaultPlayer } from './DefaultPlayer'; 4 | import styles from './DefaultPlayer.css'; 5 | import Time from './Time/Time'; 6 | import Seek from './Seek/Seek'; 7 | import Volume from './Volume/Volume'; 8 | import PlayPause from './PlayPause/PlayPause'; 9 | import Fullscreen from './Fullscreen/Fullscreen'; 10 | import Overlay from './Overlay/Overlay'; 11 | 12 | describe('DefaultPlayer', () => { 13 | let component; 14 | 15 | beforeAll(() => { 16 | component = shallow(); 17 | }); 18 | 19 | it('should accept a className prop and append it to the components class', () => { 20 | const newClassNameString = 'a new className'; 21 | expect(component.prop('className')) 22 | .toContain(styles.component); 23 | component.setProps({ 24 | className: newClassNameString 25 | }); 26 | expect(component.prop('className')) 27 | .toContain(styles.component); 28 | expect(component.prop('className')) 29 | .toContain(newClassNameString); 30 | }); 31 | 32 | it('applies `style` prop if provided', () => { 33 | component.setProps({ 34 | style: { color: 'red' } 35 | }); 36 | expect(component.prop('style')) 37 | .toEqual({ color: 'red' }); 38 | }); 39 | 40 | it('spreads all parent props on the video element', () => { 41 | component.setProps({ 42 | autoPlay: true 43 | }); 44 | expect(component.find('video').prop('autoPlay')) 45 | .toEqual(true); 46 | }); 47 | 48 | it('has an overlay component', () => { 49 | expect(component.find(Overlay).exists()) 50 | .toBeTruthy(); 51 | }); 52 | 53 | it('renders some default controls in a default order', () => { 54 | const controlsComponent = component.find(`.${styles.controls}`); 55 | expect(controlsComponent.childAt(0).is(PlayPause)) 56 | .toBeTruthy(); 57 | expect(controlsComponent.childAt(1).is(Seek)) 58 | .toBeTruthy(); 59 | expect(controlsComponent.childAt(2).is(Time)) 60 | .toBeTruthy(); 61 | expect(controlsComponent.childAt(3).is(Volume)) 62 | .toBeTruthy(); 63 | expect(controlsComponent.childAt(4).is(Fullscreen)) 64 | .toBeTruthy(); 65 | }); 66 | 67 | it('renders controls in a given custom order', () => { 68 | component.setProps({ 69 | controls: ['Fullscreen', 'Seek', 'Time'] 70 | }); 71 | const controlsComponent = component.find(`.${styles.controls}`); 72 | expect(controlsComponent.childAt(0).is(Fullscreen)) 73 | .toBeTruthy(); 74 | expect(controlsComponent.childAt(1).is(Seek)) 75 | .toBeTruthy(); 76 | expect(controlsComponent.childAt(2).is(Time)) 77 | .toBeTruthy(); 78 | }); 79 | 80 | it('renders no controls when given an empty array', () => { 81 | expect(component.find(`.${styles.controls}`).exists()) 82 | .toBeTruthy(); 83 | component.setProps({ 84 | controls: [] 85 | }); 86 | expect(component.find(`.${styles.controls}`).exists()) 87 | .toBeFalsy(); 88 | }); 89 | 90 | it('renders no controls when there is an error', () => { 91 | component.setProps({ 92 | controls: ['PlayPause'], 93 | video: { 94 | error: false 95 | } 96 | }); 97 | expect(component.find(`.${styles.controls}`).exists()) 98 | .toBeTruthy(); 99 | component.setProps({ 100 | controls: ['PlayPause'], 101 | video: { 102 | error: true 103 | } 104 | }); 105 | expect(component.find(`.${styles.controls}`).exists()) 106 | .toBeFalsy(); 107 | }); 108 | }); 109 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Fullscreen/Fullscreen.css: -------------------------------------------------------------------------------- 1 | .component {} 2 | 3 | .component:hover { 4 | background-color: #000; 5 | } 6 | 7 | .button { 8 | width: 34px; 9 | height: 34px; 10 | background: none; 11 | border: 0; 12 | color: inherit; 13 | font: inherit; 14 | line-height: normal; 15 | overflow: visible; 16 | padding: 0; 17 | cursor: pointer; 18 | } 19 | 20 | .button:focus { 21 | outline: 0; 22 | } 23 | 24 | .icon { 25 | padding: 5px; 26 | } 27 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Fullscreen/Fullscreen.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import styles from './Fullscreen.css'; 3 | import FullscreenIcon from './../Icon/fullscreen.svg'; 4 | 5 | export default ({ onClick, className, ariaLabel }) => { 6 | return ( 7 |
11 | 20 |
21 | ); 22 | }; 23 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Fullscreen/Fullscreen.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { shallow } from 'enzyme'; 3 | import Fullscreen from './Fullscreen'; 4 | import styles from './Fullscreen.css'; 5 | 6 | describe('Fullscreen', () => { 7 | let component; 8 | 9 | beforeAll(() => { 10 | component = shallow( 11 | 12 | ); 13 | }); 14 | 15 | it('should accept a className prop and append it to the components class', () => { 16 | const newClassNameString = 'a new className'; 17 | expect(component.prop('className')) 18 | .toContain(styles.component); 19 | component.setProps({ 20 | className: newClassNameString 21 | }); 22 | expect(component.prop('className')) 23 | .toContain(styles.component); 24 | expect(component.prop('className')) 25 | .toContain(newClassNameString); 26 | }); 27 | 28 | it('triggers \'onClick\' prop when the button is clicked', () => { 29 | const spy = jest.fn(); 30 | component.setProps({ 31 | onClick: spy 32 | }); 33 | expect(spy) 34 | .not.toHaveBeenCalled(); 35 | component.find('button').simulate('click'); 36 | expect(spy) 37 | .toHaveBeenCalled(); 38 | }); 39 | 40 | it('has correct aria-label', () => { 41 | expect(component.find('button').prop('aria-label')) 42 | .toEqual('Fullscreen'); 43 | }); 44 | }); 45 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Icon/closed_caption.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Icon/fullscreen.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Icon/fullscreen_exit.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Icon/pause.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Icon/play_arrow.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Icon/report.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Icon/spin.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Icon/volume_down.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Icon/volume_mute.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Icon/volume_off.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Icon/volume_up.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Overlay/Overlay.css: -------------------------------------------------------------------------------- 1 | .component { 2 | position: absolute; 3 | top: 0; 4 | right: 0; 5 | bottom: 0; 6 | left: 0; 7 | height: 100%; 8 | width: 100%; 9 | color: #fff; 10 | text-align: center; 11 | cursor: pointer; 12 | background-color: rgba(0,0,0,0); 13 | } 14 | 15 | .inner { 16 | display: inline-block; 17 | position: absolute; 18 | top: 50%; 19 | right: 0; 20 | left: 50%; 21 | width: 60px; 22 | height: 60px; 23 | transform: translateY(-50%); 24 | margin-left: -30px; 25 | background-color: rgba(0,0,0,0.7); 26 | border-radius: 10px; 27 | } 28 | 29 | .icon { 30 | position: absolute; 31 | top: 50%; 32 | right: 0; 33 | left: 50%; 34 | margin-left: -20px; 35 | transform: translateY(-50%); 36 | } 37 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Overlay/Overlay.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import styles from './Overlay.css'; 3 | import PlayArrow from './../Icon/play_arrow.svg'; 4 | import Spin from './../Icon/spin.svg'; 5 | import Report from './../Icon/report.svg'; 6 | 7 | export default class Overlay extends Component { 8 | renderContent () { 9 | const { 10 | error, 11 | paused, 12 | loading 13 | } = this.props; 14 | const iconProps = { 15 | className: styles.icon, 16 | height: 40, 17 | width: 40, 18 | fill: '#fff' 19 | }; 20 | if (error) { 21 | return ( 22 | 23 | 24 | 25 | ); 26 | } else if (loading) { 27 | return ( 28 | 29 | 30 | 31 | ); 32 | } else if (paused) { 33 | return ( 34 | 35 | 36 | 37 | ); 38 | } 39 | } 40 | 41 | render () { 42 | const { className, onClick } = this.props; 43 | return ( 44 |
49 | { this.renderContent() } 50 |
51 | ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Overlay/Overlay.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { shallow } from 'enzyme'; 3 | import Overlay from './Overlay'; 4 | import styles from './Overlay.css'; 5 | import PlayArrow from './../Icon/play_arrow.svg'; 6 | import Spin from './../Icon/spin.svg'; 7 | import Report from './../Icon/report.svg'; 8 | 9 | describe('Overlay', () => { 10 | let component; 11 | 12 | beforeAll(() => { 13 | component = shallow(); 14 | }); 15 | 16 | it('should accept a className prop and append it to the components class', () => { 17 | const newClassNameString = 'a new className'; 18 | expect(component.prop('className')) 19 | .toContain(styles.component); 20 | component.setProps({ 21 | className: newClassNameString 22 | }); 23 | expect(component.prop('className')) 24 | .toContain(styles.component); 25 | expect(component.prop('className')) 26 | .toContain(newClassNameString); 27 | }); 28 | 29 | it('shows a PlayArrow icon if paused', () => { 30 | component.setProps({ 31 | paused: true 32 | }); 33 | expect(component.html()) 34 | .toContain(PlayArrow); 35 | }); 36 | 37 | it('shows Report icon if error regardless of loading or paused state', () => { 38 | component.setProps({ 39 | error: true, 40 | loading: true, 41 | paused: true 42 | }); 43 | expect(component.html()) 44 | .toContain(Report); 45 | }); 46 | 47 | it('shows Spin icon if loading regardless of paused state', () => { 48 | component.setProps({ 49 | loading: true, 50 | paused: true, 51 | error: false 52 | }); 53 | expect(component.html()) 54 | .toContain(Spin); 55 | }); 56 | }); 57 | -------------------------------------------------------------------------------- /src/DefaultPlayer/PlayPause/PlayPause.css: -------------------------------------------------------------------------------- 1 | .component {} 2 | 3 | .component:hover { 4 | background-color: #000; 5 | } 6 | 7 | .button { 8 | width: 34px; 9 | height: 34px; 10 | background: none; 11 | border: 0; 12 | color: inherit; 13 | font: inherit; 14 | line-height: normal; 15 | overflow: visible; 16 | padding: 0; 17 | cursor: pointer; 18 | } 19 | 20 | .button:focus { 21 | outline: 0; 22 | } 23 | 24 | .icon { 25 | padding: 5px; 26 | } 27 | -------------------------------------------------------------------------------- /src/DefaultPlayer/PlayPause/PlayPause.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import styles from './PlayPause.css'; 3 | import PlayArrow from './../Icon/play_arrow.svg'; 4 | import Pause from './../Icon/pause.svg'; 5 | 6 | export default ({ onClick, paused, className, ariaLabelPlay, ariaLabelPause }) => { 7 | return ( 8 |
12 | 27 |
28 | ); 29 | }; 30 | -------------------------------------------------------------------------------- /src/DefaultPlayer/PlayPause/PlayPause.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { shallow } from 'enzyme'; 3 | import PlayPause from './PlayPause'; 4 | import styles from './PlayPause.css'; 5 | import PlayArrow from './../Icon/play_arrow.svg'; 6 | import Pause from './../Icon/pause.svg'; 7 | 8 | describe('PlayPause', () => { 9 | let component; 10 | 11 | beforeAll(() => { 12 | component = shallow( 13 | 16 | ); 17 | }); 18 | 19 | it('should accept a className prop and append it to the components class', () => { 20 | const newClassNameString = 'a new className'; 21 | expect(component.prop('className')) 22 | .toContain(styles.component); 23 | component.setProps({ 24 | className: newClassNameString 25 | }); 26 | expect(component.prop('className')) 27 | .toContain(styles.component); 28 | expect(component.prop('className')) 29 | .toContain(newClassNameString); 30 | }); 31 | 32 | it('triggers \'onClick\' prop when the button is clicked', () => { 33 | const spy = jest.fn(); 34 | component.setProps({ 35 | onClick: spy 36 | }); 37 | expect(spy) 38 | .not.toHaveBeenCalled(); 39 | component.find('button').simulate('click'); 40 | expect(spy) 41 | .toHaveBeenCalled(); 42 | }); 43 | 44 | describe('when paused', () => { 45 | beforeAll(() => { 46 | component.setProps({ 47 | paused: true 48 | }); 49 | }); 50 | 51 | it('shows a play icon', () => { 52 | expect(component.html()) 53 | .toContain(PlayArrow); 54 | expect(component.html()) 55 | .not.toContain(Pause); 56 | }); 57 | 58 | it('has correct aria-label', () => { 59 | expect(component.find('button').prop('aria-label')) 60 | .toEqual('Play'); 61 | }); 62 | }); 63 | 64 | describe('when playing', () => { 65 | beforeAll(() => { 66 | component.setProps({ 67 | paused: false 68 | }); 69 | }); 70 | 71 | it('shows a pause icon', () => { 72 | expect(component.html()) 73 | .toContain(Pause); 74 | expect(component.html()) 75 | .not.toContain(PlayArrow); 76 | }); 77 | 78 | it('has correct aria-label', () => { 79 | expect(component.find('button').prop('aria-label')) 80 | .toEqual('Pause'); 81 | }); 82 | }); 83 | }); 84 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Seek/Seek.css: -------------------------------------------------------------------------------- 1 | .component { 2 | position: relative; 3 | } 4 | 5 | .track { 6 | position: absolute; 7 | top: 50%; 8 | left: 5px; 9 | right: 5px; 10 | height: 4px; 11 | transform: translateY(-50%); 12 | background-color: #3e3e3e; 13 | } 14 | 15 | .buffer, 16 | .fill, 17 | .input { 18 | position: absolute; 19 | top: 0; 20 | left: 0; 21 | height: 100%; 22 | } 23 | 24 | .buffer { 25 | background-color: #5a5a5a; 26 | } 27 | 28 | .fill { 29 | background: #fff; 30 | } 31 | 32 | .input { 33 | width: 100%; 34 | opacity: 0; 35 | cursor: pointer; 36 | } 37 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Seek/Seek.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import styles from './Seek.css'; 3 | 4 | export default ({ onChange, percentagePlayed, percentageBuffered, className, ariaLabel }) => { 5 | return ( 6 |
10 |
11 |
16 |
21 | 31 |
32 |
33 | ); 34 | }; 35 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Seek/Seek.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { shallow } from 'enzyme'; 3 | import Seek from './Seek'; 4 | import styles from './Seek.css'; 5 | 6 | describe('Seek', () => { 7 | let component; 8 | 9 | beforeAll(() => { 10 | component = shallow(); 11 | }); 12 | 13 | it('should accept a className prop and append it to the components class', () => { 14 | const newClassNameString = 'a new className'; 15 | expect(component.prop('className')) 16 | .toContain(styles.component); 17 | component.setProps({ 18 | className: newClassNameString 19 | }); 20 | expect(component.prop('className')) 21 | .toContain(styles.component); 22 | expect(component.prop('className')) 23 | .toContain(newClassNameString); 24 | }); 25 | 26 | it('has a range input with correct ranges and percentagePlayed value', () => { 27 | component.setProps({ 28 | percentagePlayed: 10 29 | }); 30 | const rangeInput = component.find(`.${styles.input}`); 31 | expect(rangeInput.prop('type')) 32 | .toEqual('range'); 33 | expect(rangeInput.prop('orient')) 34 | .toEqual('horizontal'); 35 | expect(rangeInput.prop('step')) 36 | .toEqual(1); 37 | expect(rangeInput.prop('min')) 38 | .toEqual('0'); 39 | expect(rangeInput.prop('max')) 40 | .toEqual('100'); 41 | expect(rangeInput.prop('value')) 42 | .toEqual(10); 43 | }); 44 | 45 | it('handles an undefined percentagePlayed value', () => { 46 | component.setProps({ 47 | percentagePlayed: undefined 48 | }); 49 | const rangeInput = component.find(`.${styles.input}`); 50 | expect(rangeInput.prop('value')) 51 | .toEqual(0); 52 | }); 53 | 54 | it('triggers \'onChange\' prop when the input is changed', () => { 55 | const spy = jest.fn(); 56 | component.setProps({ 57 | onChange: spy 58 | }); 59 | expect(spy) 60 | .not.toHaveBeenCalled(); 61 | component.find('input').simulate('change'); 62 | expect(spy) 63 | .toHaveBeenCalled(); 64 | }); 65 | 66 | it('changes the played fill bar width', () => { 67 | component.setProps({ 68 | percentagePlayed: 0 69 | }); 70 | expect(component.find(`.${styles.fill}`).prop('style').width) 71 | .toEqual('0%'); 72 | component.setProps({ 73 | percentagePlayed: 11 74 | }); 75 | expect(component.find(`.${styles.fill}`).prop('style').width) 76 | .toEqual('11%'); 77 | }); 78 | 79 | it('changes the buffer bar width', () => { 80 | component.setProps({ 81 | percentageBuffered: 0 82 | }); 83 | expect(component.find(`.${styles.buffer}`).prop('style').width) 84 | .toEqual('0%'); 85 | component.setProps({ 86 | percentageBuffered: 11 87 | }); 88 | expect(component.find(`.${styles.buffer}`).prop('style').width) 89 | .toEqual('11%'); 90 | }); 91 | }); 92 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Time/Time.css: -------------------------------------------------------------------------------- 1 | .component { 2 | padding: 0 10px 0 10px; 3 | line-height: 35px; 4 | color: #fff; 5 | } 6 | 7 | .current { 8 | margin-right: 5px; 9 | } 10 | 11 | .duration { 12 | margin-left: 5px; 13 | color: #919191; 14 | } 15 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Time/Time.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import styles from './Time.css'; 3 | 4 | const formatTime = (seconds) => { 5 | const date = new Date(Date.UTC(1970,1,1,0,0,0,0)); 6 | seconds = isNaN(seconds) || seconds > 86400 7 | ? 0 8 | : Math.floor(seconds); 9 | date.setSeconds(seconds); 10 | const duration = date.toISOString().substr(11, 8).replace(/^0{1,2}:?0{0,1}/,''); 11 | return duration; 12 | }; 13 | 14 | export default ({ currentTime, duration, className }) => { 15 | return ( 16 |
20 | 21 | { formatTime(currentTime) } 22 | 23 | / 24 | 25 | { formatTime(duration) } 26 | 27 |
28 | ); 29 | }; 30 | -------------------------------------------------------------------------------- /src/DefaultPlayer/Time/Time.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { shallow } from 'enzyme'; 3 | import Time from './Time'; 4 | import styles from './Time.css'; 5 | 6 | describe('Time', () => { 7 | let component; 8 | 9 | beforeAll(() => { 10 | component = shallow(