2021-11-03 22:52:18 +01:00
// @flow
import React from 'react' ;
import { SITE _HELP _EMAIL } from 'config' ;
import Button from 'component/button' ;
2021-11-05 20:14:00 +01:00
import { killStream } from '$web/src/livestreaming' ;
2021-11-09 19:02:34 +01:00
import watchLivestreamStatus from '$web/src/livestreaming/long-polling' ;
2021-11-03 22:52:18 +01:00
import 'scss/component/claim-preview-reset.scss' ;
type Props = {
channelId : string ,
channelName : string ,
2021-11-05 20:14:00 +01:00
claimIsMine : boolean ,
2021-11-03 22:52:18 +01:00
doToast : ( { message : string , isError ? : boolean } ) => void ,
} ;
const ClaimPreviewReset = ( props : Props ) => {
2021-11-05 20:14:00 +01:00
const { channelId , channelName , claimIsMine , doToast } = props ;
2021-11-09 19:02:34 +01:00
const [ isLivestreaming , setIsLivestreaming ] = React . useState ( false ) ;
React . useEffect ( ( ) => {
return watchLivestreamStatus ( channelId , ( state ) => setIsLivestreaming ( state ) ) ;
} , [ channelId , setIsLivestreaming ] ) ;
if ( ! claimIsMine || ! isLivestreaming ) return null ;
2021-11-03 22:52:18 +01:00
const handleClick = async ( ) => {
try {
2021-11-05 20:14:00 +01:00
await killStream ( channelId , channelName ) ;
2021-11-03 22:52:18 +01:00
doToast ( { message : _ _ ( 'Live stream successfully reset.' ) , isError : false } ) ;
} catch {
doToast ( { message : _ _ ( 'There was an error resetting the live stream.' ) , isError : true } ) ;
}
} ;
return (
< p className = { 'claimPreviewReset' } >
< span className = { 'claimPreviewReset__hint' } >
{ _ _ (
"If you're having trouble starting a stream or if your stream shows that you're live but aren't, try a reset. If the problem persists, please reach out at %SITE_HELP_EMAIL%." ,
{ SITE _HELP _EMAIL }
) }
< / span >
< Button
button = "primary"
label = { _ _ ( 'Reset stream' ) }
className = { 'claimPreviewReset__button' }
onClick = { handleClick }
/ >
< / p >
) ;
} ;
export default ClaimPreviewReset ;