import * as events from 'events' ; import { inject , injectable } from 'inversify' ; import * as apid from '../../../api' ; import Recorded from '../../db/entities/Recorded' ; import ILogger from '../ILogger' ; import ILoggerModel from '../ILoggerModel' ; import IRecordedEvent from './IRecordedEvent' ; @ injectable ( ) class RecordedEvent implements IRecordedEvent { private log : ILogger ; private emitter : events . EventEmitter = new events . EventEmitter ( ) ; constructor ( @ inject ( 'ILoggerModel' ) logger ) { this . log = logger . getLogger ( ) ; } param recorded public emitDeleteRecorded ( recorded ) { this . emitter . emit ( RecordedEvent . DELETE_RECORDED_EVENT , recorded ) ; } param videoFileId public emitUpdateVideoFileSize ( videoFileId ) { this . emitter . emit ( RecordedEvent . UPDATE_VIDEO_FILE_SIZE , videoFileId ) ; } param recordedId public emitCreateNewRecorded ( recordedId ) { this . emitter . emit ( RecordedEvent . CREATE_NEW_RECORDED , recordedId ) ; } param newVideoFileId public emitAddVideoFile ( newVideoFileId ) { this . emitter . emit ( RecordedEvent . ADD_VIDEO_FILE , newVideoFileId ) ; } param newVideoFileId param needsCreateThumbnail public emitAddUploadedVideoFile ( newVideoFileId , needsCreateThumbnail ) { this . emitter . emit ( RecordedEvent . ADD_UPLOADED_VIDEO_FILE , newVideoFileId , needsCreateThumbnail ) ; } param videoFileId public emitDeleteVideoFile ( videoFileId ) { this . emitter . emit ( RecordedEvent . DLETE_VIDEO_FILE , videoFileId ) ; } param recordedId param isProtected public emitChangeProtect ( recordedId , isProtected ) { this . emitter . emit ( RecordedEvent . CHANGE_PROTECT , recordedId , isProtected ) ; } param callback public setDeleteRecorded ( callback ) { this . emitter . on ( RecordedEvent . DELETE_RECORDED_EVENT , async ( recorded ) => { try { await callback ( recorded ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setCreateNewRecorded ( callback ) { this . emitter . on ( RecordedEvent . CREATE_NEW_RECORDED , async ( recordedId ) => { try { await callback ( recordedId ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setUpdateVideoFileSize ( callback ) { this . emitter . on ( RecordedEvent . UPDATE_VIDEO_FILE_SIZE , async ( videoFileId ) => { try { await callback ( videoFileId ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setAddVideoFile ( callback ) { this . emitter . on ( RecordedEvent . ADD_VIDEO_FILE , async ( newVideoFileId ) => { try { await callback ( newVideoFileId ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setAddUploadedVideoFile ( callback ) { this . emitter . on ( RecordedEvent . ADD_UPLOADED_VIDEO_FILE , async ( newVideoFileId , needsCreateThumbnail ) => { try { await callback ( newVideoFileId , needsCreateThumbnail ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setDeleteVideoFile ( callback ) { this . emitter . on ( RecordedEvent . DLETE_VIDEO_FILE , async ( videoFileId ) => { try { await callback ( videoFileId ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } param callback public setChangeProtect ( callback ) { this . emitter . on ( RecordedEvent . CHANGE_PROTECT , async ( recordedId , isProtected ) => { try { await callback ( recordedId , isProtected ) ; } catch ( err ) { this . log . system . error ( err ) ; } } ) ; } } namespace RecordedEvent { export const DELETE_RECORDED_EVENT = 'DeleteRecorded' ; export const UPDATE_VIDEO_FILE_SIZE = 'UpdateVideoFileSize' ; export const CREATE_NEW_RECORDED = 'createNewRecorded' ; export const ADD_VIDEO_FILE = 'AddVideoFile' ; export const ADD_UPLOADED_VIDEO_FILE = 'addUploadedVideoFile' ; export const DLETE_VIDEO_FILE = 'DeleteVideoFile' ; export const CHANGE_PROTECT = 'ChangeProtect' ; } export default RecordedEvent ;