Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ustream 2 #21

Merged
merged 2 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/ReactPlayer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ReactPlayer.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "maestro-react-player",
"version": "1.2.2",
"version": "1.2.3",
"description": "A React component for playing a variety of URLs, including file paths, YouTube, Facebook, Twitch, SoundCloud, Streamable, Vimeo, Wistia and DailyMotion",
"main": "lib/ReactPlayer.js",
"typings": "index.d.ts",
Expand Down
43 changes: 26 additions & 17 deletions src/players/UstreamLive.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react'

import { callPlayer, getSDK, randomString, queryString } from '../utils'
import { callPlayer, getSDK, randomString } from '../utils'
import createSinglePlayer from '../singlePlayer'

const SDK_URL = 'http://developers.ustream.tv/js/ustream-embedapi.min.js'
Expand All @@ -9,7 +9,7 @@ const MATCH_URL = /(ustream.tv\/channel\/)([^#&?/]*)/
const PLAYER_ID_PREFIX = 'UstreamLive-player-'
export class UstreamLive extends Component {
static displayName = 'UstreamLive';
static canPlay = url => MATCH_URL.test(url);
static canPlay = url => MATCH_URL.test(url)
static loopOnEnded = false;

playerID = PLAYER_ID_PREFIX + randomString()
Expand All @@ -19,32 +19,41 @@ export class UstreamLive extends Component {
const m = url.match(MATCH_URL)
return m[2]
}
load (url) {
componentDidUpdate (prevProps) {
// reset autoplay on reload
if (prevProps.url !== this.props.url) {
this.autoplay = null
}
}

load () {
const {onEnded, onError, onPause, onPlay, onReady, playing} = this.props
getSDK(SDK_URL, SDK_GLOBAL).then(UstreamEmbed => {
if (!this.container) return
this.autoplay = playing
this.currentTime = 0
this.player = UstreamEmbed(this.playerID)
this.player.currentTime = 0
this.player.addListener('playing', (type, playing) => {
if (playing) {
this.playTime = Date.now()
this.props.onPlay()
onPlay()
} else {
this.player.currentTime = this.getCurrentTime()
this.currentTime = this.getCurrentTime()
this.playTime = null
this.props.onPause()
onPause()
}
})
this.player.addListener('live', () => {
this.props.onReady()
onReady()
})
this.player.addListener('offline', () => {
this.props.onReady()
onReady()
})
this.player.addListener('finished', this.props.onEnded)
this.player.addListener('finished', onEnded)
this.player.getProperty('duration', (duration) => {
this.player.duration = duration || Infinity
})
}, this.props.onError)
}, onError)
}
// todo
mute = () => {}
Expand Down Expand Up @@ -73,8 +82,7 @@ export class UstreamLive extends Component {
if (this.playTime) {
playing = (Date.now() - this.playTime) / 1000
}

return this.player.currentTime + playing
return this.currentTime + playing
}
getSecondsLoaded () {
return null
Expand All @@ -89,15 +97,16 @@ export class UstreamLive extends Component {
width: '100%',
height: '100%'
}
const query = queryString({
autoplay: this.props.playing
})

if (![true, false].includes(this.autoplay)) {
this.autoplay = this.props.playing
}

return (
<iframe
id={this.playerID}
ref={this.ref}
src={`${base}/${channelId}?html5ui?${query}`}
src={`${base}/${channelId}?html5ui?autoplay=${this.autoplay}`}
frameBorder='0'
scrolling='no'
style={style}
Expand Down