Skip to content

Commit

Permalink
Set Vimeo iframe src in play method instead of render
Browse files Browse the repository at this point in the history
* Allows us to render the Vimeo player without a valid URL, which helps us fix bugs
* More or less reverts commit d308aa6
  • Loading branch information
cookpete committed Dec 15, 2015
1 parent a9e9854 commit 355ffc5
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/players/Vimeo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import queryString from 'query-string'
import { stringify } from 'query-string'

import propTypes from '../propTypes'
import Base from './Base'
Expand Down Expand Up @@ -29,19 +29,26 @@ export default class Vimeo extends Base {
this.iframe = this.refs.iframe
super.componentDidMount()
}
shouldComponentUpdate (nextProps) {
return this.props.url !== nextProps.url
shouldComponentUpdate () {
return false
}
play (url) {
if (!url) {
if (url) {
const id = url.match(MATCH_URL)[3]
const iframeParams = {
...DEFAULT_IFRAME_PARAMS,
...this.props.vimeoConfig.iframeParams
}
this.iframe.src = IFRAME_SRC + id + '?' + stringify(iframeParams)
} else {
this.postMessage('play')
}
}
pause () {
this.postMessage('pause')
}
stop () {
// No need
this.iframe.src = ''
}
seekTo (fraction) {
this.postMessage('seekTo', this.duration * fraction)
Expand Down Expand Up @@ -81,19 +88,10 @@ export default class Vimeo extends Base {
return this.iframe.contentWindow && this.iframe.contentWindow.postMessage(data, this.origin)
}
render () {
const id = this.props.url.match(MATCH_URL)[3]
const style = {
width: '100%',
height: '100%'
}
const iframeParams = { ...DEFAULT_IFRAME_PARAMS, ...this.props.vimeoConfig.iframeParams }
return (
<iframe
ref='iframe'
src={IFRAME_SRC + id + '?' + queryString.stringify(iframeParams)}
style={style}
frameBorder='0'
/>
)
return <iframe ref='iframe' frameBorder='0' style={style} />
}
}

0 comments on commit 355ffc5

Please sign in to comment.