Skip to content

Commit 9c82bfd

Browse files
committed
Tidy up Wistia player
1 parent bede619 commit 9c82bfd

2 files changed

Lines changed: 24 additions & 33 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ReactPlayer
66
[![Dependency Status](https://img.shields.io/david/CookPete/react-player.svg)](https://david-dm.org/CookPete/react-player)
77
[![devDependency Status](https://img.shields.io/david/dev/CookPete/react-player.svg)](https://david-dm.org/CookPete/react-player?type=dev)
88

9-
A react component for playing media from YouTube, SoundCloud, Streamable, Vidme, Vimeo, or Wistia as well as supported media files. Used by [rplayr](http://rplayr.com), an app to generate playlists from Reddit URLs.
9+
A react component for playing a variety of URLs, including file paths, YouTube, SoundCloud, Streamable, Vidme, Vimeo and Wistia. Used by [rplayr](http://rplayr.com), an app to generate playlists from Reddit URLs.
1010

1111
The component parses a URL and loads in the appropriate markup and external SDKs to play media from [various sources](#supported-media). [Props](#props) can be passed in to control playback and react to events such as buffering or media ending.
1212

src/players/Wistia.js

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,36 @@ import loadScript from 'load-script'
44
import Base from './Base'
55

66
const SDK_URL = '//fast.wistia.com/assets/external/E-v1.js'
7+
const SDK_GLOBAL = 'Wistia'
78
const MATCH_URL = /^https?:\/\/(.+)?(wistia.com|wi.st)\/(medias|embed)\/(.*)$/
89

910
export default class Wistia extends Base {
1011
static displayName = 'Wistia'
1112
static canPlay (url) {
1213
return MATCH_URL.test(url)
1314
}
14-
constructor (props) {
15-
super(props)
16-
this.loadingSDK = true
17-
this.player = null
18-
}
1915
componentDidMount () {
2016
const { onStart, onPause, onEnded } = this.props
21-
this.getSDK().then((_script) => {
17+
this.loadingSDK = true
18+
this.getSDK().then(() => {
2219
window._wq = window._wq || []
23-
window._wq.push(
24-
{
25-
id: this.getVideoId(this.props.url),
26-
onReady: (video) => {
27-
this.loadingSDK = false
28-
this.player = video
29-
this.player.bind('start', onStart)
30-
this.player.bind('play', this.onPlay)
31-
this.player.bind('pause', onPause)
32-
this.player.bind('end', onEnded)
33-
this.onReady()
34-
}
20+
window._wq.push({
21+
id: this.getID(this.props.url),
22+
onReady: player => {
23+
this.loadingSDK = false
24+
this.player = player
25+
this.player.bind('start', onStart)
26+
this.player.bind('play', this.onPlay)
27+
this.player.bind('pause', onPause)
28+
this.player.bind('end', onEnded)
29+
this.onReady()
3530
}
36-
)
31+
})
3732
})
3833
}
3934
getSDK () {
4035
return new Promise((resolve, reject) => {
41-
if (window.Wistia) {
36+
if (window[SDK_GLOBAL]) {
4237
resolve()
4338
} else {
4439
loadScript(SDK_URL, (err, script) => {
@@ -48,13 +43,15 @@ export default class Wistia extends Base {
4843
}
4944
})
5045
}
46+
getID (url) {
47+
return url && url.match(MATCH_URL)[4]
48+
}
5149
load (url) {
52-
const wistiaId = this.getVideoId(url)
50+
const id = this.getID(url)
5351
if (this.isReady) {
54-
this.player.replaceWith(wistiaId)
52+
this.player.replaceWith(id)
5553
this.props.onReady()
5654
this.onReady()
57-
return
5855
}
5956
}
6057
play () {
@@ -93,22 +90,16 @@ export default class Wistia extends Base {
9390
getFractionLoaded () {
9491
return null
9592
}
96-
getVideoId (url) {
97-
return url && url.match(MATCH_URL)[4]
98-
}
99-
ref = container => {
100-
this.container = container
101-
}
10293
render () {
94+
const id = this.getID(this.props.url)
95+
const className = `wistia_embed wistia_async_${id}`
10396
const style = {
10497
width: '100%',
10598
height: '100%',
10699
display: this.props.url ? 'block' : 'none'
107100
}
108-
109-
const id = this.getVideoId(this.props.url)
110101
return (
111-
<div ref={this.ref} className={`wistia_embed wistia_async_${id}`} style={style} />
102+
<div className={className} style={style} />
112103
)
113104
}
114105
}

0 commit comments

Comments
 (0)