import * as events from 'events' ; import { inject , injectable } from 'inversify' ; import ILogger from '../ILogger' ; import ILoggerModel from '../ILoggerModel' ; import IOperatorEncodeEvent , { OperatorFinishEncodeInfo } from './IOperatorEncodeEvent' ; @ injectable ( ) class OperatorEncodeEvent implements IOperatorEncodeEvent { private log : ILogger ; private emitter : events . EventEmitter = new events . EventEmitter ( ) ; constructor ( @ inject ( 'ILoggerModel' ) logger ) { this . log = logger . getLogger ( ) ; } param info public emitFinishEncode ( info ) { this . emitter . emit ( OperatorEncodeEvent . FINISH_ENCODE_EVENT , info ) ; } param callback public setFinishEncode ( callback ) { this . emitter . on ( OperatorEncodeEvent . FINISH_ENCODE_EVENT , async ( info ) => { try { await callback ( info ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } } namespace OperatorEncodeEvent { export const FINISH_ENCODE_EVENT = 'finishEncodeEvent' ; } export default OperatorEncodeEvent ;