Skip to content

Commit

Permalink
Vimeo player improvements
Browse files Browse the repository at this point in the history
Like the FilePlayer, instead of dealing with src in methods, just let React rendering take care of it
  • Loading branch information
cookpete committed Oct 16, 2015
1 parent 237c51a commit d308aa6
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/players/Vimeo.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,19 @@ export default class Vimeo extends Base {
this.iframe = React.findDOMNode(this.refs.iframe)
super.componentDidMount()
}
shouldComponentUpdate () {
return false
shouldComponentUpdate (nextProps) {
return this.props.url !== nextProps.url
}
play (url) {
if (url) {
let id = url.match(MATCH_URL)[3]
this.iframe.src = IFRAME_SRC + id + '?api=1&autoplay=1&badge=0&byline=0&portrait=0&title=0'
} else {
if (!url) {
this.postMessage('play')
}
}
pause () {
this.postMessage('pause')
}
stop () {
this.iframe.src = ''
// No need
}
seekTo (fraction) {
this.postMessage('seekTo', this.duration * fraction)
Expand All @@ -49,7 +46,7 @@ export default class Vimeo extends Base {
onMessage = e => {
if (!MATCH_MESSAGE_ORIGIN.test(e.origin)) return
this.origin = this.origin || e.origin
let data = JSON.parse(e.data)
const data = JSON.parse(e.data)
if (data.event === 'ready') {
this.postMessage('getDuration')
this.postMessage('addEventListener', 'playProgress')
Expand All @@ -67,14 +64,22 @@ export default class Vimeo extends Base {
}
postMessage = (method, value) => {
if (!this.origin) return
let data = JSON.stringify({ method, value })
const data = JSON.stringify({ method, value })
return this.iframe.contentWindow && this.iframe.contentWindow.postMessage(data, this.origin)
}
render () {
let style = {
const id = this.props.url.match(MATCH_URL)[3]
const style = {
width: '100%',
height: '100%'
}
return <iframe ref='iframe' frameBorder='0' style={style} />
return (
<iframe
ref='iframe'
src={IFRAME_SRC + id + '?api=1&autoplay=1&badge=0&byline=0&portrait=0&title=0'}
style={style}
frameBorder='0'
/>
)
}
}

0 comments on commit d308aa6

Please sign in to comment.