mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-11 03:24:16 +00:00
player events
This commit is contained in:
parent
0293a5cd6f
commit
a54304ec54
@ -15,6 +15,10 @@ const streamsSource = config.remotes.streamingApi
|
|||||||
|
|
||||||
export default class StreamViewer extends React.Component {
|
export default class StreamViewer extends React.Component {
|
||||||
state = {
|
state = {
|
||||||
|
isEnded: false,
|
||||||
|
isLoading: true,
|
||||||
|
endResult: false,
|
||||||
|
|
||||||
userData: null,
|
userData: null,
|
||||||
streamInfo: null,
|
streamInfo: null,
|
||||||
spectators: 0,
|
spectators: 0,
|
||||||
@ -67,10 +71,10 @@ export default class StreamViewer extends React.Component {
|
|||||||
// await for it
|
// await for it
|
||||||
await this.gatherStreamInfo()
|
await this.gatherStreamInfo()
|
||||||
|
|
||||||
// create timer
|
// // create timer
|
||||||
if (this.state.streamInfo.connectCreated) {
|
// if (this.state.streamInfo.connectCreated) {
|
||||||
this.createTimerCounter()
|
// this.createTimerCounter()
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount = () => {
|
componentWillUnmount = () => {
|
||||||
@ -106,7 +110,7 @@ export default class StreamViewer extends React.Component {
|
|||||||
username: this.state.streamKey,
|
username: this.state.streamKey,
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
antd.message.error(error.message)
|
antd.message.error(error)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -136,8 +140,8 @@ export default class StreamViewer extends React.Component {
|
|||||||
if (loadedProtocol === "hls") {
|
if (loadedProtocol === "hls") {
|
||||||
this.state.protocolInstance.levels.forEach((level, levelIndex) => {
|
this.state.protocolInstance.levels.forEach((level, levelIndex) => {
|
||||||
if (level.height === newQuality) {
|
if (level.height === newQuality) {
|
||||||
console.log("Found quality match with " + newQuality);
|
console.log("Found quality match with " + newQuality)
|
||||||
this.state.protocolInstance.currentLevel = levelIndex;
|
this.state.protocolInstance.currentLevel = levelIndex
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -198,8 +202,10 @@ export default class StreamViewer extends React.Component {
|
|||||||
const source = `${streamsSource}/stream/flv/${this.state.streamKey}`
|
const source = `${streamsSource}/stream/flv/${this.state.streamKey}`
|
||||||
|
|
||||||
const instance = mpegts.createPlayer({
|
const instance = mpegts.createPlayer({
|
||||||
|
enableWorker: true,
|
||||||
type: "flv",
|
type: "flv",
|
||||||
url: source,
|
url: source,
|
||||||
|
cors: true,
|
||||||
isLive: true
|
isLive: true
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -207,12 +213,50 @@ export default class StreamViewer extends React.Component {
|
|||||||
instance.load()
|
instance.load()
|
||||||
instance.play()
|
instance.play()
|
||||||
|
|
||||||
|
instance.on("error", (error) => {
|
||||||
|
console.error(error)
|
||||||
|
antd.message.error(error.toString())
|
||||||
|
|
||||||
|
//this.onSourceEnded(error)
|
||||||
|
})
|
||||||
|
|
||||||
|
// instance.on("onSourceOpen", this.onSourceLoading)
|
||||||
|
// instance.on(mpegts.Events["LOADING_COMPLETE"], this.onSourceLoadingDone)
|
||||||
|
// instance.on("onSourceEnded", this.onSourceEnded)
|
||||||
|
|
||||||
this.setState({ protocolInstance: instance, loadedProtocol: "flv" })
|
this.setState({ protocolInstance: instance, loadedProtocol: "flv" })
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onSourceLoading = () => {
|
||||||
|
this.setState({
|
||||||
|
isLoading: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
onSourceLoadingDone = () => {
|
||||||
|
console.log(`loaded ${this.state.loadedProtocol}`)
|
||||||
|
this.setState({
|
||||||
|
isLoading: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
onSourceEnded = () => {
|
||||||
|
console.log("Source ended")
|
||||||
|
this.setState({ isEnded: true })
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return <div className="stream">
|
return <div className="stream">
|
||||||
|
{
|
||||||
|
this.state.isEnded && <div className="stream_end">
|
||||||
|
<antd.Result>
|
||||||
|
<h1>
|
||||||
|
This stream is ended
|
||||||
|
</h1>
|
||||||
|
</antd.Result>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
<video ref={this.videoPlayerRef} id="player" />
|
<video ref={this.videoPlayerRef} id="player" />
|
||||||
<div className="panel">
|
<div className="panel">
|
||||||
<div className="info">
|
<div className="info">
|
||||||
@ -231,10 +275,6 @@ export default class StreamViewer extends React.Component {
|
|||||||
<Icons.Eye />
|
<Icons.Eye />
|
||||||
{this.state.spectators}
|
{this.state.spectators}
|
||||||
</div>
|
</div>
|
||||||
<div id="timeCount">
|
|
||||||
<Icons.Clock />
|
|
||||||
{this.state.timeFromNow}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="chatbox">
|
<div className="chatbox">
|
||||||
{/* TODO: Use chatbox component and join to stream channel using username */}
|
{/* TODO: Use chatbox component and join to stream channel using username */}
|
||||||
|
@ -4,6 +4,17 @@
|
|||||||
//justify-content: space-between;
|
//justify-content: space-between;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.stream_end {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 100;
|
||||||
|
background-color: rgba(0, 0, 0, 0.8);
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
.stream {
|
.stream {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user