import * as events from 'events' ; import { inject , injectable } from 'inversify' ; import * as apid from '../../../api' ; import ILogger from '../ILogger' ; import ILoggerModel from '../ILoggerModel' ; import IEncodeEvent , { FinishEncodeInfo } from './IEncodeEvent' ; @ injectable ( ) class EncodeEvent implements IEncodeEvent { private log : ILogger ; private emitter : events . EventEmitter = new events . EventEmitter ( ) ; constructor ( @ inject ( 'ILoggerModel' ) logger ) { this . log = logger . getLogger ( ) ; } param encodeId public emitAddEncode ( encodeId ) { this . emitter . emit ( EncodeEvent . ADD_ENCODE_EVENT , encodeId ) ; } param encodeId public emitCancelEncode ( encodeId ) { this . emitter . emit ( EncodeEvent . CANCEL_ENCODE_EVENT , encodeId ) ; } param info public emitFinishEncode ( info ) { this . emitter . emit ( EncodeEvent . FINISH_ENCODE_EVENT , info ) ; } /**
     * エンコード失敗イベント発行
     */ public emitErrorEncode ( ) { this . emitter . emit ( EncodeEvent . ERROR_ENCODE_EVENT ) ; } /**
     * エンコード進捗情報更新イベント発行
     */ public emitUpdateEncodeProgress ( ) { this . emitter . emit ( EncodeEvent . UPDATE_ENCODE_PROGRESS_EVENT ) ; } /**
     * エンコード更新イベント発行
     */ public emitupdateEncode ( ) { this . emitter . emit ( EncodeEvent . UPDATE_ENCODE_EVENT ) ; } param callback public setAddEncode ( callback ) { this . emitter . on ( EncodeEvent . ADD_ENCODE_EVENT , async ( encodeId ) => { try { await callback ( encodeId ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setCancelEncode ( callback ) { this . emitter . on ( EncodeEvent . CANCEL_ENCODE_EVENT , async ( encodeId ) => { try { await callback ( encodeId ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setFinishEncode ( callback ) { this . emitter . on ( EncodeEvent . FINISH_ENCODE_EVENT , async ( info ) => { try { await callback ( info ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setErrorEncode ( callback ) { this . emitter . on ( EncodeEvent . ERROR_ENCODE_EVENT , async ( ) => { try { await callback ( ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setUpdateEncode ( callback ) { this . emitter . on ( EncodeEvent . UPDATE_ENCODE_EVENT , async ( ) => { try { await callback ( ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setUpdateEncodeProgress ( callback ) { this . emitter . on ( EncodeEvent . UPDATE_ENCODE_PROGRESS_EVENT , async ( ) => { try { await callback ( ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } } namespace EncodeEvent { export const ADD_ENCODE_EVENT = 'addEncodeEvent' ; export const CANCEL_ENCODE_EVENT = 'cancelEncodeEvent' ; export const FINISH_ENCODE_EVENT = 'finishEncodeEvent' ; export const ERROR_ENCODE_EVENT = 'errorEncodeEvent' ; export const UPDATE_ENCODE_EVENT = 'updateEncodeEvent' ; export const UPDATE_ENCODE_PROGRESS_EVENT = 'updateENcodeProgressEvent' ; } export default EncodeEvent ;