import { Context } from "../context/Context"; import { BaseOperation } from "./base/BaseOperation"; import { EOperationStatus } from "./enum/EOperationStatus"; import { EOperationType } from "./enum/EOperationType"; import { IOperation } from "./interface/IOperation"; import { ActionParams } from "../action/type/ActionParams"; import { RegionChangeActionParams } from "../action/type/RegionChangeActionParams"; import { RoleUserEnum } from "../context/enum/RoleUserEnum"; const parseError = require('parse-error'); export class JoinChannelOperation extends BaseOperation implements IOperation { constructor(context: Context){ super(context); this.type=EOperationType.JOIN_CHANNEL; } /*@overwrite*/ public async handler(params ? : ActionParams) : Promise{ return new Promise( async (resolve, reject)=>{ try { this.context.getDeterminants().setUpdating(true); let joinChannelParams : RegionChangeActionParams = Object.assign(params ? params : {}); if(joinChannelParams.keepTracks == false || joinChannelParams.role == RoleUserEnum.Audience){ this.context.getDeterminants().setHasCamera(false); this.context.getDeterminants().setHasScreen(false); } this.context.getDeterminants().setChannelIncoming(joinChannelParams.channel); this.context.getDeterminants().setRoleIncoming(joinChannelParams.role); let client = this.context.getResources().getClient(); let uid = this.context.getDeterminants().getUid(); await client.join(this.context.getDeterminants().getAppId(), joinChannelParams.channel, null, uid); this.context.getResources().startRecordVolumen(this.context.getDeterminants().getVolumenCallback()); this.context.getDeterminants().setChannel(joinChannelParams.channel); this.context.getDeterminants().setRole(joinChannelParams.role); this.status = EOperationStatus.PERFORMED; } catch (error) { this.addError(error); this.status = EOperationStatus.FAILED; } resolve(this.status); }); } }