diff --git a/packages/app/src/pages/live/[key].jsx b/packages/app/src/pages/live/[key].jsx index a176ff66..e063757b 100755 --- a/packages/app/src/pages/live/[key].jsx +++ b/packages/app/src/pages/live/[key].jsx @@ -23,14 +23,12 @@ export default class StreamViewer extends React.Component { loading: true, cinemaMode: false, - streamSources: null, - streamInfo: null, + stream: null, + spectators: 0, player: null, decoderInstance: null, - - plyrOptions: {}, } videoPlayerRef = React.createRef() @@ -60,9 +58,12 @@ export default class StreamViewer extends React.Component { decoderInstance.on(mpegts.Events.ERROR, this.onSourceEnd) decoderInstance.attachMediaElement(this.videoPlayerRef.current) + decoderInstance.load() - await decoderInstance.play() + await decoderInstance.play().catch((error) => { + console.error(error) + }) this.toggleLoading(false) @@ -125,54 +126,42 @@ export default class StreamViewer extends React.Component { }) } - loadStreamInfo = async (username) => { - const streamInfo = await Livestream.getStreamInfo({ username }).catch((error) => { + loadStream = async (payload) => { + const stream = await Livestream.getLivestream({ + username: payload.username, + profile_id: payload.profile, + }).catch((error) => { console.error(error) return null }) - if (!streamInfo) { + if (!stream) { return false } - console.log("Stream info", streamInfo) + console.log("Stream data >", stream) this.setState({ - streamInfo: streamInfo, - }) - } - - loadStreamSources = async (username) => { - const streamSources = await Livestream.getLivestream({ username }).catch((error) => { - console.error(error) - - this.onSourceEnd(error) - - return null + stream: stream, + spectators: stream.connectedClients, }) - if (!streamSources) { - return false - } - - console.log("Stream sources", streamSources) - - this.setState({ - streamSources: streamSources, - spectators: streamSources.connectedClients, - }) + return stream } attachPlayer = () => { + // check if user has interacted with the page const player = new Plyr("#player", { clickToPlay: false, autoplay: true, + muted: true, controls: ["mute", "volume", "fullscreen", "airplay", "options", "settings",], settings: ["quality"], - ...this.state.plyrOptions, }) + player.muted = true + // insert a button to enter to cinema mode player.elements.buttons.fullscreen.insertAdjacentHTML("beforeBegin", `