import { inject , injectable } from 'inversify' ; import * as apid from '../../../../../api' ; import IStreamApiModel from '../../api/streams/IStreamApiModel' ; import ILiveHLSVideoState from './ILiveHLSVideoState' ; @ injectable ( ) class LiveHLSVideoState implements ILiveHLSVideoState { private streamApiModel : IStreamApiModel ; private streamId : apid . StreamId | null = null ; private keepTimerId : number | undefined ; constructor ( @ inject ( 'IStreamApiModel' ) streamApiModel ) { this . streamApiModel = streamApiModel ; } param channelId param mode return public async start ( channelId , mode ) { this . streamId = await this . streamApiModel . startLiveHLS ( channelId , mode ) ; this . keepTimerId = setInterval ( async ( ) => { if ( this . streamId === null ) { return ; } await this . streamApiModel . keep ( this . streamId ) ; } , LiveHLSVideoState . KEEP_INTERVAL * 1000 ) ; } return public async stop ( ) { if ( typeof this . keepTimerId !== 'undefined' ) { clearInterval ( this . keepTimerId ) ; this . keepTimerId = undefined ; } if ( this . streamId !== null ) { await this . streamApiModel . stop ( this . streamId ) ; this . streamId = null ; } } return public getStreamId ( ) { return this . streamId ; } return public async isEnabled ( ) { const info = await this . streamApiModel . getStreamInfo ( true ) ; for ( const item of info . items ) { if ( item . streamId === this . streamId && item . isEnable === true ) { return true ; } } return false ; } } namespace LiveHLSVideoState { export const KEEP_INTERVAL = 10 ; } export default LiveHLSVideoState ;