From 55db788f502c8fb843e9377441bc97d983d65f95 Mon Sep 17 00:00:00 2001 From: Carlos Santos <4a.santos@gmail.com> Date: Wed, 1 Mar 2023 18:07:02 +0100 Subject: [PATCH] openvidu-components: Refactored streams types enabled pipe --- .../src/lib/models/participant.model.ts | 11 ++++++----- .../src/lib/pipes/participant.pipe.ts | 16 ++++++---------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/openvidu-components-angular/projects/openvidu-angular/src/lib/models/participant.model.ts b/openvidu-components-angular/projects/openvidu-angular/src/lib/models/participant.model.ts index c6f6734c..fa21f44c 100644 --- a/openvidu-components-angular/projects/openvidu-angular/src/lib/models/participant.model.ts +++ b/openvidu-components-angular/projects/openvidu-angular/src/lib/models/participant.model.ts @@ -160,13 +160,14 @@ export abstract class ParticipantAbstractModel { /** * @internal + * @returns The participant active connection types */ - getConnectionTypesActive(): VideoType[] { - let connType = []; - if (this.isCameraActive()) connType.push(VideoType.CAMERA); - if (this.isScreenActive()) connType.push(VideoType.SCREEN); + getActiveConnectionTypes(): VideoType[] { + const activeTypes: VideoType[] = []; + if (this.isCameraActive()) activeTypes.push(VideoType.CAMERA); + if (this.isScreenActive()) activeTypes.push(VideoType.SCREEN); - return connType; + return activeTypes; } /** diff --git a/openvidu-components-angular/projects/openvidu-angular/src/lib/pipes/participant.pipe.ts b/openvidu-components-angular/projects/openvidu-angular/src/lib/pipes/participant.pipe.ts index 9a425c29..f22fa267 100644 --- a/openvidu-components-angular/projects/openvidu-angular/src/lib/pipes/participant.pipe.ts +++ b/openvidu-components-angular/projects/openvidu-angular/src/lib/pipes/participant.pipe.ts @@ -27,15 +27,11 @@ export class StreamTypesEnabledPipe implements PipeTransform { constructor(private translateService: TranslateService) {} transform(participant: ParticipantAbstractModel): string { - let result = ''; - let activeStreams = participant?.getConnectionTypesActive().toString(); - const activeStreamsArr: string[] = activeStreams.split(','); - activeStreamsArr.forEach((type, index) => { - result += this.translateService.translate(`PANEL.PARTICIPANTS.${type}`) - if(activeStreamsArr.length > 0 && index < activeStreamsArr.length - 1){ - result += ', '; - } - }); - return `(${result})`; + + const activeStreams = participant?.getActiveConnectionTypes() ?? []; + const streamNames = activeStreams.map(streamType => this.translateService.translate(`PANEL.PARTICIPANTS.${streamType}`)); + const streamsString = streamNames.join(', '); + + return `(${streamsString})`; } }