import { inject , injectable } from 'inversify' ; import * as apid from '../../../../api' ; import IEncodeEvent , { FinishEncodeInfo } from '../../event/IEncodeEvent' ; import ILogger from '../../ILogger' ; import ILoggerModel from '../../ILoggerModel' ; import IIPCClient from '../../ipc/IIPCClient' ; import ISocketIOManageModel from '../socketio/ISocketIOManageModel' ; import IEncodeFinishModel from './IEncodeFinishModel' ; @ injectable ( ) export default class EncodeFinishModel implements IEncodeFinishModel { private log : ILogger ; private socket : ISocketIOManageModel ; private ipc : IIPCClient ; private encodeEvent : IEncodeEvent ; constructor ( @ inject ( 'ILoggerModel' ) logger , @ inject ( 'ISocketIOManageModel' ) socket , @ inject ( 'IIPCClient' ) ipc , @ inject ( 'IEncodeEvent' ) encodeEvent ) { this . log = logger . getLogger ( ) ; this . socket = socket ; this . ipc = ipc ; this . encodeEvent = encodeEvent ; } public set ( ) { this . encodeEvent . setAddEncode ( this . addEncode . bind ( this ) ) ; this . encodeEvent . setCancelEncode ( this . cancelEncode . bind ( this ) ) ; this . encodeEvent . setFinishEncode ( this . finishEncode . bind ( this ) ) ; this . encodeEvent . setErrorEncode ( this . errorEncode . bind ( this ) ) ; this . encodeEvent . setUpdateEncodeProgress ( this . updateEncodeProgress . bind ( this ) ) ; } param encodeId private addEncode ( _encodeId ) { this . socket . notifyClient ( ) ; } param encodeId private cancelEncode ( _encodeId ) { this . socket . notifyClient ( ) ; } param info private async finishEncode ( info ) { let newVideoFileId = null ; try { if ( info . fullOutputPath === null || info . filePath === null ) { await this . ipc . recorded . updateVideoFileSize ( info . videoFileId ) ; } else { const id = await this . ipc . recorded . addVideoFile ( { recordedId : info . recordedId , parentDirectoryName : info . parentDirName , filePath : info . filePath , type : 'encoded' , name : info . mode , } ) ; newVideoFileId = id ; } } catch ( err ) { this . log . encode . error ( 'finish encode error' ) ; this . log . encode . error ( err ) ; } if ( info . removeOriginal === true ) { await this . ipc . recorded . deleteVideoFile ( info . videoFileId , true ) ; } this . socket . notifyClient ( ) ; await this . ipc . encodeEvent . emitFinishEncode ( { recordedId : info . recordedId , videoFileId : newVideoFileId , mode : info . mode , } ) ; } /**
     * エンコード失敗処理
     */ private errorEncode ( ) { this . socket . notifyClient ( ) ; } /**
     * エンコード進捗情報更新
     */ private updateEncodeProgress ( ) { this . socket . notifyUpdateEncodeProgress ( ) ; } }