import { inject , injectable } from 'inversify' ; import * as apid from '../../../../../api' ; import UaUtil from '../../../util/UaUtil' ; import Util from '../../../util/Util' ; import IServerConfigModel from '../../serverConfig/IServerConfigModel' ; import { IOnAirSelectStreamSettingStorageModel } from '../../storage/onair/IOnAirSelectStreamSettingStorageModel' ; import { ISettingStorageModel } from '../../storage/setting/ISettingStorageModel' ; import IOnAirSelectStreamState , { LiveStreamType , StreamConfigItem } from './IOnAirSelectStreamState' ; @ injectable ( ) export default class OnAirSelectStreamState implements IOnAirSelectStreamState { public isOpen : boolean = false ; public useURLScheme : boolean = false ; public streamTypes : LiveStreamType [ ] = [ ] ; public streamConfigItems : StreamConfigItem [ ] = [ ] ; public selectedStreamType : LiveStreamType | undefined ; public selectedStreamConfig : number | undefined ; private serverConfig : IServerConfigModel ; private settingModel : ISettingStorageModel ; private streamSelectSetting : IOnAirSelectStreamSettingStorageModel ; private channelItem : apid . ScheduleChannleItem | null = null ; private streamConfig : { [ type ] : string [ ] ; } = { } ; constructor ( @ inject ( 'IServerConfigModel' ) serverConfig , @ inject ( 'ISettingStorageModel' ) settingModel , @ inject ( 'IOnAirSelectStreamSettingStorageModel' ) streamSelectSetting ) { this . serverConfig = serverConfig ; this . settingModel = settingModel ; this . streamSelectSetting = streamSelectSetting ; } param channelItem public open ( channelItem ) { this . isOpen = true ; this . channelItem = channelItem ; this . useURLScheme = this . streamSelectSetting . getSavedValue ( ) . useURLScheme ; this . updateStreamTypes ( true ) ; this . updateStreamConfig ( true ) ; } /**
     * ダイアログを閉じる
     */ public close ( ) { if ( typeof this . selectedStreamType !== 'undefined' && typeof this . selectedStreamConfig !== 'undefined' ) { this . streamSelectSetting . tmp . useURLScheme = this . useURLScheme ; this . streamSelectSetting . tmp . type = this . selectedStreamType as string ; this . streamSelectSetting . tmp . mode = typeof this . selectedStreamConfig === 'undefined' ? 0 : this . selectedStreamConfig ; this . streamSelectSetting . save ( ) ; } this . isOpen = false ; this . channelItem = null ; } return public getChannelItem ( ) { return this . channelItem ; } /**
     * 配信方式の更新
     */ public updateStreamTypes ( isInit = false ) { this . streamTypes = [ ] ; this . streamConfig = { } ; const config = this . serverConfig . getConfig ( ) ; if ( config !== null && config . isEnableTSLiveStream === true && typeof config . streamConfig !== 'undefined' && typeof config . streamConfig . live !== 'undefined' && typeof config . streamConfig . live . ts !== 'undefined' ) { if ( this . useURLScheme === true ) { if ( typeof config . streamConfig . live . ts . m2ts !== 'undefined' && config . streamConfig . live . ts . m2ts . length > 0 ) { this . streamTypes . push ( 'M2TS' ) ; this . streamConfig [ 'M2TS' ] = config . streamConfig . live . ts . m2ts . map ( c => { return c . name ; } ) ; } } else { if ( typeof config . streamConfig . live . ts . m2tsll !== 'undefined' && config . streamConfig . live . ts . m2tsll . length > 0 ) { this . streamTypes . push ( 'M2TS-LL' ) ; this . streamConfig [ 'M2TS-LL' ] = config . streamConfig . live . ts . m2tsll ; } if ( typeof config . streamConfig . live . ts . webm !== 'undefined' && config . streamConfig . live . ts . webm . length > 0 ) { this . streamTypes . push ( 'WebM' ) ; this . streamConfig [ 'WebM' ] = config . streamConfig . live . ts . webm ; } if ( typeof config . streamConfig . live . ts . mp4 !== 'undefined' && config . streamConfig . live . ts . mp4 . length > 0 ) { this . streamTypes . push ( 'MP4' ) ; this . streamConfig [ 'MP4' ] = config . streamConfig . live . ts . mp4 ; } if ( typeof config . streamConfig . live . ts . hls !== 'undefined' && config . streamConfig . live . ts . hls . length > 0 ) { this . streamTypes . push ( 'HLS' ) ; this . streamConfig [ 'HLS' ] = config . streamConfig . live . ts . hls ; } } } if ( isInit === true ) { if ( typeof this . selectedStreamType === 'undefined' ) { const savedType = this . streamSelectSetting . getSavedValue ( ) . type ; const newSelectedStreamType = this . streamTypes . find ( type => { return type === savedType ; } ) ; this . selectedStreamType = typeof newSelectedStreamType === 'undefined' ? this . streamTypes [ 0 ] : newSelectedStreamType ; } } else { this . selectedStreamType = this . streamTypes [ 0 ] ; } } /**
     * ストリーム設定の更新
     */ public updateStreamConfig ( isInit = false ) { this . streamConfigItems = this . getStreamConfig ( ) . map ( ( c , i ) => { return { text : c , value : i , } ; } ) ; if ( isInit === true ) { this . selectedStreamConfig = this . streamSelectSetting . getSavedValue ( ) . mode ; } if ( typeof this . selectedStreamConfig === 'undefined' || typeof this . streamConfigItems [ this . selectedStreamConfig ] === 'undefined' ) { this . selectedStreamConfig = 0 ; } } param type return private getStreamConfig ( ) { const result = typeof this . selectedStreamType === 'undefined' ? [ ] : this . streamConfig [ this . selectedStreamType ] ; return typeof result === 'undefined' ? [ ] : result ; } return public getM2TSURL ( ) { const channel = this . getChannelItem ( ) ; if ( typeof this . selectedStreamConfig === 'undefined' || channel === null ) { return null ; } const config = this . serverConfig . getConfig ( ) ; let urlScheme = null ; const settingURLScheme = this . settingModel . getSavedValue ( ) . onAirM2TSViewURLScheme ; if ( settingURLScheme !== null && settingURLScheme . length > 0 ) { urlScheme = settingURLScheme ; } else if ( config !== null ) { if ( UaUtil . isiOS ( ) === true && typeof config . urlscheme . m2ts . ios !== 'undefined' ) { urlScheme = config . urlscheme . m2ts . ios ; } else if ( UaUtil . isAndroid ( ) === true && typeof config . urlscheme . m2ts . android !== 'undefined' ) { urlScheme = config . urlscheme . m2ts . android ; } else if ( UaUtil . isMac ( ) === true && typeof config . urlscheme . m2ts . mac !== 'undefined' ) { urlScheme = config . urlscheme . m2ts . mac ; } else if ( UaUtil . isWindows ( ) === true && typeof config . urlscheme . m2ts . win !== 'undefined' ) { urlScheme = config . urlscheme . m2ts . win ; } } if ( urlScheme === null ) { return null ; } let viewURL = location . host + Util . getSubDirectory ( ) + `/api/streams/live/${ channel . id . toString ( 10 ) }/m2ts?mode=${ this . selectedStreamConfig }` ; if ( urlScheme . match ( /vlc-x-callback/ ) ) { viewURL = encodeURIComponent ( viewURL ) ; } return urlScheme . replace ( /PROTOCOL/g , location . protocol . replace ( ':' , '' ) ) . replace ( /ADDRESS/g , viewURL ) ; } return public getM2TPlayListURL ( ) { const channel = this . getChannelItem ( ) ; if ( typeof this . selectedStreamConfig === 'undefined' || channel === null ) { return null ; } return `/api/streams/live/${ channel . id . toString ( 10 ) }/m2ts/playlist?mode=${ this . selectedStreamConfig }` ; } }