Skip to content

Commit

Permalink
Add hlsVersion and dashVersion file config
Browse files Browse the repository at this point in the history
Also bump to latest versions
Closes cookpete/react-player#513
  • Loading branch information
happydev829 committed Nov 17, 2018
1 parent 7ee84cc commit 38b08b9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Key | Options
`mixcloud` | `options`: Override the [default player options](https://www.mixcloud.com/developers/widget/#methods)
`dailymotion` | `params`: Override the [default player vars](https://developer.dailymotion.com/player#player-parameters)<br />`preload`: Used for [preloading](#preloading)
`twitch` | `options`: Override the [default player options](https://dev.twitch.tv/docs/embed)
`file` | `attributes`: Apply [element attributes](https://developer.mozilla.org/en/docs/Web/HTML/Element/video#Attributes)<br />`forceVideo`: Always render a `<video>` element<br />`forceAudio`: Always render an `<audio>` element<br />`forceHLS`: Use [hls.js](https://github.com/video-dev/hls.js) for HLS streams<br />`forceDASH`: Always use [dash.js](https://github.com/Dash-Industry-Forum/dash.js) for DASH streams<br />`hlsOptions`: Override the [default `hls.js` options](https://github.com/video-dev/hls.js/blob/master/docs/API.md#fine-tuning)
`file` | `attributes`: Apply [element attributes](https://developer.mozilla.org/en/docs/Web/HTML/Element/video#Attributes)<br />`forceVideo`: Always render a `<video>` element<br />`forceAudio`: Always render an `<audio>` element<br />`forceHLS`: Use [hls.js](https://github.com/video-dev/hls.js) for HLS streams<br />`forceDASH`: Always use [dash.js](https://github.com/Dash-Industry-Forum/dash.js) for DASH streams<br />`hlsOptions`: Override the [default `hls.js` options](https://github.com/video-dev/hls.js/blob/master/docs/API.md#fine-tuning)<br />`hlsVersion`: Override the [`hls.js`](https://github.com/video-dev/hls.js) version loaded from [`cdnjs`](https://cdnjs.com/libraries/hls.js), default: `0.10.1`<br />`dashVersion`: Override the [`dash.js`](https://github.com/Dash-Industry-Forum/dash.js) version loaded from [`cdnjs`](https://cdnjs.com/libraries/dashjs), default: `2.9.2`

##### Preloading

Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export interface FileConfig {
forceHLS?: boolean;
forceDASH?: boolean;
hlsOptions?: Object;
hlsVersion?: string;
dashVersion?: string;
}

export interface Config {
Expand Down
9 changes: 5 additions & 4 deletions src/players/FilePlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const IOS = typeof navigator !== 'undefined' && /iPad|iPhone|iPod/.test(navigato
const AUDIO_EXTENSIONS = /\.(m4a|mp4a|mpga|mp2|mp2a|mp3|m2a|m3a|wav|weba|aac|oga|spx)($|\?)/i
const VIDEO_EXTENSIONS = /\.(mp4|og[gv]|webm|mov|m4v)($|\?)/i
const HLS_EXTENSIONS = /\.(m3u8)($|\?)/i
const HLS_SDK_URL = 'https://cdnjs.cloudflare.com/ajax/libs/hls.js/0.9.1/hls.min.js'
const HLS_SDK_URL = 'https://cdnjs.cloudflare.com/ajax/libs/hls.js/VERSION/hls.min.js'
const HLS_GLOBAL = 'Hls'
const DASH_EXTENSIONS = /\.(mpd)($|\?)/i
const DASH_SDK_URL = 'https://cdnjs.cloudflare.com/ajax/libs/dashjs/2.6.5/dash.all.min.js'
const DASH_SDK_URL = 'https://cdnjs.cloudflare.com/ajax/libs/dashjs/VERSION/dash.all.min.js'
const DASH_GLOBAL = 'dashjs'
const MATCH_DROPBOX_URL = /www\.dropbox\.com\/.+/

Expand Down Expand Up @@ -117,8 +117,9 @@ export class FilePlayer extends Component {
return DASH_EXTENSIONS.test(url) || this.props.config.file.forceDASH
}
load (url) {
const { hlsVersion, dashVersion } = this.props.config.file
if (this.shouldUseHLS(url)) {
getSDK(HLS_SDK_URL, HLS_GLOBAL).then(Hls => {
getSDK(HLS_SDK_URL.replace('VERSION', hlsVersion), HLS_GLOBAL).then(Hls => {
this.hls = new Hls(this.props.config.file.hlsOptions)
this.hls.on(Hls.Events.ERROR, (e, data) => {
this.props.onError(e, data, this.hls, Hls)
Expand All @@ -128,7 +129,7 @@ export class FilePlayer extends Component {
})
}
if (this.shouldUseDASH(url)) {
getSDK(DASH_SDK_URL, DASH_GLOBAL).then(dashjs => {
getSDK(DASH_SDK_URL.replace('VERSION', dashVersion), DASH_GLOBAL).then(dashjs => {
this.dash = dashjs.MediaPlayer().create()
this.dash.initialize(this.player, url, this.props.playing)
this.dash.getDebug().setLogToBrowserConsole(false)
Expand Down
8 changes: 6 additions & 2 deletions src/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export const propTypes = {
forceAudio: bool,
forceHLS: bool,
forceDASH: bool,
hlsOptions: object
hlsOptions: object,
hlsVersion: string,
dashVersion: string
}),
wistia: shape({
options: object
Expand Down Expand Up @@ -131,7 +133,9 @@ export const defaultProps = {
forceAudio: false,
forceHLS: false,
forceDASH: false,
hlsOptions: {}
hlsOptions: {},
hlsVersion: '0.10.1',
dashVersion: '2.9.2'
},
wistia: {
options: {}
Expand Down

0 comments on commit 38b08b9

Please sign in to comment.