import { RtspMp4Pipeline } from './rtsp-mp4-pipeline' ; import { RtspConfig } from '../components/rtsp-session' ; import { WSConfig } from '../components/ws-source/openwebsocket' ; import { MseSink } from '../components/mse' ; import { WSSource } from '../components/ws-source' ; import { AuthConfig , Auth } from '../components/auth' ; import { MediaTrack } from '../utils/protocols/isom' ; export interface Html5VideoConfig { ws ? : WSConfig ; rtsp ? : RtspConfig ; mediaElement : HTMLVideoElement ; auth ? : AuthConfig ; } export class Html5VideoPipeline extends RtspMp4Pipeline { public onSourceOpen ? : ( mse : MediaSource , tracks : MediaTrack [ ] ) => void ; public onServerClose ? : ( ) => void ; public ready : Promise < void > ; public tracks ? : MediaTrack [ ] ; private _src ? : WSSource ; private readonly _sink : MseSink ; constructor ( config ) { const { ws : wsConfig , rtsp : rtspConfig , mediaElement , auth : authConfig , } = config ; super ( rtspConfig ) ; if ( authConfig ) { const auth = new Auth ( authConfig ) ; this . insertBefore ( this . rtsp , auth ) ; } const mseSink = new MseSink ( mediaElement ) ; mseSink . onSourceOpen = ( mse , tracks ) => { this . tracks = tracks ; this . onSourceOpen && this . onSourceOpen ( mse , tracks ) ; } ; this . append ( mseSink ) ; this . _sink = mseSink ; const waitForWs = WSSource . open ( wsConfig ) ; this . ready = waitForWs . then ( ( wsSource ) => { wsSource . onServerClose = ( ) => { this . onServerClose && this . onServerClose ( ) ; } ; this . prepend ( wsSource ) ; this . _src = wsSource ; } ) ; } close ( ) { this . _src && this . _src . outgoing . end ( ) ; } get currentTime ( ) { return this . _sink . currentTime ; } async play ( ) { return await this . _sink . play ( ) ; } pause ( ) { return this . _sink . pause ( ) ; } }