Skip to content

Commit

Permalink
Use fetch-jsonp for SoundCloud resolve endpoint
Browse files Browse the repository at this point in the history
Also removes the need for fetch polyfill
Fixes cookpete/react-player#24
Should also fix cookpete/react-player#47
  • Loading branch information
webmiraclepro committed May 17, 2016
1 parent afb581f commit ba2c0ca
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,12 @@
},
"dependencies": {
"es6-promise": "^3.1.2",
"fetch-jsonp": "^1.0.0",
"load-script": "^1.0.0",
"query-string": "^4.1.0",
"whatwg-fetch": "^1.0.0"
"query-string": "^4.1.0"
},
"standard": {
"parser": "babel-eslint",
"global": [
"fetch"
],
"ignore": [
"/dist/*"
]
Expand Down
1 change: 0 additions & 1 deletion src/ReactPlayer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'es6-promise'
import 'whatwg-fetch'
import React, { Component } from 'react'

import { propTypes, defaultProps } from './props'
Expand Down
9 changes: 4 additions & 5 deletions src/players/SoundCloud.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import loadScript from 'load-script'
import fetchJSONP from 'fetch-jsonp'

import Base from './Base'

Expand Down Expand Up @@ -43,15 +44,13 @@ export default class SoundCloud extends Base {
if (songData[url]) {
return Promise.resolve(songData[url])
}
return fetch(RESOLVE_URL + '?url=' + url + '&client_id=' + this.props.soundcloudConfig.clientId)
return fetchJSONP(RESOLVE_URL + '?url=' + url + '&client_id=' + this.props.soundcloudConfig.clientId)
.then(response => {
if (response.status >= 200 && response.status < 300) {
if (response.ok) {
songData[url] = response.json()
return songData[url]
} else {
const error = new Error(response.statusText)
error.response = response
throw error
this.props.onError(new Error('SoundCloud track could not be resolved'))
}
})
}
Expand Down

0 comments on commit ba2c0ca

Please sign in to comment.