import { IRecordedSelectStreamSettingStorageModel } from '@/model/storage/recorded/IRecordedSelectStreamSettingStorageModel' ; import { inject , injectable } from 'inversify' ; import * as apid from '../../../../../../api' ; import IServerConfigModel from '../../../serverConfig/IServerConfigModel' ; import IRecordedDetailSelectStreamState , { RecordedStreamType , StreamConfigItem } from './IRecordedDetailSelectStreamState' ; @ injectable ( ) export default class RecordedDetailSelectStreamState implements IRecordedDetailSelectStreamState { public isOpen : boolean = false ; public streamTypeItems : RecordedStreamType [ ] = [ ] ; public streamModeItems : StreamConfigItem [ ] = [ ] ; public selectedStreamType : RecordedStreamType | undefined ; public title : string | null = null ; public selectedStreamMode : number | undefined ; private serverConfig : IServerConfigModel ; private streamSelectSetting : IRecordedSelectStreamSettingStorageModel ; private streamConfig : { [ type ] : string [ ] ; } = { } ; private videoFileId : apid . VideoFileId | null = null ; private recordedId : apid . RecordedId | null = null ; constructor ( @ inject ( 'IServerConfigModel' ) serverConfig , @ inject ( 'IRecordedSelectStreamSettingStorageModel' ) streamSelectSetting ) { this . serverConfig = serverConfig ; this . streamSelectSetting = streamSelectSetting ; } public open ( videoFile , recordedId ) { this . isOpen = true ; this . title = videoFile . name ; this . videoFileId = videoFile . id ; this . recordedId = recordedId ; this . streamModeItems = [ ] ; this . streamConfig = { } ; const config = this . serverConfig . getConfig ( ) ; if ( config !== null && typeof config . streamConfig !== 'undefined' && typeof config . streamConfig . recorded !== 'undefined' ) { const ts = config . streamConfig . recorded . ts ; const encoded = config . streamConfig . recorded . encoded ; if ( videoFile . type === 'ts' && config . isEnableTSRecordedStream === true && typeof ts !== 'undefined' ) { if ( typeof ts . webm !== 'undefined' && ts . webm . length > 0 ) { this . streamTypeItems . push ( 'WebM' ) ; this . streamConfig [ 'WebM' ] = ts . webm ; } if ( typeof ts . mp4 !== 'undefined' && ts . mp4 . length > 0 ) { this . streamTypeItems . push ( 'MP4' ) ; this . streamConfig [ 'MP4' ] = ts . mp4 ; } if ( typeof ts . hls !== 'undefined' && ts . hls . length > 0 ) { this . streamTypeItems . push ( 'HLS' ) ; this . streamConfig [ 'HLS' ] = ts . hls ; } } else if ( videoFile . type === 'encoded' && config . isEnableEncodedRecordedStream === true && typeof encoded !== 'undefined' ) { if ( typeof encoded . webm !== 'undefined' && encoded . webm . length > 0 ) { this . streamTypeItems . push ( 'WebM' ) ; this . streamConfig [ 'WebM' ] = encoded . webm ; } if ( typeof encoded . mp4 !== 'undefined' && encoded . mp4 . length > 0 ) { this . streamTypeItems . push ( 'MP4' ) ; this . streamConfig [ 'MP4' ] = encoded . mp4 ; } if ( typeof encoded . hls !== 'undefined' && encoded . hls . length > 0 ) { this . streamTypeItems . push ( 'HLS' ) ; this . streamConfig [ 'HLS' ] = encoded . hls ; } } else { throw new Error ( 'VideoTypeError' ) ; } if ( typeof this . selectedStreamType === 'undefined' ) { const savedType = this . streamSelectSetting . getSavedValue ( ) . type ; const newSelectedStreamType = this . streamTypeItems . find ( type => { return type === savedType ; } ) ; this . selectedStreamType = typeof newSelectedStreamType === 'undefined' ? this . streamTypeItems [ 0 ] : newSelectedStreamType ; } } this . updateModeItems ( true ) ; } /**
     * ダイアログを閉じる
     */ public close ( ) { if ( typeof this . selectedStreamType !== 'undefined' && typeof this . selectedStreamMode !== 'undefined' ) { this . streamSelectSetting . tmp . type = this . selectedStreamType as string ; this . streamSelectSetting . tmp . mode = typeof this . selectedStreamMode === 'undefined' ? 0 : this . selectedStreamMode ; this . streamSelectSetting . save ( ) ; } this . isOpen = false ; } /**
     * 視聴設定の更新
     */ public updateModeItems ( isInit = false ) { this . streamModeItems = this . getModeItems ( ) . map ( ( text , i ) => { return { text : text , value : i , } ; } ) ; if ( isInit === true ) { this . selectedStreamMode = this . streamSelectSetting . getSavedValue ( ) . mode ; } if ( typeof this . selectedStreamMode === 'undefined' || typeof this . streamModeItems [ this . selectedStreamMode ] === 'undefined' ) { this . selectedStreamMode = 0 ; } } return private getModeItems ( ) { return typeof this . selectedStreamType === 'undefined' ? [ ] : this . streamConfig [ this . selectedStreamType ] ; } return public getVideoFileId ( ) { return this . videoFileId ; } return public getRecordedId ( ) { return this . recordedId ; } }