import * as events from 'events' ; import { inject , injectable } from 'inversify' ; import * as apid from '../../../api' ; import ILogger from '../ILogger' ; import ILoggerModel from '../ILoggerModel' ; import IThumbnailEvent from './IThumbnailEvent' ; @ injectable ( ) class ThumbnailEvent implements IThumbnailEvent { private log : ILogger ; private emitter : events . EventEmitter = new events . EventEmitter ( ) ; constructor ( @ inject ( 'ILoggerModel' ) logger ) { this . log = logger . getLogger ( ) ; } param videoFileId param recordedId public emitAdded ( videoFileId , recordedId ) { this . emitter . emit ( ThumbnailEvent . ADDED_EVENT , videoFileId , recordedId ) ; } /**
     * サムネイル削除イベント発行
     */ public emitDeleted ( ) { this . emitter . emit ( ThumbnailEvent . DELETED_EVENT ) ; } param callback public setAdded ( callback ) { this . emitter . on ( ThumbnailEvent . ADDED_EVENT , async ( videoFileId , recordedId ) => { try { await callback ( videoFileId , recordedId ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setDeleted ( callback ) { this . emitter . on ( ThumbnailEvent . DELETED_EVENT , async ( ) => { try { await callback ( ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } } namespace ThumbnailEvent { export const ADDED_EVENT = 'added' ; export const DELETED_EVENT = 'deleted' ; } export default ThumbnailEvent ;