diff --git a/src/ReactPlayer.js b/src/ReactPlayer.js index cfed0da4..7c90f21f 100644 --- a/src/ReactPlayer.js +++ b/src/ReactPlayer.js @@ -1,21 +1,11 @@ -import React, { Component, PropTypes } from 'react' +import React, { Component } from 'react' import 'array.prototype.find' +import propTypes from './propTypes' import players from './players' export default class MediaPlayer extends Component { - static propTypes = { - url: PropTypes.string, - playing: PropTypes.bool, - volume: PropTypes.number, - width: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]), - height: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]), - onPlay: PropTypes.func, - onPause: PropTypes.func, - onBuffer: PropTypes.func, - onEnded: PropTypes.func, - onError: PropTypes.func - } + static propTypes = propTypes static defaultProps = { volume: 0.8, width: 640, diff --git a/src/players/Base.js b/src/players/Base.js index a06f0f88..dbbd2a51 100644 --- a/src/players/Base.js +++ b/src/players/Base.js @@ -1,20 +1,11 @@ -import { Component, PropTypes } from 'react' +import { Component } from 'react' + +import propTypes from '../propTypes' const UPDATE_FREQUENCY = 500 export default class Base extends Component { - static propTypes = { - url: PropTypes.string, - playing: PropTypes.bool, - volume: PropTypes.number, - width: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]), - height: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]), - onPlay: PropTypes.func, - onPause: PropTypes.func, - onBuffer: PropTypes.func, - onEnded: PropTypes.func, - onError: PropTypes.func - } + static propTypes = propTypes static defaultProps = { onProgress: function () {} } diff --git a/src/players/SoundCloud.js b/src/players/SoundCloud.js index dd29b743..73cdcc92 100644 --- a/src/players/SoundCloud.js +++ b/src/players/SoundCloud.js @@ -1,6 +1,7 @@ import React from 'react' import loadScript from 'load-script' +import propTypes from '../propTypes' import Base from './Base' const CLIENT_ID = 'e8b6f84fbcad14c301ca1355cae1dea2' @@ -10,7 +11,7 @@ const RESOLVE_URL = '//api.soundcloud.com/resolve.json' const MATCH_URL = /^https?:\/\/(soundcloud.com|snd.sc)\/(.*)$/ export default class SoundCloud extends Base { - static propTypes = Base.propTypes // HACK: Prevent lint error + static propTypes = propTypes static canPlay (url) { return MATCH_URL.test(url) } diff --git a/src/players/Vimeo.js b/src/players/Vimeo.js index b799e5f3..1d880e3a 100644 --- a/src/players/Vimeo.js +++ b/src/players/Vimeo.js @@ -1,5 +1,6 @@ import React from 'react' +import propTypes from '../propTypes' import Base from './Base' const IFRAME_SRC = 'https://player.vimeo.com/video/' @@ -7,7 +8,7 @@ const MATCH_URL = /https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\ const MATCH_MESSAGE_ORIGIN = /^https?:\/\/player.vimeo.com/ export default class Vimeo extends Base { - static propTypes = Base.propTypes // HACK: Prevent lint error + static propTypes = propTypes static canPlay (url) { return MATCH_URL.test(url) } diff --git a/src/players/YouTube.js b/src/players/YouTube.js index 2b0cb31d..0207a8a7 100644 --- a/src/players/YouTube.js +++ b/src/players/YouTube.js @@ -1,6 +1,7 @@ import React from 'react' import loadScript from 'load-script' +import propTypes from '../propTypes' import Base from './Base' const SDK_URL = '//www.youtube.com/iframe_api' @@ -9,7 +10,7 @@ const MATCH_URL = /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:em const PLAYER_ID = 'youtube-player' export default class YouTube extends Base { - static propTypes = Base.propTypes // HACK: Prevent lint error + static propTypes = propTypes static canPlay (url) { return MATCH_URL.test(url) } diff --git a/src/propTypes.js b/src/propTypes.js new file mode 100644 index 00000000..e205eadb --- /dev/null +++ b/src/propTypes.js @@ -0,0 +1,14 @@ +import { PropTypes } from 'react' + +export default { + url: PropTypes.string, + playing: PropTypes.bool, + volume: PropTypes.number, + width: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]), + height: PropTypes.oneOfType([ PropTypes.string, PropTypes.number ]), + onPlay: PropTypes.func, + onPause: PropTypes.func, + onBuffer: PropTypes.func, + onEnded: PropTypes.func, + onError: PropTypes.func +}