Last active
November 20, 2016 12:26
-
-
Save bikegriffith/111e1e1c57667574da7dba0210a7a407 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import Clappr from 'clappr'; | |
export default React.createClass({ | |
propTypes: { | |
source: React.PropTypes.string | |
}, | |
shouldComponentUpdate: function(nextProps, nextState) { | |
let changed = (nextProps.source != this.props.source); | |
this.props = nextProps; | |
this.state = nextState; | |
if (changed) { | |
this.change(nextProps.source); | |
} | |
return false; | |
}, | |
componentDidMount: function() { | |
this.change(this.props.source); | |
}, | |
componentWillUnmount: function() { | |
this.destroyPlayer(); | |
}, | |
destroyPlayer() { | |
if (this.player) { | |
this.player.destroy(); | |
} | |
this.player = null; | |
}, | |
change: function(source) { | |
if (this.player) { | |
this.destroyPlayer(); | |
} | |
this.player = new Clappr.Player({ | |
parent: this.refs.player, | |
source: source, | |
width: '100%', | |
height: '100%', | |
hlsjsConfig: { | |
enableWorker: true | |
} | |
}); | |
}, | |
render: function() { | |
return ( | |
<div> | |
<div ref="player"></div> | |
</div> | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment