import { InitAction } from "../action/InitAction"; import { Context } from "../context/Context"; import { ERuleTypes } from "../rules/enum/ERuleTypes"; import { IManager } from "./interface/IManager"; import { v4 as uuidv4 } from "uuid"; import { EActionStatus } from "../action/enum/EActionStatus"; import { EMessageType } from "../logger/enum/EMessageType"; import { EOperationStatus } from "../operation/enum/EOperationStatus"; import { InitActionParams } from "../action/type/InitActionParams"; import { BaseManager } from "./base/BaseManager"; import { CustomError } from "../exception/CustomError"; import { ToggleVoiceRules } from "../rules/ToggleVoiceRules"; import { MuteAudioOperation } from "../operation/MuteAudioOperation"; import { ToggleVoiceAction } from "../action/ToggleVoiceAction"; const parseError = require('parse-error'); export class ToggleVoiceManager extends BaseManager implements IManager { constructor(action : ToggleVoiceAction, context: Context){ super(action, context); } /*@overwrite*/ public async performAction(): Promise { return new Promise( async (resolve, reject)=>{ let params : InitActionParams = Object.assign(this.getAction().getParams()); let validationRules = new ToggleVoiceRules(params); validationRules.validate([ERuleTypes.IS_AUDIO_TRACK_ENABLE, ERuleTypes.HAS_AUDIO_TRACK], this.context); try { let muteAudioOperation = new MuteAudioOperation(this.context); await muteAudioOperation.handler(params); if(muteAudioOperation.status == EOperationStatus.PERFORMED){ if(validationRules.passes){ this.action.status = EActionStatus.PERFORMED; this.logger.log({ id: uuidv4(), title: this.action.type, body: "Action "+this.action.type + " performaced", action: this.action, errors: validationRules.errors, type:EMessageType.INFO }); }else{ this.action.status = EActionStatus.INCOMPLETE; this.logger.log({ id: uuidv4(), title: this.action.type, body: "Action "+this.action.type + " performaced", action: this.action, errors: validationRules.errors, type:EMessageType.WARNING }); } }else{ let errors : Array = []; if(muteAudioOperation.errors) errors = [...errors, ...muteAudioOperation.errors]; this.action.status = EActionStatus.FAILED; this.logger.log({ id: uuidv4(), title: this.action.type, body: "Something operations not performaced in action "+this.action.type, action: this.action, errors: errors, type: EMessageType.ERROR }); } } catch (error) { let errors = parseError(error); this.action.status = EActionStatus.FAILED; this.logger.log({ id: uuidv4(), title: this.action.type, body: "Something operations not performaced in action "+this.action.type, action: this.action, errors: errors, type: EMessageType.ERROR }); } resolve(this.action.status); }); } }