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 { BaseManager } from "./base/BaseManager"; import { CustomError } from "../exception/CustomError"; import { ShareCameraRules } from "../rules/ShareCameraRules"; import { ShareCameraActionParams } from "../action/type/ShareCameraActionParams"; import { ShareCameraOperation } from "../operation/ShareCameraOperation"; import { ShareScreenActionParams } from "../action/type/ShareScreenActionParams"; import { ShareScreenRules } from "../rules/ShareScreenRules"; import { ShareScreenOperation } from "../operation/ShareScreenOperation"; import { ShareScreenAction } from "../action/ShareScreenAction"; const parseError = require('parse-error'); export class ShareScreenManager extends BaseManager implements IManager { constructor(action : ShareScreenAction, context: Context){ super(action, context); } /*@overwrite*/ public async performAction(): Promise { return new Promise( async (resolve, reject)=>{ let params : ShareScreenActionParams = Object.assign(this.getAction().getParams()); let validationRules = new ShareScreenRules(params); validationRules.validate([ERuleTypes.IS_CLIENT_INIT, ERuleTypes.IS_HOST, ERuleTypes.IS_CONNECTED], this.context); if(validationRules.passes){ try { let shareScreenOperation = new ShareScreenOperation(this.context); await shareScreenOperation.handler(params); if(shareScreenOperation.status == EOperationStatus.PERFORMED){ 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{ let errors : Array = []; if(shareScreenOperation.errors) errors = [...errors, ...shareScreenOperation.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 }); } }else{ this.action.status = EActionStatus.FAILED; this.logger.log({ id: uuidv4(), title: this.action.type, body: "Action "+this.action.type + " not performaced", action: this.action, errors: validationRules.errors, type: EMessageType.ERROR }); } resolve(this.action.status); }); } }