import * as events from 'events' ; import { inject , injectable } from 'inversify' ; import Recorded from '../../db/entities/Recorded' ; import Reserve from '../../db/entities/Reserve' ; import ILogger from '../ILogger' ; import ILoggerModel from '../ILoggerModel' ; import IRecordingEvent from './IRecordingEvent' ; @ injectable ( ) class RecordingEvent implements IRecordingEvent { private log : ILogger ; private emitter : events . EventEmitter = new events . EventEmitter ( ) ; constructor ( @ inject ( 'ILoggerModel' ) logger ) { this . log = logger . getLogger ( ) ; } param reserve public emitStartPrepRecording ( reserve ) { this . emitter . emit ( RecordingEvent . START_PREP_RRECORDING_EVENT , reserve ) ; } param reserve public emitCancelPrepRecording ( reserve ) { this . emitter . emit ( RecordingEvent . CANCEL_PREP_RRECORDING_EVENT , reserve ) ; } param reserve public emitPrepRecordingFailed ( reserve ) { this . emitter . emit ( RecordingEvent . PREP_RECORDING_FAILED_EVENT , reserve ) ; } param reserve public emitStartRecording ( reserve , recorded ) { this . emitter . emit ( RecordingEvent . START_RECORDING_EVENT , reserve , recorded ) ; } param reserve param recorded public emitRecordingFailed ( reserve , recorded ) { this . emitter . emit ( RecordingEvent . RECORDING_FAILED_EVENT , reserve , recorded ) ; } param reserve public emitRecordingRetryOver ( reserve ) { this . emitter . emit ( RecordingEvent . RECORDING_RETRY_OVER_EVENT , reserve ) ; } param reserve param recorded param isNeedDeleteReservation public emitFinishRecording ( reserve , recorded , isNeedDeleteReservation ) { this . emitter . emit ( RecordingEvent . FINISH_RECORDING_EVENT , reserve , recorded , isNeedDeleteReservation ) ; } param callback public setStartPrepRecording ( callback ) { this . emitter . on ( RecordingEvent . START_PREP_RRECORDING_EVENT , async ( reserve ) => { try { await callback ( reserve ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setCancelPrepRecording ( callback ) { this . emitter . on ( RecordingEvent . CANCEL_PREP_RRECORDING_EVENT , async ( reserve ) => { try { await callback ( reserve ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setPrepRecordingFailed ( callback ) { this . emitter . on ( RecordingEvent . PREP_RECORDING_FAILED_EVENT , async ( reserve ) => { try { await callback ( reserve ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setStartRecording ( callback ) { this . emitter . on ( RecordingEvent . START_RECORDING_EVENT , async ( reserve , recorded ) => { try { await callback ( reserve , recorded ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setRecordingFailed ( callback ) { this . emitter . on ( RecordingEvent . RECORDING_FAILED_EVENT , async ( reserve , recorded ) => { try { await callback ( reserve , recorded ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setRecordingRetryOver ( callback ) { this . emitter . on ( RecordingEvent . RECORDING_RETRY_OVER_EVENT , async ( reserve ) => { try { await callback ( reserve ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setFinishRecording ( callback ) { this . emitter . on ( RecordingEvent . FINISH_RECORDING_EVENT , async ( reserve , recorded , isNeedDeleteReservation ) => { try { await callback ( reserve , recorded , isNeedDeleteReservation ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } } namespace RecordingEvent { export const START_PREP_RRECORDING_EVENT = 'StartPrepRecording' ; export const CANCEL_PREP_RRECORDING_EVENT = 'CancelPrepRecording' ; export const PREP_RECORDING_FAILED_EVENT = 'PrepRecordingFailed' ; export const START_RECORDING_EVENT = 'StartRecordingEvent' ; export const RECORDING_FAILED_EVENT = 'RecordingFailedEvent' ; export const RECORDING_RETRY_OVER_EVENT = 'RecordingRetryOverEvent' ; export const FINISH_RECORDING_EVENT = 'FinishRecordingEvent' ; } export default RecordingEvent ;