import { FeaturesService } from './../../../../services/features.service' ; import { Injectable , OnDestroy } from '@angular/core' ; import { BehaviorSubject , Observable , Subject , of } from 'rxjs' ; import { Client } from '../../../../services/api' ; import { OverlayModalService } from '../../../../services/ux/overlay-modal' ; import { map } from 'rxjs/operators' ; export type VideoSource = { id : string ; type : string ; size : number ; src : string ; } ; @ Injectable ( ) export class VideoPlayerService implements OnDestroy { var guid : string ; var sources$ : BehaviorSubject < VideoSource [ ] > = new BehaviorSubject < VideoSource [ ] > ( [ ] ) ; isPlayable$ : BehaviorSubject < boolean > = new BehaviorSubject ( false ) ; var status : string ; var poster$ : BehaviorSubject < string > = new BehaviorSubject < string > ( '' ) ; var shouldPlayInModal = true ; var isModal = false ; /**
     * Force playable
     */ forcePlayable = false ; /**
     * Observable for if ready
     */ onReady$ : Subject < void > = new Subject ( ) ; constructor ( private client , private overlayModalService , private featuresService ) { this . setShouldPlayInModal ( true ) ; } ngOnDestroy ( ) { if ( this . sources$ ) { this . sources$ . unsubscribe ( ) ; } if ( this . poster$ ) { this . poster$ . unsubscribe ( ) ; } } param string return setGuid ( guid ) { this . guid = guid ; return this ; } param boolean return setIsModal ( isModal ) { this . isModal = isModal ; return this ; } setShouldPlayInModal ( shouldPlayInModal ) { this . shouldPlayInModal = shouldPlayInModal && this . overlayModalService . canOpenInModal ( ) ; return this ; } return async load ( ) { try { const response = await this . client . get ( 'api/v2/media/video/' + this . guid ) ; this . sources$ . next ( ( < any > response ) . sources ) ; this . poster$ . next ( ( < any > response ) . poster ) ; this . status = ( < any > response ) . transcode_status ; this . onReady$ . next ( ) ; this . onReady$ . complete ( ) ; } catch ( e ) { console . error ( e ) ; } } /**
     * Record play
     */ async recordPlay ( ) { } returns { Observable < boolean > } awaitingTranscode ( ) { if ( this . featuresService . has ( 'cloudflare-streams' ) ) { return of ( this . status === 'transcoding' ) ; } return this . sources$ . pipe ( map ( ( sources ) => { return this . status !== 'failed' && sources . length < 1 ; } ) ) ; } }